@Test
  public void testAbcd() throws Exception {
    driver.get(baseUrl + "/");
    driver.findElement(By.linkText("Sign In")).click();

    driver.findElement(By.linkText("Sign In")).getText();
    driver.findElement(By.xpath("//input[@name='loginName']")).clear();
    driver.findElement(By.xpath("//input[@name='loginName']")).sendKeys("*****@*****.**");
    driver.findElement(By.xpath("//input[@name='password']")).clear();
    driver.findElement(By.xpath("//input[@name='password']")).sendKeys("demo123");
    driver.findElement(By.xpath("//input[@type='image']")).click();
    driver.findElement(By.linkText("Money")).click();

    driver.findElement(By.linkText("Portfolio")).click();
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

    WebElement table = driver.findElement(By.id("table-holding-data"));

    if (table.isDisplayed()) {

      List<WebElement> rows = table.findElements(By.tagName("tr"));

      System.out.println("Row Count - " + rows.size());

      Iterator<WebElement> i = rows.iterator();

      System.out.println("Table has following content");

      while (i.hasNext()) {

        WebElement row = i.next();

        List<WebElement> columns = row.findElements(By.tagName("td"));

        Iterator<WebElement> j = columns.iterator();

        while (j.hasNext()) {

          WebElement column = j.next();

          System.out.print(column.getText());

          System.out.print("    |  ");
        }
        System.out.println("--------------------");
      }
      System.out.println("Table content is printed");
    } else {
      System.out.println("Table not found");
    }
  }
Beispiel #2
0
  @Test
  public void testLogin() throws Exception {
    // open | /webui/ |
    driver.get(baseUrl + "webui/");
    // type | id=loginPanel_grdLogin_rowUser_txtUserId | GardenAdmin
    driver.findElement(By.id("loginPanel_txtUserId")).clear();
    driver.findElement(By.id("loginPanel_txtUserId")).sendKeys("GardenAdmin");

    // fireEvent | id=loginPanel_grdLogin_rowUser_txtUserId | blur
    // not needed for webdriver
    // type | id=loginPanel_grdLogin_rowPassword_txtPassword | GardenAdmin
    driver.findElement(By.id("loginPanel_txtPassword")).clear();
    driver.findElement(By.id("loginPanel_txtPassword")).sendKeys("GardenAdmin");
    // fireEvent | id=loginPanel_grdLogin_rowPassword_txtPassword | blur
    // not needed for webdriver
    // click | id=loginPanel_grdLogin_rowSelectRole_chkSelectRole-real |
    driver.findElement(By.id("loginPanel_chkSelectRole-real")).click();
    // click | loginPanel_Ok | 10
    driver.findElement(By.id("loginPanel_Ok")).click();
    // waitForElementPresent | id=rolePanel_grdChooseRole_rowclient_lstClient-btn |
    for (int second = 0; ; second++) {
      if (second >= 60) fail("timeout");
      try {
        if (isElementPresent(By.id("rolePanel_lstClient-btn"))) break;
      } catch (Exception e) {
      }
      Thread.sleep(1000);
    }

    WebElement lstClient = driver.findElement(By.id("rolePanel_lstClient"));
    if (lstClient != null && lstClient.isDisplayed()) {
      // click | id=rolePanel_grdChooseRole_rowclient_lstClient-btn |
      driver.findElement(By.id("rolePanel_lstClient-btn")).click();
      // click | css=#rolePanel_grdChooseRole_rowclient_lstClient_GardenWorld > td.z-comboitem-text
      // |
      driver
          .findElement(By.cssSelector("#rolePanel_lstClient_GardenWorld > td.z-comboitem-text"))
          .click();
      Thread.sleep(1000);
    }
    // click | id=rolePanel_grdChooseRole_rowRole_lstRole-btn |
    driver.findElement(By.id("rolePanel_lstRole-btn")).click();
    // click | css=#rolePanel_grdChooseRole_rowRole_lstRole_GardenWorld_Admin > td.z-comboitem-text
    // |
    driver
        .findElement(By.cssSelector("#rolePanel_lstRole_GardenWorld_Admin > td.z-comboitem-text"))
        .click();
    Thread.sleep(1000);
    // click | id=rolePanel_grdChooseRole_rowOrganisation_lstOrganisation-btn |
    driver.findElement(By.id("rolePanel_lstOrganisation-btn")).click();
    // click | css=#rolePanel_grdChooseRole_rowOrganisation_lstOrganisation_HQ > td.z-comboitem-text
    // |
    driver
        .findElement(By.cssSelector("#rolePanel_lstOrganisation_HQ > td.z-comboitem-text"))
        .click();
    // click | rolePanel_Ok |
    driver.findElement(By.id("rolePanel_Ok")).click();
    // waitForElementPresent | loginUserAndRole |
    for (int second = 0; ; second++) {
      if (second >= 60) fail("timeout");
      try {
        if (isElementPresent(By.id("loginUserAndRole"))) break;
      } catch (Exception e) {
      }
      Thread.sleep(1000);
    }
    // assertText | loginUserAndRole | [email protected]/GardenWorld Admin
    assertEquals(
        "[email protected]/GardenWorld Admin",
        driver.findElement(By.id("loginUserAndRole")).getText());
  }
