1 post from 2006
- January
- February
- March
- April
- May
- June
- July
- August
- September
- October
- November
- December
I have recently been experimenting with using Selenium for testing web applications, and have had both positive and negative experiences. Selenium tests run directly in a browser; the browser can be specified at runtime via a constructor argument. For example:
public void setUp() {
sel = new DefaultSelenium("localhost",
4444, "*firefox", "http://url-of-app-being-tested:port");
sel.start();
}
The tests themselves take the form of the following:
public void testLinkNotPresent() {
sel.open("/");
sel.isTextPresent(LINK_TEXT);
}
See the JavaDoc for the DefaultSelenium class for more information on how to build tests.
Now, while this has proven to be a useful tool, my main hesitation revolves around the speed of the tests. If you are using JUnit 3.x -- not uncommon in most Java shops -- each of your test* methods will have a new DefaultSelenium object created. This means that a new browser window will be created for each test. And it's not just that a new browser window is opened, but that they are opened multiple times for each test: apparently the browser is initially loaded to have its proxy settings set so that it will talk to the Selenium server, then closed, then reloaded, then reloaded again for some reason, at which point the tests actually start.
My test class called had only 7 tests total in it, but nonetheless it took some 3 minutes to run.
The Selenium website recommends using TestNG to alleviate this problem with the setUp() method, and apparently JUnit4 also provides a global "setUp" method that only gets called once. Neither of these are suitable options.
The final nail in the coffin was that Safari is not a supported browser.
Final verdict: Selenium is interesting, but still needs work. My next step is to compare it with jWebUnit.
Edit: Ran across this in a JUnit FAQ: How do I run setup code once for all my TestCases? This recommends modifications to your suite class, but if you aren't using suites (I am not) it's not very helpful.