I’ve been using Selenium and Watij for a while now (more Watij than Selenium). I’ve written about my prior experiences here and here. Watij — there is no significant development happening there for the last year or two. While Selenium Remote Control was nice, its IE support (especially IE 7) was not that great when I last evaluated (it may have improved since then).

I guess on Twitter, I first heard about WebDriver, and accolades about its approach and its API design. So decided to give it a try. Best part is Selenium and WebDriver projects are joining forces with a merger in Selenium 2.0. Per my understanding, the plan is to provide both Selenium and WebDriver APIs under Selenium 2.0 umbrella. At the time of writing this post Selenium 2.0a1 (Alpha-release) was out.

So here are my first impressions:

  • Approach: At the outset WebDriver is similar to Selenium (Remote Control) and Watij — developer-focused and API-driven. But the best part, for me at least, WebDriver doesn’t take the approach of running as a Javascript application within the browser (like Selenium), rather it takes JNA approach interacting with the browser. That approach rules out same origin issue (a headache with Javascript approach).  Also this doesn’t require native libraries installed and registered on the client (e.g: DLLs need to installed on the client for Watij).
  • API: API is intuitive. For example, following code snippet finds the element (text box, in this case) by name and simulate the typing by the sendKeys() method.
    driver.findElement(By.name("full_name")).sendKeys("Joe Schmo");
    

    Similarly,

    driver.findElement(By.name("Details")).click();
    

    finds the element (button, in this case) and clicks the button.

  • Multiple drivers: Unlike Watij, which only supports IE at this time, WebDriver supports — IE, Firefox, Chrome, and it also has a HtmlUnit version to run headless.
  • Window/Frame handling: This is yet another area where WebDriver excels with a caveat (that I’ll get into in a moment). When an operation like a button-click or a hyperlink-click opens a new pop-up browser, WebDriver provides an excellent way to get a handle to the new browser. Following call returns a set of all the window Ids.
    driver.getWindowHandles()
    

    You can iterate over the Set to find which one is your new window and switch to that window for all future operations.

    driver.switchTo().window(windowName)
    

    Windows’ handling is quite solid compared to handling of the Frames. In most of the situations it worked except when there are iFrames which load dynamically the behavior is not that consistent.

  • Wait behavior: When a particular operation (like a button-click) is underway WebDriver waits for the operation to finish before it executes the next step of the test case. Although this sounds trivial, I’ve had issues with this while using other tools. In those cases I had to use Thread.sleep() to wait between the page load and the execution of the subsequent step.
  • Alert Dialog: Couldn’t find a way yet to handle alert dialogs. I have to dig a bit more into the API and forums to see if they are supported at this time.
  • Mouse Events: I’d like to see more mouse events — double click, hover over an element, page scrolling, right click, etc.

Are you using WebDriver? What are your thoughts?

driver.findElement(By.name("q"));

Tags: , ,