public void testViewMacronutrientsAsHCP() throws Exception {
    // Login patient 1.
    WebDriver wd = (HtmlUnitDriver) login("9000000071", "pw");
    assertEquals("iTrust - HCP Home", wd.getTitle());

    // Navigate to the Macronutrients page.
    wd.findElement(By.partialLinkText("Patient Macronutrient")).click();
    assertEquals("iTrust - Please Select a Patient", wd.getTitle());
    wd.findElement(By.name("UID_PATIENTID")).sendKeys("342");
    // the button to click should have the text of the MID
    wd.findElement(By.cssSelector("input[value='342']")).submit();

    assertTrue(
        wd.findElement(By.tagName("body"))
            .getText()
            .contains("Hubert Farnsworth's Macronutrient Intake"));

    wd = (HtmlUnitDriver) login("9000000000", "pw");
    assertEquals("iTrust - HCP Home", wd.getTitle());

    // Navigate to the Macronutrients page.
    wd.findElement(By.partialLinkText("Patient Macronutrient")).click();
    assertEquals("iTrust - Please Select a Patient", wd.getTitle());
    wd.findElement(By.name("UID_PATIENTID")).sendKeys("342");
    // the button to click should have the text of the MID
    wd.findElement(By.cssSelector("input[value='342']")).submit();

    assertTrue(
        wd.findElement(By.tagName("body"))
            .getText()
            .contains("You do not have permission to view the Food Diary!"));
  }
Ejemplo n.º 2
0
 @Test(
     priority = 1,
     dependsOnMethods = {"test001createRoleTest"})
 public void test002updateRoleTest() {
   // click Roles menu
   $(By.partialLinkText("Roles")).shouldBe(visible).click();
   // click List roles menu item
   $(By.linkText("List roles")).shouldBe(visible).click();
   // search for newly created role
   searchForElement(ROLE_NAME_VALUE);
   // click on the found role
   $(By.linkText(ROLE_NAME_VALUE)).shouldBe(visible).click();
   // update role attributes values
   Set<String> attributeFielldNames = roleAttributes.keySet();
   Map<String, String> roleAttributesUpdated = new HashMap<>();
   for (String attributeFieldName : attributeFielldNames) {
     roleAttributesUpdated.put(
         attributeFieldName, roleAttributes.get(attributeFieldName) + UPDATED_VALUE);
   }
   setFieldValues(roleAttributesUpdated);
   // click Save button
   $(By.linkText("Save")).shouldBe(visible).click();
   // check if Success message appears
   $(byText("Success")).shouldBe(visible);
   // search for newly created role
   searchForElement(ROLE_NAME_VALUE + UPDATED_VALUE);
   // click on the found role
   $(By.linkText(ROLE_NAME_VALUE + UPDATED_VALUE)).shouldBe(visible).click();
   // check role attributes are filled in with correct values
   checkObjectAttributesValues(roleAttributesUpdated);
 }
Ejemplo n.º 3
0
public class DevBySalaryPage extends BaseForm {
  private static String formlocator = "//body/div[@class='wrapper dev all']";

  private Button devByPositionLink = new Button(By.linkText("Должности"), "link on positions");
  private Button devByPositionQALink =
      new Button(By.partialLinkText("QA Engineer"), "link on QA position");
  private Label devBySalaryRations =
      new Label(
          By.xpath("//strong[contains(., 'Соотношение размеров зарплат')]"), "salary rations text");
  private Label devBySalaryForQA =
      new Label(
          By.xpath("//span[@class='ui-selectmenu-status' and contains(., 'QA Engineer/ Tester')]"),
          "salary for QA in menu");

  public void clickOnPositionAll() {
    devByPositionLink.click();
  }

  public void clickOnPositionQA() {
    devByPositionQALink.click();
  }

  public DevBySalaryPage() {
    super(By.xpath(formlocator), "dev.by Salary page");
  }

