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"));
Follow on Twitter
Trackback: uberVU - social comments
#1 by Simon Stewart on December 17th, 2009
Quote
Hi, great to hear that you’re enjoying webdriver! You raise some good points, so I thought you might be interested to hear how we’re planning on handling them.
We plan on handling alert dialogs with a blocking API (“driver.switchTo().alert()”) The same API will be used for prompts and confirms too. The most recent discussion, which fleshes out the plan a bit more, is here (apologies for the massive URL!)
https://groups.google.com/group/webdriver/tree/browse_frm/thread/eff940e74bd493fd/1c23c0408eb36619?rnum=1&q=alert&_done=%2Fgroup%2Fwebdriver%2Fbrowse_frm%2Fthread%2Feff940e74bd493fd%2F1c23c0408eb36619%3Ftvc%3D1%26q%3Dalert%26#doc_e018e0cbce9b3d2e
With the RenderedWebElement, it’s already possible to call “hover”, but you’re right that there’s missing functionality. This is another thing that we plan on adding, though right now we’re focussing on making sure that the pieces that we’ve got work as they should before pushing in more code
If there’s something that you really need, please let us know!
[Reply]
Surya Suravarapu Reply:
December 17th, 2009 at 11:24 am
Simon, thanks for the comments.
After working with (and evaluating) various API-based testing frameworks I have no hesitation to say WebDriver is extremely promising. In fact, the scenarios that I used (for evaluation) were non-trivial and have a fair bit of complexity in terms of varied controls, multiple windows, iFrames, etc. I was pleasantly surprised to see how little I paused while writing my test code.
An active team can address the missing functionality, I’m hopeful. Kudos to the team!
[Reply]
Ankush Reply:
February 11th, 2010 at 6:32 am
Hi Surya,
I need some help. I am a new user of webdriver.
In my application there is a functionality where user has to upload a file using windows File upload window. I am not able to handle it. Can you help me in that..
[Reply]
AndreyO Reply:
February 16th, 2010 at 11:52 am
Same issue, how to work with File Uploader ?
[Reply]
Jerome Velociter Reply:
February 24th, 2010 at 10:21 am
For file upload you can check out the example here : http://www.google.com/codesearch/p?hl=en#2tHw6m3DZzo/trunk/common/test/java/org/openqa/selenium/UploadTest.java&q=Upload%20package:http://selenium\.googlecode\.com&sa=N&cd=5&ct=rc
[Reply]
#2 by Ankush on February 11th, 2010
Quote
Hi, I was trying to use the webdriver. In my application there is a functionality where user has to attach a file. The application opens a windows “File Upload” box. I am not able to handle this window. Can any one help me.
Thanks
[Reply]