Thursday, September 6, 2012

Selenium WebDriver utility for determining when page has finished rendering

We are using Selenium for automated testing of our web app.   We use the new Selenium WebDriver API to create java based unit tests for interfacing with the UI.  One problem we had was determining when the page had completely finished rendering as the page may still be in the process up updating after the initial page is loaded.   There is an ADF javascript function for checking this
the helper method below can be called by the test class to determine when the page is fully synchronized with the server and the next action can be performed.



public static void waitForPageToFinishRendering(WebDriver oDriver, int timeout) {
        ExpectedCondition e = new ExpectedCondition() {
            public Boolean apply(WebDriver d) {
              JavascriptExecutor js = (JavascriptExecutor) d;
              Boolean isReady = (Boolean)js.executeScript("return AdfPage.PAGE.isSynchronizedWithServer()");
              return isReady;
            }
          };
          WebDriverWait w = new WebDriverWait(oDriver,
timeout,100);
          w.until(e);
    }


For a Good overview of using Selenium with ADF see 
http://www.oracle.com/technetwork/articles/adf/part6-094560.html
That article talks about using waitForElementPresent before performing the next action but I have found using the technique above to be more reliable.  Especially for complex pages where there is a lot of lazy loading going on.

7 comments:

  1. Good article....

    http://www.evalleypoint.com/

    ReplyDelete
  2. Great tip, thanks very much! Works way better than the kludgy alternative methods, and seems to work well consistently.

    ReplyDelete
  3. Your welcome! glad it worked for you

    ReplyDelete
  4. Where can i get ADF javascript?

    ReplyDelete
  5. I'm not sure what it is your asking but the
    API docs can be found at http://docs.oracle.com/cd/E23549_01/apirefs.1111/e12046/index-all-I.html

    ReplyDelete
  6. We were new to selenium web driver.plz let me know the best article for beginners

    ReplyDelete
    Replies
    1. There are several on the project site. Start with "getting started"
      http://code.google.com/p/selenium/

      Delete