  public void assertDevBySalary() {
    assert (devBySalaryRations.isPresent(10) && devBySalaryForQA.isPresent(10));
  }
}
Ejemplo n.º 4
0
 @Test(priority = 0)
 public void test001createRoleTest() {
   close();
   login();
   // click Roles menu
   $(By.partialLinkText("Roles")).shouldBe(visible).click();
   // click New role menu item
   $(By.linkText("New role")).shouldBe(visible).click();
   // set new role attributes
   roleAttributes.put(ROLE_NAME_FIELD, ROLE_NAME_VALUE);
   roleAttributes.put(ROLE_DISPLAY_NAME_FIELD, ROLE_DISPLAY_NAME_VALUE);
   roleAttributes.put(ROLE_DESCRIPTION_FIELD, ROLE_DESCRIPTION_VALUE);
   roleAttributes.put(ROLE_TYPE_FIELD, ROLE_TYPE_VALUE);
   roleAttributes.put(ROLE_IDENTIFIER_FIELD, ROLE_IDENTIFIER_VALUE);
   roleAttributes.put(ROLE_RISK_LEVEL_FIELD, ROLE_RISK_LEVEL_VALUE);
   setFieldValues(roleAttributes);
   // click Save button
   $(By.linkText("Save")).shouldBe(visible).click();
   // check if Success message appears
   $(byText("Success")).shouldBe(visible);
   // search for newly created role
   searchForElement(ROLE_NAME_VALUE);
   // click on the found role
   $(By.linkText(ROLE_NAME_VALUE)).shouldBe(visible).click();
   // check role attributes are filled in with correct values
   checkObjectAttributesValues(roleAttributes);
 }
  @Test
  public void testLoginAndLogout() throws InterruptedException {
    String baseUrl = "http://www.testerhome.com";
    String loginText = "登录";
    String logoutText = "退出";

    String userName = "******";
    String password = "******";

    // get index page of testerhome
    driver.get(baseUrl);
    Thread.sleep(1000);

    // enter login page by clicking login button
    driver.findElement(By.partialLinkText(loginText)).click();
    Thread.sleep(500);

    // input user name and password
    WebElement userNameInput = driver.findElement(By.id("user_login"));
    userNameInput.clear();
    userNameInput.sendKeys(userName);

    WebElement passwordInput = driver.findElement(By.id("user_password"));
    passwordInput.clear();
    passwordInput.sendKeys(password);

    // click login commit button and wait for success alert
    driver.findElement(By.name("commit")).click();
    TestWaiter.waitForElement(By.cssSelector("div.alert.alert-success"), 3, driver);
    Thread.sleep(3000);

    // click toggle menu button
    WebElement toggleMenuBtn = driver.findElement(By.cssSelector("button.navbar-toggle"));
    toggleMenuBtn.click();
    Thread.sleep(500);

    // click logout text and wait for success alert
    driver.findElement(By.partialLinkText(logoutText)).click();
    TestWaiter.waitForElement(By.cssSelector("div.alert.alert-success"), 3, driver);
    Thread.sleep(3000);
  }
  public void testViewMacronutrientGraphs() throws Exception {
    // Login patient 1.
    WebDriver wd = login("341", "pw");
    assertEquals("iTrust - Patient Home", wd.getTitle());
    assertLogged(TransactionType.HOME_VIEW, 341L, 0L, "");

    // Navigate to the Macronutrients page.
    wd.findElement(By.partialLinkText("Macronutrients")).click();
    assertEquals("iTrust - View Macronutrients", wd.getTitle());
    assertTrue(
        wd.findElement(By.tagName("body")).getText().contains("Macronutrient Intake Totals"));
  }
Ejemplo n.º 7
0
  public SearchItemPage searchSpecifiedIteam(String item) {
    if (driver.getPageSource().contains(item)) {
      System.out.println("Jest tekst");
      WebElement firstLink = driver.findElement(By.partialLinkText(item));
      System.out.println(firstLink.getAttribute("href"));
      firstLink.click();
    } else {
      System.out.println("Nie ma tekstu");
    }

    return new SearchItemPage(driver);
  }
