Monday, September 24, 2012

Selenium IE Webdriver in Java

Recently at the company I work for, we've been using the Robot Framework and Selenium for automated testing.  We've had great success so far, Firefox and Chrome have been working great.  However, IE was a bit more problematic for us.  The default IE web driver for IE has been very flaky for us.  We've had issue such as xpath expressions failing, random javascript errors and even crashes.  Even when testing on Sauce Labs, we've experienced these issues.  Given that these same tests worked for Chrome and Firefox without issue, naturally we blamed the IE driver.

After we gave up on the standard IE driver, we started researching other solutions for testing IE.  Watir was the first interesting project we looked at.  It looked good, but it was a Ruby project and we don't have much Ruby expertise.  I found a java equivalent called Watij and that showed more promise for us.  Unfortunately, the project is several years old and didn't support 64-bit JVM's.  In addition, Watij is based on a set of proprietary COM API's from a company called teamdev.  This made it difficult to track down issues when the COM calls would fail.  So I started evaluating calling IE COM directly from Java.

I finally settled on COM4j for the bulk of the IE interaction with addtional help from JNA to call some of the win32 API's.  This combination has worked well for us and we were able to get a Java IE WebDriver going.  We've created a googlecode project to host this effort:
http://code.google.com/p/java-ie-webdriver/

So far we've had great success with this driver and one of our projects has 50+ robot tests that are all passing in both IE 8 and IE 9 using this driver.  At this point, most of the driver is implemented, including all the element finder methods and full file upload support. So feel free to give it a try and let us know how it works for you.

8 comments:

  1. Hi Tom thanks for this wonderful solution. I installed the IEDriverServer-amd64 to my machine but when I run my script tests, I found this configuratation error/warning "Could not find Native class" in this file IEDriverServer.log

    info] Module Name: C:\Selenium\IEDriverServer.exe
    [info] Module INI: C:\Selenium\IEDriverServer.ini
    [info] Module Dir: C:\Selenium\
    [info] INI Dir: C:\Selenium\
    [info] Working directory set to: C:\Selenium
    [info] Found VM: C:\Program Files\Java\jre7\bin\server\jvm.dll
    [info] Expanding Classpath: IEDriverServer-start.jar
    [info] Generated Classpath: C:\Selenium\IEDriverServer-start.jar
    [info] VM Args:
    [info] vmarg.0=-Djava.class.path=C:\Selenium\IEDriverServer-start.jar
    [info] Main Class: com/googlecode/javaiewebdriver/remote/JavaIEWebDriverRemote
    [info] Registering natives for Native class
    [warn] Could not find Native class
    2013-01-30 15:32:12.251:INFO:oejs.Server:jetty-7.x.y-SNAPSHOT
    2013-01-30 15:32:12.282:INFO:oejsh.ContextHandler:started o.e.j.s.ServletContextHandler{/,null}
    2013-01-30 15:32:12.298:INFO:oejs.AbstractConnector:Started SelectChannelConnector@0.0.0.0:3001

    what do I need to change from your configuration settings in this file (IEDriverServer.ini)?

    working.directory=c:\seleniumgrid\
    main.class=com.googlecode.javaiewebdriver.remote.JavaIEWebDriverRemote
    classpath.1=IEDriverServer-start.jar
    vm.location=C:\Program Files\Java\jre7\bin\server\jvm.dll
    log=IEDriverServer.log

    ReplyDelete
  2. I get the same warning in my logs too. I think you can ignore it. It looks like the jetty listener is starting up, so you should be good to go.

    ReplyDelete
  3. Hi Tom I tried your solution because the Selenium server was not working, it seems to run fine at the begining but I can make findElement work with xpath at all, I have tried different xpath sintax version but still no luck

    ReplyDelete
  4. I've been able to use xpath without issue. Is it not finding the elements or is it erroring out? One thing I've noticed is that if the html is invalid, there may be a mismatch between the IE dom and the dom that java creates. Also, IE makes all the tags upper case, so the xpath needs to be upper case. (For the common cases, I handle this automatically, but there may be cases I'm missing) It would help if you could create a unit test--or at least give more details about what isn't working.

    ReplyDelete
  5. This comment has been removed by a blog administrator.

    ReplyDelete
  6. This comment has been removed by a blog administrator.

    ReplyDelete
  7. This comment has been removed by a blog administrator.

    ReplyDelete
  8. This comment has been removed by a blog administrator.

    ReplyDelete