views:

58

answers:

3

Hi, I'm using PHPUnit's Selenium extension to do web testing. I'm finding it very slow, taking seconds for a single test method. Part of the issue appears to be that its starting a new Selenium session between each test method (getNewBrowserSession), as part of runTest(). This is expensive. I'm ok with running a class or even a whole suite's worth of test methods in a single selenium session.

Can this be done? Are there other tips for speeding up PHPUnit + Selenium?

Thanks.

+1  A: 

You need to share the Selenium instance between your tests. I am not familiar with PHPUnit, but in JUnit you use static member (create a base test class that holds the Selenium instance and all tests should extend it). In TestNG you can use test context.

Also try to minimize the usage of XPath if you test on IE - absence of native XPath makes tests run slower.

Also Selenium 1 uses JavaScript to drive the browser, so it is somewhat slow on IE. Selenium 2 (aka WebDriver) uses native methods to drive the browser, so at least IE tests are faster.

ZloiAdun
Thanks, we already hit the XPath performance problem on IE and are using locators and JQuery. And we're using Selenium 2.
Schwern
So then you need to create a WebDriver on the suite start and call WebDriver.quit() only on the suite end
ZloiAdun
A: 

I'd suggest you to build Continous Integration system to run test at night. Then at morning you will have information what test are ok and what no. Check Hudson.

Igor Rodinov
We're already using Hudson. Overnight testing is far too long to wait for the tests to be of use to directly aid and speed development. We use the continuous integration system to run tests against the full battery of browser types and versions and operating systems.
Schwern
+3  A: 

Have you tried using the browserSessionReuse option? E.g. starting selenium with

java -jar ./selenium-server.java -browserSessionReuse
borrible
Thank you, that sped up the tests immensely!
Schwern