{
"$type": "site.standard.document",
"path": "/selenium-screenshots-in-continuous-integration/",
"publishedAt": "2016-09-08T20:56:28.000Z",
"site": "at://did:plc:6gssgguzeecdttuw4gpdshg2/site.standard.publication/self",
"tags": [
"selenium",
"testing",
"coding",
"travis-ci",
"gradle",
"automation",
"java"
],
"textContent": "There is nothing worse that when your tests fail only on your continuous integration server. This non-deterministic behaviour can be a pain to debug. This is compounded when testing with Selenium. If you can't see the state of the browser when a test fails how can you fix the issue?\n\nThis week we had an issue with a test that kept failing only on CI. In order to fix the issue, I ended up writing a jUnit test watcher that will take a screenshot of the failure and email it out to our team.\n\nI've talked about our automated acceptance testing before. http://broonix-rants.ghost.io/automated-acceptance-tests/. Lubos, from our development team, wrote a nice how-to that replicates a minimalistic version of our setup. https://lkrnac.net/blog/2016/01/run-selenium-tests-on-travisci/. The code below builds on this setup.\n\nOur setup is pretty standard. Our app (Java/React) is built with Gradle on Travis-ci. While this how to will focus on our setup. It should be adaptable to any other build system.\n\nI'm going to use Lubos' code from the link above as a starting point. Here is a basic test class that uses Selenium.\n\n[Embedded code (GitHub Gist)]\n\nWe'll implement screenshot capture using a jUnit test watcher. Our watcher will look to see if we are running on Travis-ci and if the failure is Selenium related. If it is a screenshot will be taken (if possible) then emailed out to the team.\n\n[Embedded code (GitHub Gist)]\n\nSo far this has proven a rather useful addition to our test setup.\n\nRead the original post with all embeds and interactive content at https://rants.broonix.ca/selenium-screenshots-in-continuous-integration/",
"title": "Selenium Screenshots in Continuous Integration"
}