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:
- You will need to use a delegate to pass parameters to the test, in this case I've used a lambda expression.
- 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:
"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."
ReplyDeleteWere you running this in the debugger (F5 in Visual Studio) by any chance?
Running it outside of the debugger (Ctrl-F5) is usually *much* faster, because Java code tends to throw a lot of exceptions and the Visual Studio debugger is very slow with exceptions.
I didn't consider that, I was indeed using the debugger.
ReplyDeleteI'll have to give that a try..
Would be interested to hear your findings on test scalability and resource utilization. How much system resources are taken up for running these tests and how far can you scale up.
ReplyDelete