Pimp my testAUTOmation (Part 1)

Selenium 4 & Screenshots

Software development projects live from the use of modern testing tools, which support the project members in their work. Selenium has been available since 2004 and may seem a bit dusty, but it is not out of fashion. With Selenium 4 it is catching up with the new challenges. With this blog series, I want to show what Selenium 4 brings and how important features like screenshots, videos, reports and approaches of AI can be implemented using simple means. I will try to evaluate the approaches according to their added value (The Good) and their challenges (The Bad) as well as give useful hints (… and the Useful).

Jason Huggins started working on Selenium back in 2004 as an internal project for testing websites. Over time, Selenium became the leading tool in many development projects or served as the basis for other testing tools. Currently, the framework feels a bit old-fashioned, but it stands out from its challengers with its broad support of languages (Ruby, Java, Python, C#, JavaScript) and browsers (Firefox, Internet Explorer, Safari, Opera, Chrome, Edge and others).

What is new in Selenium 4?

Version 4, which is announced for 2020, attempts to bring selenium into the modern age. This includes the following innovations:

WebDriver API becomes a W3C standardThis means there will be only one WebDriver for all browsers.
Selenium4 IDE TNG„TheNextGeneration“ Selenium IDE is based on Node JS and is available for Firefox and Chrome. Parallel test runs can be started and there is extended test protocol information (test result, runtime etc.).
Improved WebDriver GridSetup, administration and docker support have been improved.
FurthermoreThere is a better UI and the reporting / logging have been optimized.
DocumentationVersion 4 should come with a detailed documentation and new tutorials.

With version 4, Selenium consists of the following parts: The Selenium WebDriver, the Selenium IDE and the Selenium Grid. The Selenium WebDriver is a collection of different programming language integrations to control browsers for test automation. The Selenium IDE is a Chrome or Firefox add-on to start test automation directly from the browser without programming knowledge and allows the recording and the play back of test cases in the browser. The Selenium Grid allows controlled and simultaneous test executions on different machines and supports the administration of different test environments from a central point. Thus, a test case can be tested against different browser or operating system combinations or a list of test cases can be executed scaled and distributed over several machines.

Selenium 4

The GoodThe Bad… and the Useful
WebDriver API >> W3C
Selenium 4 IDE TNG
Improved WebDriver Grid
New challenger like cypress etc.
Selenium 4 was announced for 2019

Latest Selenium 4 Alpha version 4.0.0-alpha-5

Screenshots can help with testing!

Newer frameworks for test automation already have a function for creating screenshots. But with a few lines of code, you can also add the possibility to store screenshots in selenium tests.

private void screenShot(RemoteWebDriver driver, String folder, String filename) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HHmmss");
    String timestamp  = dateFormat.format(new Date());
    try {
        File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
        // Now you can do whatever you need to do with it, for example copy somewhere
        FileUtils.copyFile(scrFile, new File(folder + filename + "_" + timestamp + ".png"));
    catch (IOException e) {

However, you should always pay attention to the purpose of screenshots when creating and storing the file. Screenshots can be used for debugging purposes and to point out problems. Therefore, it makes sense to create screenshots only when problems occur. According to this approach, the screenshot functionality can be extended by a flexible and global switch that can be set as needed.

On the other hand, screenshots can be used to document the test results and may even be mandatory in some projects, as legal or other requirements must be met in such cases. In this case, the storage of the screenshots must be traceable, and each generated file must be assigned to a test case and the corresponding test run. According to this approach, the file name must have a reference to the test case and a suitable timestamp. Furthermore, the storage directory for this one test run must also be created and named.


The GoodThe Bad… and the Useful
Allows the verification of the test run resultsCan only show a snapshotCan be used for “debugging”

In my next post we will create a video of the test implementation.

This post was written by: