Ejemplo n.º 1
2
  /**
   * Wait up to By element present
   *
   * @param element
   */
  public void waitForElement(By element) {

    try {
      wait = new WebDriverWait(driver, 60);
      wait.until(visibilityOfElementLocated(element));
    } catch (Exception e) {
    }
  }
  @Test
  public void testLogging() {

    driver = new HtmlUnitDriver();
    wait = new WebDriverWait(driver, 20);

    driver.get(pathHost + pathContext);

    // Article list
    wait.until(ExpectedConditions.textToBePresentInElement(By.id("headerTitle"), "Chris`s Blog"));
    // conditions
    header = driver.findElement(By.id("headerTitle")).getText();
    Assert.assertEquals("Chris`s Blog", header);
    title = driver.getTitle();
    Assert.assertEquals("Chris`s Blog - List of Articles", title);
    text = driver.findElement(By.id("hello-world-servlets_titleList")).getText();
    Assert.assertEquals("Hello World Servlets", text);
    // actions
    driver.findElement(By.id("login")).sendKeys("tmp");
    driver.findElement(By.id("password")).sendKeys("tmp");
    driver.findElement(By.id("signIn")).click();

    // Article list
    wait.until(ExpectedConditions.textToBePresentInElement(By.id("headerTitle"), "Chris`s Blog"));
    // conditions
    header = driver.findElement(By.id("headerTitle")).getText();
    Assert.assertEquals("Chris`s Blog", header);
    title = driver.getTitle();
    Assert.assertEquals("Chris`s Blog - List of Articles", title);
    text = driver.findElement(By.id("hello-world-servlets_titleList")).getText();
    Assert.assertEquals("Hello World Servlets", text);
    text = driver.findElement(By.className("textMsg")).getText();
    Assert.assertEquals("Incorrect email or password.", text);
  }
Ejemplo n.º 3
1
 /**
  * Wait up to String locator present
  *
  * @param selector
  */
 public void waitForElement(String xpath) {
   wait = new WebDriverWait(driver, 50);
   try {
     wait.until(visibilityOfElementLocated(By.xpath(xpath)));
   } catch (Exception e) {
   }
 }
Ejemplo n.º 4
0
 private void waitUntil(Function<WebDriver, Boolean> function) {
   Wait<WebDriver> wait =
       new FluentWait<WebDriver>(AbstractTest.driver)
           .withTimeout(AbstractTest.LOAD_TIMEOUT_SECONDS, TimeUnit.SECONDS)
           .pollingEvery(AbstractTest.POLLING_FREQUENCY_MILLISECONDS, TimeUnit.MILLISECONDS)
           .ignoring(NoSuchElementException.class);
   wait.until(function);
 }
Ejemplo n.º 5
0
  public SampleSites(WebDriver driver) {
    super();
    this.driver = driver;

    Wait<WebDriver> wait =
        new FluentWait<WebDriver>(driver).withTimeout(30, SECONDS).pollingEvery(2, SECONDS);

    wait.until(ExpectedConditions.titleIs("Sample Sites"));
  }
Ejemplo n.º 6
0
 /**
  * Do a wait on the select2 field.
  *
  * @throws TimeoutException
  * @since 6.0
  */
 private void waitSelect2() throws TimeoutException {
   Wait<WebElement> wait =
       new FluentWait<WebElement>(
               !multiple
                   ? driver.findElement(By.xpath(S2_SINGLE_INPUT_XPATH))
                   : element.findElement(By.xpath(S2_MULTIPLE_INPUT_XPATH)))
           .withTimeout(SELECT2_LOADING_TIMEOUT, TimeUnit.SECONDS)
           .pollingEvery(100, TimeUnit.MILLISECONDS)
           .ignoring(NoSuchElementException.class);
   Function<WebElement, Boolean> s2WaitFunction = new Select2Wait();
   wait.until(s2WaitFunction);
 }
Ejemplo n.º 7
0
  public <T> void waitUntilCondition(ExpectedCondition<T> condition) {
    // Temporarily remove the implicit wait on the driver since we're doing our own waits...
    getDriver().manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);

    Wait<WebDriver> wait = new WebDriverWait(getDriver(), getTimeout());
    try {
      wait.until(condition);
    } finally {
      // Reset timeout
      setDriverImplicitWait(getDriver());
    }
  }
Ejemplo n.º 8
0
  private WebElement waitForElementFound(final By by) {
    Wait<WebDriver> wait =
        new FluentWait<WebDriver>(driver)
            .withTimeout(30, TimeUnit.SECONDS)
            .pollingEvery(5, TimeUnit.SECONDS)
            .ignoring(NoSuchElementException.class);

    return wait.until(
        new Function<WebDriver, WebElement>() {
          public WebElement apply(WebDriver driver) {
            return driver.findElement(by);
          }
        });
  }
Ejemplo n.º 9
0
  protected WebElement fluentWait(final By locator) {
    Wait<WebDriver> wait =
        new FluentWait<WebDriver>(driver)
            .withTimeout(10, TimeUnit.SECONDS)
            .pollingEvery(1, TimeUnit.SECONDS)
            .ignoring(NoSuchElementException.class);

    WebElement foo =
        wait.until(
            new Function<WebDriver, WebElement>() {
              public WebElement apply(WebDriver driver) {
                return driver.findElement(locator);
              }
            });
    return foo;
  };
Ejemplo n.º 10
0
  public RelationTabSubPage setRelationWithDocument(String documentName, String predicateUri) {

    org.junit.Assert.assertFalse(isObjectDocumentChecked());

    Select predicateSelect = new Select(predicate);
    predicateSelect.selectByValue(predicateUri);

    Select2WidgetElement documentSuggestionWidget =
        new Select2WidgetElement(driver, driver.findElement(By.xpath(SELECT2_DOCUMENT_XPATH)));

    documentSuggestionWidget.selectValue(documentName);

    Function<WebDriver, Boolean> isDocumentSelected =
        new Function<WebDriver, Boolean>() {
          @Override
          public Boolean apply(WebDriver driver) {
            WebElement selectedDocument = driver.findElement(By.id(OBJECT_DOCUMENT_UID_ID));
            String value = selectedDocument.getAttribute("value");
            boolean result = StringUtils.isNotBlank(value);
            if (!result) {
              log.debug("Waiting for select2 ajaxReRender");
            }
            return result;
          }
        };

    org.junit.Assert.assertTrue(isObjectDocumentChecked());

    Wait<WebDriver> wait =
        new FluentWait<WebDriver>(driver)
            .withTimeout(SELECT2_CHANGE_TIMEOUT, TimeUnit.SECONDS)
            .pollingEvery(100, TimeUnit.MILLISECONDS)
            .ignoring(StaleElementReferenceException.class);

    wait.until(isDocumentSelected);

    if (log.isDebugEnabled()) {
      WebElement selectedDocument = driver.findElement(By.id(OBJECT_DOCUMENT_UID_ID));
      log.debug("Submitting relation on document: " + selectedDocument.getAttribute("value"));
    }

    addButton.click();

    return asPage(RelationTabSubPage.class);
  }
  public void waitForPageLoaded(WebDriver driver) {

    ExpectedCondition<Boolean> expectation =
        new ExpectedCondition<Boolean>() {
          public Boolean apply(WebDriver driver) {
            return ((JavascriptExecutor) driver)
                .executeScript("return document.readyState")
                .equals("complete");
          }
        };

    Wait<WebDriver> wait = new WebDriverWait(driver, 30);
    try {
      wait.until(expectation);
    } catch (Throwable error) {
      assertEquals("Timeout waiting for Page Load Request to complete.", false, true);
    }
  }
Ejemplo n.º 12
0
  /**
   * @param locator
   * @return
   */
  public WebElement fluentWait(final By locator) throws NoSuchElementException, TimeoutException {
    Wait<WebDriver> wait =
        new FluentWait<WebDriver>(driver)
            .withTimeout(12, TimeUnit.SECONDS)
            .pollingEvery(2, TimeUnit.SECONDS);
    //				.ignoring(NoSuchElementException.class);

    WebElement foo =
        wait.until(
            new Function<WebDriver, WebElement>() {
              public WebElement apply(WebDriver driver) {
                WebElement foundElement = driver.findElement(locator);
                return foundElement;
              }
            });

    return foo;
  };