Ejemplo n.º 8
0
  @Test
  public void scrollElementIntoView() {
    WebDriver d = getDriver();

    d.get("https://developer.mozilla.org/en/CSS/Attribute_selectors");
    WebElement aboutGoogleLink = d.findElement(By.partialLinkText("About MDN"));
    Point locationBeforeScroll = aboutGoogleLink.getLocation();
    Point locationAfterScroll =
        ((Locatable) aboutGoogleLink).getLocationOnScreenOnceScrolledIntoView();

    assertTrue(locationBeforeScroll.x >= locationAfterScroll.x);
    assertTrue(locationBeforeScroll.y >= locationAfterScroll.y);
  }
  public void testViewEmptyMacronutrientGraphs() throws Exception {
    // Login patient 1.
    WebDriver wd = login("343", "pw");
    assertEquals("iTrust - Patient Home", wd.getTitle());
    assertLogged(TransactionType.HOME_VIEW, 343L, 0L, "");

    // Navigate to the Macronutrients page.
    wd.findElement(By.partialLinkText("Macronutrients")).click();
    assertEquals("iTrust - View Macronutrients", wd.getTitle());
    assertTrue(
        wd.findElement(By.tagName("body")).getText().contains("Add an entry to your Food Diary."));
    assertTrue(
        wd.findElement(By.tagName("body")).getText().contains("You have no Food Diary entries."));
  }
  @Test
  @Title("Create new building to verify R,E,C permissions")
  public void test003CreateNewBuilding() throws Exception {

    OpenView.NavigateTO(Grundschutz, InventoryAnalysis);
    // Create TO

    TargetObject.CreateNew("Building", TOname, null);

    // Assert
    $(By.xpath(".//*[@id='footerForm:message']/dt/span"))
        .waitUntil(visible, 10000)
        .shouldHave(text("Successfully saved"))
        .shouldHave(text(TOname));
    $(By.partialLinkText(TOname)).waitUntil(present, 8000).shouldBe(visible, enabled);
  }
Ejemplo n.º 11
0
 /**
  * Permet de trouver un élément dans une page avec un minimum d'effort pour l'utilisateur Pour
  * l'instant c'est hyper brouillon, faut repasser dessus
  *
  * @param clue
  * @return
  */
 private static WebElement fineElementFinder(String clue) {
   WebElement ret = null;
   Exception e = null;
   try { // TODO Make this stuff smarter by proper use of xpath
     ret = SEL_DRIVER.findElement(By.name(clue)); // find element using tag 'name'
   } catch (Exception e0) {
     e = e0;
     try {
       ret = SEL_DRIVER.findElement(By.linkText(clue));
     } catch (Exception e1) {
       e = e1;
       try {
         ret = SEL_DRIVER.findElement(By.partialLinkText(clue));
       } catch (Exception e2) {
         e = e2;
         try {
           ret = SEL_DRIVER.findElement(By.className(clue));
         } catch (Exception e3) {
           e = e3;
           try {
             ret = SEL_DRIVER.findElement(By.cssSelector("value$='" + clue + "'"));
           } catch (Exception e4) {
             e = e4;
             try {
               ret = SEL_DRIVER.findElement(By.xpath("#" + clue));
             } // find element id
             catch (Exception e5) {
               e = e5;
               try {
                 ret = SEL_DRIVER.findElement(By.xpath("//*[contains(@value, '" + clue + "')]"));
               } catch (Exception e6) {
                 e = e6;
                 System.out.println(
                     "NOTHING WAS FOUND by the fine element finder using clue : '"
                         + clue
                         + "' ! ");
               }
             }
           }
         }
       }
     }
   }
   if (e != null) {}
   return ret;
 }
  @Test
  @Title("Delete created TO, check L permission")
  public void test004DeleteCreatedBuilding() throws Exception {
    // Select created TO

    $(By.partialLinkText(TOname)).click();

    // Click Delete button and confirm deletion
    $("#deleteElementEnabled").waitUntil(enabled, 6000).click();
    $("#genericConfirmPanelYes").waitUntil(enabled, 8000).click();

    $("#genericConfirmPanelYes").waitUntil(disappear, 8000);

    // Assertion
    $(By.xpath(".//*[@id='footerForm:message']/dt/span"))
        .waitUntil(visible, 8000)
        .shouldHave(text("Item successfully deleted"))
        .shouldHave(text(TOname));
  }
Ejemplo n.º 13
0
 @Test(
     priority = 2,
     dependsOnMethods = {"test001createRoleTest"})
 public void test003deleteRoleTest() {
   // click Roles menu
   $(By.partialLinkText("Roles")).shouldBe(visible).click();
   // click List roles menu item
   $(By.linkText("List roles")).shouldBe(visible).click();
   // search for created role
   searchForElement(ROLE_NAME_VALUE + UPDATED_VALUE);
   // select found role checkbox
   $(byAttribute("type", "checkbox")).shouldBe(visible).click();
   // click on the menu icon in the upper right corner of the roles list
   $(By.className("cog")).find(By.className("caret")).shouldBe(visible).click();
   // click Delete menu item
   $(By.linkText("Delete")).shouldBe(visible).click();
   // click Yes button in the Confirm delete window
   $(By.linkText("Yes")).shouldBe(visible).click();
   // check if success message appears after role deletion
   $(byText("The role(s) have been successfully deleted.")).shouldBe(visible);
 }