Beispiel #3
0
  private void test_image_picker(WebDriver driver) {
    // Check both files exist
    File f1 = null;
    File f2 = null;
    try {
      ClassLoader cl = ImagePickerTest.class.getClassLoader();
      f1 = new File(cl.getResource("image_picker_1.png").toURI());
      assertTrue(f1.exists());
      f2 = new File(cl.getResource("image_picker_2.png").toURI());
      assertTrue(f2.exists());
    } catch (URISyntaxException e) {
      e.printStackTrace();
    }
    assertNotNull(f1);
    assertNotNull(f2);

    // Login
    CStudioSeleniumUtil.try_login(
        driver, CStudioSeleniumUtil.AUTHOR_USER, CStudioSeleniumUtil.AUTHOR_PASSWORD, true);

    // Navigate to Widget
    CStudioSeleniumUtil.navigate_to_image_picker_widget(driver);

    // Upload right file size
    CStudioSeleniumUtil.click_on(driver, By.id("xf-4$xf-20$imageSrcAltTextTest-imageButton"));

    // Check popup dialog appears
    WebElement popup = driver.findElement(By.id("cstudio-wcm-popup-div_c"));
    assertTrue(popup.isDisplayed());

    WebElement input =
        driver.findElement(By.xpath("/html/body/div[3]/div/div[2]/div/div/div/form/input"));
    input.sendKeys(f1.getAbsolutePath());

    WebElement upload =
        driver.findElement(By.xpath("/html/body/div[3]/div/div[2]/div/div/div/form/input[2]"));
    upload.click();

    new WebDriverWait(driver, CStudioSeleniumUtil.SHORT_TIMEOUT)
        .until(
            new ExpectedCondition<Boolean>() {
              public Boolean apply(WebDriver d) {
                WebElement e = d.findElement(By.id("xf-4$xf-20$imageSrcAltTextTest$xf-206$$a"));
                return e != null && e.getAttribute("class").contains("xforms-alert-inactive");
              }
            });
    WebElement mark = driver.findElement(By.id("xf-4$xf-20$imageSrcAltTextTest$xf-206$$a"));
    assertTrue(mark.getAttribute("class").contains("xforms-alert-inactive"));

    // Delete uploaded image
    CStudioSeleniumUtil.click_on(driver, By.id("xf-4$xf-20$imageSrcAltTextTest-deleteButton"));
    WebElement filename =
        driver.findElement(By.id("xf-4$xf-20$imageSrcAltTextTest$xf-206-filename"));
    assertTrue(filename.getText().equals("250W X 130H"));

    // Upload any image
    CStudioSeleniumUtil.click_on(driver, By.id("xf-4$xf-20$imageSrcTest-imageButton"));

    // Check popup dialog appears
    popup = driver.findElement(By.id("cstudio-wcm-popup-div_c"));
    assertTrue(popup.isDisplayed());

    input = driver.findElement(By.xpath("/html/body/div[3]/div/div[2]/div/div/div/form/input"));
    input.sendKeys(f2.getAbsolutePath());

    upload = driver.findElement(By.xpath("/html/body/div[3]/div/div[2]/div/div/div/form/input[2]"));
    upload.click();

    new WebDriverWait(driver, CStudioSeleniumUtil.SHORT_TIMEOUT)
        .until(
            new ExpectedCondition<Boolean>() {
              public Boolean apply(WebDriver d) {
                WebElement e = d.findElement(By.id("xf-4$xf-20$imageSrcTest$xf-237-filename"));
                return e != null && e.getText().equals("/static-assets/images/image_picker_2.png");
              }
            });

    // Delete uploaded image
    CStudioSeleniumUtil.click_on(driver, By.id("xf-4$xf-20$imageSrcTest-deleteButton"));
    filename = driver.findElement(By.id("xf-4$xf-20$imageSrcTest$xf-237-filename"));
    assertTrue(filename.getText().equals(""));

    // Close driver
    CStudioSeleniumUtil.exit(driver);
  }