/**
   * Is this web element present and visible on the screen This method will not throw an exception
   * if the element is not on the screen at all. If the element is not visible, the method will wait
   * a bit to see if it appears later on.
   */
  @Override
  public boolean isVisible() {

    try {
      WebElement element = getElement();
      return (element != null) && (element.isDisplayed());
    } catch (ElementNotVisibleException e) {
      return false;
    } catch (NoSuchElementException e) {
      return false;
    } catch (StaleElementReferenceException se) {
      return false;
    }
  }
  public boolean isPresent() {
    if (driverIsDisabled()) {
      return false;
    }

    try {
      WebElement element = getElement();

      if (element == null) {
        return false;
      }
      element.isDisplayed();
      return true;
    } catch (ElementNotVisibleException e) {
      return true;
    } catch (NotFoundException e) {
      return false;
    } catch (ElementNotFoundAfterTimeoutError timeoutError) {
      return false;
    }
  }
Ejemplo n.º 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);
  }