Ejemplo n.º 13
0
  // XXX: in some cases firefox not wait for the full page to load after calling .get or .click.
  // This may cause immediate find's to break and using an implicit or explicit wait doesn't help
  private WebElement fluentWaitForElement(final By locator) {
    Wait<WebDriver> wait =
        new FluentWait<WebDriver>(getDriverProvider().get())
            .withTimeout(PageObject.DEFAULT_WAIT_TIMEOUT, PageObject.DEFAULT_WAIT_TIMEOUT_UNIT)
            .pollingEvery(PageObject.DEFAULT_RETRY_TIMEOUT, PageObject.DEFAULT_RETRY_TIMEOUT_UNIT)
            .ignoring(NoSuchElementException.class);

    WebElement element =
        wait.until(
            new Function<WebDriver, WebElement>() {
              @Override
              public WebElement apply(WebDriver driver) {
                return driver.findElement(locator);
              }
            });

    return element;
  }
 /**
  * Login into ADL SCORM Test Course
  *
  * @param course
  */
 public void loginCourse(int course) {
   driver.findElement(By.linkText("SCORM 1.2 ADL Test course")).click();
   wait.until(presenceOfElementLocated(By.id("username")));
   driver.findElement(By.id("username")).clear();
   driver.findElement(By.id("password")).clear();
   if (course != 2) {
     driver.findElement(By.id("username")).sendKeys("joestudent");
     driver.findElement(By.id("password")).sendKeys("joestudent");
   } else {
     driver.findElement(By.id("username")).sendKeys("marylearner");
     driver.findElement(By.id("password")).sendKeys("marylearner");
   }
   driver.findElement(By.id("loginbtn")).click();
   wait.until(presenceOfElementLocated(By.xpath("//span[text()='ADL SCORM Test Course I']")));
   if (course != 1) {
     driver.findElement(By.xpath("//span[text()='ADL SCORM Test Course II']")).click();
   } else {
     driver.findElement(By.xpath("//span[text()='ADL SCORM Test Course I']")).click();
   }
 }
Ejemplo n.º 15
0
  @Test
  public void myFirstGoogleTest() {
    driver.get("http://www.google.com");

    ((WebDriverWait) wait).withTimeout(60, TimeUnit.SECONDS);

    WebElement searchBox = driver.findElement(By.name("q"));
    searchBox.sendKeys("Cheese");

    WebElement navend = wait.until(navEndIsVisibleAndTitleContains("heese"));
  }
Ejemplo n.º 16
0
  public RelationTabSubPage initRelationSetUp() {
    addANewRelationLink.click();

    Function<WebDriver, Boolean> createRelationFormVisible =
        new Function<WebDriver, Boolean>() {
          @Override
          public Boolean apply(WebDriver driver) {
            return createRelationForm != null;
          }
        };

    Wait<WebDriver> wait =
        new FluentWait<WebDriver>(driver)
            .withTimeout(CREATE_FORM_LOADING_TIMEOUT, TimeUnit.SECONDS)
            .pollingEvery(100, TimeUnit.MILLISECONDS)
            .ignoring(NoSuchElementException.class);

    wait.until(createRelationFormVisible);

    return asPage(RelationTabSubPage.class);
  }
 /**
  * Test all SCOes
  *
  * @param mode
  * @param course
  * @param scoLeft
  */
 public void testSCO(char mode, int course, int scoLeft) {
   wait.until(presenceOfElementLocated(By.id("n")));
   String url = driver.getCurrentUrl();
   if (mode == 'b') {
     driver.findElement(By.id("b")).click();
   } else {
     driver.findElement(By.id("n")).click();
   }
   driver.findElement(By.xpath("//input[@value='Enter']")).click();
   wait.until(presenceOfElementLocated(By.id("ygtvcontentel2")));
   wait.until(presenceOfElementLocated(By.id("scorm_object")));
   System.out.println("SCO Loaded. Testing ...");
   driver.switchTo().frame("scorm_object");
   if ((course == 1 && currentSCO != 4) || (course == 2 && currentSCO != 2)) {
     wait.until(
         presenceOfElementLocated(
             By.xpath("//*[contains(.,'Status:  This SCO Test Completed.')]")));
   } else if ((course == 1 && currentSCO == 4) || (course == 2 && currentSCO == 2)) {
     // for both course 1 and course 2
     if (scoLeft != 0) {
       wait.until(
           presenceOfElementLocated(
               By.xpath("//*[contains(.,'Please Log out and re-login to the LMS.')]")));
       return;
     } else {
       wait.until(
           presenceOfElementLocated(
               By.xpath("//*[contains(.,'Status:  This SCO Test Completed.')]")));
     }
   }
   System.out.println(driver.findElement(By.id("teststatus")).getText());
   currentSCO++;
   driver.get(url);
 }
Ejemplo n.º 18
0
 @Test
 @Ignore("Not passing from the command line")
 public void webDriverTimesOut() throws InterruptedException, MalformedURLException {
   String url = hub.getConsoleURL().toString();
   DesiredCapabilities caps = GridTestHelper.getDefaultBrowserCapability();
   WebDriver driver = new RemoteWebDriver(hub.getWebDriverHubRequestURL(), caps);
   driver.get(url);
   assertEquals(driver.getTitle(), "Grid Console");
   wait.until(
       new Function<Object, Integer>() {
         @Override
         public Integer apply(Object input) {
           Integer i = hub.getRegistry().getActiveSessions().size();
           if (i != 0) {
             return null;
           }
           return i;
         }
       });
   assertEquals(hub.getRegistry().getActiveSessions().size(), 0);
 }