We have built a pretty classical stack for running test:
- Jenkins master - main entry point and orchestrator of the build
- Jenkins swarm client on a Windows 8 PC with IE 11 - where the builds are executed
- Maven Surfire Plugin
- TestNg
- Selenium
One of the problem I encountered was not very user-friendly alert about failed tests. Jenkins send an email with a link to the unstable build. No details about failed tests, no exceptions, just a link. So I need to open my laptop, turn on my VPN, go to Jenkins server and see the details.
Too many steps.
It would be great to get a detailed alert. It's not a problem with Jenkins' Editable Email Notification and special token ${FAILED_TESTS}. This token will bring in your email detailed information about failed test. I love stacktraces, but for normal people it's a mess and frankly speaking it takes some time to understand what's going on even for a geek.
So my idea was to send a screenshot of every failed test within Jenkins alert notification. So this way, it takes a second to see the broken page and understand the root cause.
For this we will need to use the following tricks:
- org.testng.TestListenerAdapter.onTestFailure is triggered when a test is failed.
- org.openqa.selenium.TakesScreenshot takes a screenshot
- copy the screenshot to maven target folder for further usage
- use Jenkins Editable Email Notification/Attachments feature
First 3 steps are already implemented in this maven project - https://github.com/yev/seleniumMvnScreenshot
To use it you need to add the following dependency in your pom.xml file which holds the selenium tests.
To use it you need to add the following dependency in your pom.xml file which holds the selenium tests.
com.github.yev screenshot 1.0
The 4 step is only about jenkins config:
Go to your Jenkins job configuration |
Modify the regexp path to match your maven project holding the selenium test |
Post your comments here or in my twitter if you have some questions or idea to improve this stuff.