work: .net aop c sharp C# functional tests postsharp Selenium
by toni
leave a comment
AOP, NUnit and Selenium: clever screenshots of failures
Last week I did struggle finding out why a test was failing only on our Cruise box, only in the Cruise build.
I wanted to get a screenshot of each failing tests, and I think I found a clever solution: aop.
We already use PostSharp on our code base for logging, transaction demarcation and hibernate session support, so I wrote a simple annotation for our acceptance tests:
-
using System;
-
using PostSharp.Laos;
-
-
namespace Web.UI.AcceptanceTests
-
{
-
[Serializable]
-
public class ScreenCaptureAttribute : OnExceptionAspect
-
{
-
public override void OnException(MethodExecutionEventArgs eventArgs)
-
{
-
SeleniumManager.Selenium.CaptureScreenshot(string.Format("C:\\{0}.jpg", eventArgs.Method.Name));
-
}
-
}
-
}
Every time a test will throw an Exception Selenium will take a screenshot of the screen: pretty simple.
The only caveat is that it won’t work if Cruise is running as a service, and to get a decent result you’ll probably need to maximize the web browser windows.
work: acceptance tests functional tests javascript Selenium web webdriver
by toni
leave a comment
Suffering of Selenese Flu? Try webdriver
I’ve been suffering of selenese flu for months, being on a .net project we were using selenium RC. The typical symptoms are flaky, slow tests and sometimes a lot of sleeps in your code to make it work.
Selenium has its age and it struggles to cope with the current web 2.0 asynchronous calls & rich javascript.
Fortunately old good Simon is working hard at Google on webdriver, and in December the official port has been released also for the .net platform.
It works alright, there are some classes missing and you have to put the IE dll on your project as a content so that it gets copied on the bin folder to make it work.
A part from that, it’s faster, more reliable, more fun to write.
It’s time to cure your flu, webdriver is your medication.
Tibco GI? No thanks
Recently we tried TIBCO GI, I’ve to say that I’ve not been particularly happy with it, here is my list of cons:
- Not easy to test: impossible to test headless (is not supported by htmlunit), impossible to test with webdriver: Tibco provides a “Test Automation Kit”, however we had to write an extension of SeleniumServer in order to be able to write SeleniumRC from java… Pretty bad!
- It couples java, xml and javascript: yes it does, you write your objects in java, you configure them in xml and in the end you write some javascript that calls theirs java methods, a maintenance (and team on-boarding) mess!
- Yet another tool: to edit the UI there’s no plugin for Eclipse, you’ve to use a TibcoGI tool to edit the UI… Pretty bad!
- Small community: I found the community pretty small and completely unaware of the modern testing techniques (webdriver & htmlunit to start with)
- XML, XSL and Javascript: at the end it’s all about these three technologies, all together, a scary combination.
- Some browser are supported, some others.. No comment
Pros?
Well, you can write very quickly a pretty web interface but why not considering flex then?
Tired of slow functional tests?
If you are a good QA or just a good agile developer I’m sure you’re already testing your web applications with tools such as Selenium.(*)
If you’re seeking for continuous improvement I’m sure that you complained at least once on the speed of those testing and on the maintainability.
You might wanna then have a look on the results that the guys of Celerity have posted on their website, basically they migrated all their Watir functional tests wrapping htmlUnit instead of starting the browser through Watir.
First benchmarks are impressive:
| Scenario | Watir (total) | Celerity (total) | Time reduction |
|---|---|---|---|
| 1 | 316,97 s | 0,59 s | 99,81 % |
| 2 | 278 s | 86 s | 69 % |
| 3 | 128 s | 33 s | 74 % |
| 4 | 185,00 s | 4,67 s | 97,48 % |
If you are using Selenium rather than Watir don’t despair, Simon Stewart is working hard on webdriver, and if you switch to the htmlUnit driver your Selenium test you’ll have comparable improvements on the speed of your tests.
(*) many people might disagree with this sentence, if so have a look first the Simon Stewart presentation at GTAC 2007 and then let me know your thoughts.