Allow your Selenium suites to store automatically screenshots taken for every failed test in maven target folder for further usage. For example, you can include the screenshot of a failed test in email sent by your CI-build.
-
Add the following maven dependency in you
pom.xml
file:<dependency> <groupId>com.github.yev</groupId> <artifactId>screenshot</artifactId> <version>1.0</version> </dependency>
-
Add this annotation
@org.testng.annotations.Listeners(org.yev.selenium.testng.FailTestScreenshotListener.class)
to your TestNG Selenium class: -
The plugin will find by reflection the webDriver instance you are using and will do the rest for you.
After running your testNg selenium tests with maven, you will find for each failed test the screenshot which was taken automatically when this particular test failed.
It's very useful to get the screenshot of failed test directly within the email alert sent by Jenkins when build becomes unstable. So for our example case the jenkins config will be following: