Friday, February 18, 2011

Load Testing with Google's WebDriver

I have been working with WebDriver/Selenium 2 for some time now; I implemented it for my team at work and have since discovered ways to do load testing.

I code primarily in C#, but if this were to be done in Java you could take advantage of the headless browser driver (HtmlUnitDriver), which would allow you to potentially run 100s of tests at once. IKVM allows you to convert this to C#, but when I did this I discovered that a 5 second test took 2 minutes or more to run, and I wasn't willing to deal with that.

A viable option for a headless browser I found for C# is an open source project called SimpleBrowser, it doesn't support JavaScript but it's the foundation for a bigger project called XBrowser that will support not only JavaScript but HTML5, SVG, and Canvas.
It's not implemented in WebDriver but I was easily able to run 100 concurrent instances of SimpleBrowser performing a simple test.

Anyway, on to the code:



Some notes:
  1. You will need to use a delegate to pass parameters to the test, in this case I've used a lambda expression.
  2. I've run into problems trying to run this as a unit test:
  • For some reason, a unit test doesn't run the threads all at once, instead it will run them one at a time.
  • You will have to spin the main thread while it waits for the other threads to finish.

Recommended reading: