Wednesday 25 January 2017

Specflow, Selenium and TeamCity - Screenshots in TeamCity results

Trying to replicate automation test can be a real pain. Especially for those flaky test that fail from time to time.

As a result my team started to investigate how we could see what the test actually did while running.

Solution 1 - BrowserStack Automate
We started looking at BrowserStack Automate. The tool is impressive and integrates using the "RemoteWebDriver". You can then log into BrowserStack and watch videos of the test runs.

This was awesome but had some draw back. Specifically speed was an issue. Running the remote browser even in Parallel added about a 3rd to our run time. We run our automation test in TeamCity having yet another tool to monitor results was going to be tedious.

I recommend setting this up if only for the multiple browser support. https://www.browserstack.com/automate/specflow

Solution 2 - WebDriver Screenshot
We then decided to start taking screenshots of the state throughout the journey of the test. You can easily use the WebDriver to take a screenshots. We then would place this image on the Team City Agent.

This worked fast but still accessing the files and associating them to the test was not easy.

Solution 3 - TeamCity static content
Finally we have found a solution that worked for us. Making some tweaks to the screenshot solution we started to upload our images to S3. This meant we had friendly URLs we could spit out in our output logs.

Then using some hacky code we processed the logs and pulled the image content into the TeamCity stacktrace. Each image from the logs is pulled in order and appended to a list showing the journey as per our interactions. This lets us quickly build a view of what happened and spot obvious mistake.

Below is an example of how the screenshot is added to the page. The image shows on the expanded test failure.



How to : https://gist.github.com/tharris29/8c9b4aca6ae0b2bc2e3ce1b3ac406314

Excuse the hacky code and html. I will tidy it up one day. Fill free to improve it.

No comments:

Post a Comment