Ejemplo n.º 14
0
  public By getByElementFromRepo(String pageName, String loc) {
    String locatorType = null;
    String locatorValue = null;
    String repoFilePath = "src/test/resources/or/IMDbRepo.xml";

    try {
      File repoXmlFile = new File(repoFilePath);

      DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
      DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
      Document document = documentBuilder.parse(repoXmlFile);
      document.getDocumentElement().normalize();

      NodeList nodeList = document.getElementsByTagName("PageNode");
      for (int i = 0; i < nodeList.getLength(); i++) {
        Node pageNode = nodeList.item(i);
        if ((pageNode
            .getAttributes()
            .getNamedItem("name")
            .getTextContent()
            .toString()
            .equalsIgnoreCase(pageName))) {

          for (int j = 0; j < pageNode.getChildNodes().getLength(); j++) {
            if (!pageNode.getChildNodes().item(j).getNodeName().toString().startsWith("#")) {
              if (pageNode
                  .getChildNodes()
                  .item(j)
                  .getAttributes()
                  .getNamedItem("name")
                  .getTextContent()
                  .toString()
                  .equalsIgnoreCase(loc)) {
                locatorType =
                    pageNode
                        .getChildNodes()
                        .item(j)
                        .getAttributes()
                        .getNamedItem("locator_type")
                        .getTextContent()
                        .toString();
                locatorValue =
                    pageNode
                        .getChildNodes()
                        .item(j)
                        .getAttributes()
                        .getNamedItem("locator")
                        .getTextContent()
                        .toString();
              }
            }
          }
        }
      }

    } catch (Exception e) {
      e.printStackTrace();
    }

    By locator = null;

    if (locatorType.equalsIgnoreCase("Id")) {
      locator = By.id(locatorValue);
    } else if (locatorType.equalsIgnoreCase("Name")) {
      locator = By.name(locatorValue);
    } else if (locatorType.equalsIgnoreCase("CssSelector")) {
      locator = By.cssSelector(locatorValue);
    } else if (locatorType.equalsIgnoreCase("LinkText")) {
      locator = By.linkText(locatorValue);
    } else if (locatorType.equalsIgnoreCase("PartialLinkText")) {
      locator = By.partialLinkText(locatorValue);
    } else if (locatorType.equalsIgnoreCase("TagName")) {
      locator = By.tagName(locatorValue);
    } else if (locatorType.equalsIgnoreCase("Xpath")) {
      locator = By.xpath(locatorValue);
    } else if (locatorType.equalsIgnoreCase("ClassName")) {
      locator = By.className(locatorValue);
    }

    return locator;
  }
Ejemplo n.º 15
0
Archivo: Bot.java Proyecto: byde/dogame
  public void leerReportesEspionaje() {
    Db db = new Db();
    double metal, cristal, duty;
    List<WebElement> espionajes =
        driver.findElements(By.partialLinkText("Reporte de espionaje de"));
    WebElement espia;
    List<WebElement> flotas;
    boolean sindef = true;
    String helper;
    for (WebElement row : espionajes) {
      driver.switchTo().defaultContent();
      row.click();
      try {
        (new WebDriverWait(driver, 10))
            .until(
                new ExpectedCondition<Boolean>() {

                  public Boolean apply(WebDriver d) {
                    return d.findElement(By.id("TB_iframeContent")).isEnabled();
                  }
                });
        // ((JavascriptExecutor) driver).executeScript("$(\".success\").remove();");
      } catch (Exception e) {
        consola("Error: Mensajes: No abre Iframe - " + e.getMessage());
        consola("Reintentando");
        row.click();
        (new WebDriverWait(driver, 10))
            .until(
                new ExpectedCondition<Boolean>() {

                  public Boolean apply(WebDriver d) {
                    return d.findElement(By.id("TB_iframeContent")).isEnabled();
                  }
                });
      }
      driver.switchTo().frame("TB_iframeContent");

      try {
        (new WebDriverWait(driver, 30))
            .until(
                new ExpectedCondition<Boolean>() {

                  public Boolean apply(WebDriver d) {
                    return d.findElement(By.id("showmessage")).isEnabled();
                  }
                });
        consola("Log: Mensajes: Espionaje cargado");
        // ((JavascriptExecutor) driver).executeScript("$(\".success\").remove();");
      } catch (Exception e) {
        consola("Error: Mensajes: Error Espionaje cargado - " + e.getMessage());
      }
      espia = driver.findElement(By.className("spy2"));
      for (WebElement td : espia.findElements(By.tagName("td"))) {
        consola(td.getText());
      }
      helper = driver.findElement(By.xpath("/html/body/div/div[2]/table/tbody/tr[3]/td")).getText();
      consola(helper.substring(helper.indexOf("[") + 1, helper.indexOf("]")));
      // fleetdefbuildings spy
      flotas = driver.findElements(By.className("fleetdefbuildings"));
      if (flotas.size() > 0)
        if (("Flotas".equals(flotas.get(0).findElement(By.tagName("th")).getText()))
            && (flotas.get(0).findElements(By.tagName("td")).size() == 0)) {
          consola("no hay flotas");
          if ((flotas.size() > 1)
              && ("Defensa".equals(flotas.get(1).findElement(By.tagName("th")).getText()))) {
            for (WebElement d : flotas.get(1).findElements(By.className("key"))) {
              if (!d.getText().startsWith("Misil")) sindef = false;

              consola("Aqui hay " + d.getText());
            }
            if (sindef) {
              metal =
                  Double.valueOf(
                      EliminaCaracteres(
                          espia.findElements(By.tagName("td")).get(1).getText(), "."));
              cristal =
                  Double.valueOf(
                      EliminaCaracteres(
                          espia.findElements(By.tagName("td")).get(3).getText(), "."));
              duty =
                  Double.valueOf(
                      EliminaCaracteres(
                          espia.findElements(By.tagName("td")).get(5).getText(), "."));

              db.setEspionaje(
                  helper.substring(helper.indexOf("[") + 1, helper.indexOf("]")),
                  metal,
                  cristal,
                  duty,
                  planeta);
            }
            sindef = true;
          }
        }
      driver.findElement(By.className("closeTB")).click();
      try {
        Thread.sleep(200);
      } catch (InterruptedException ex) {
        consola("Error: no duerme para cerrar mensajes");
        // Logger.getLogger(Bot.class.getName()).log(Level.SEVERE, null, ex);
      }
    }
  }
 @Test
 public void assertAnchorTagCount() {
   List<WebElement> elements;
   elements = driver.findElements(By.partialLinkText("jump to para"));
   assertThat(elements.size(), is(25));
 }
Ejemplo n.º 17
0
  /**
   * Find web-element for given locator.
   *
   * @param elementName
   * @return
   */
  public WebElement findElement(String elementName) {

    String locator;

    locator = elementName;

    int count = 0;
    while (count < 4) {
      try {
        if (locator.startsWith("link=") || locator.startsWith("LINK=")) {
          locator = locator.substring(5); // remove "link=" from
          // locator
          try {
            if (locator.contains(" ")) return driver.findElement(By.partialLinkText(locator));

            return driver.findElement(By.linkText(locator));
          } catch (Exception e) {
            return null;
          }
        }

        if (locator.startsWith("id=")) {
          locator = locator.substring(3); // remove "id=" from locator
          try {
            return driver.findElement(By.id(locator));
          } catch (Exception e) {
            return null;
          }
        } else if (locator.startsWith("//")) {
          try {
            return driver.findElement(By.xpath(locator));
          } catch (Exception e) {
            return null;
          }
        } else if (locator.startsWith("css=")) {

          locator = locator.substring(4); // remove "css=" from
          // locator
          try {
            return driver.findElement(By.cssSelector(locator));
          } catch (Exception e) {
            return null;
          }
        } else if (locator.startsWith("name=")) {

          locator = locator.substring(5); // remove "name=" from
          // locator
          try {
            return driver.findElement(By.name(locator));
          } catch (Exception e) {
            return null;
          }
        } else {
          try {
            return driver.findElement(By.id(locator));
          } catch (Exception e) {
            return null;
          }
        }
      } catch (StaleElementReferenceException e) {
        e.toString();

        count = count + 1;
        // System.out.println("Trying["+
        // count+"] to recover from a stale element :" +
        // e.getMessage());
      }
      count = count + 4;
    }
    return null;
  }
Ejemplo n.º 18
0
 @Test
 public void findChangeLocationUsingPartialLinkText() {
   WebDriver driver = Browsers.CHROME;
   driver.get("http://www.ticketfly.com");
   driver.findElement(By.partialLinkText("change")).click();
 }