UI Test Automation
Testing is one of the software development life cycle stages. This stage is responsible for software reliability and high quality of an end-product. Testing provides you with useful information about a software developing project stage. Besides, it allows you to reduce the probability of bugs and future maintenance costs. Test automation significantly reduce amount of human mistakes and time you spend on testing.
The most frequently and widely used tool to automate web-interfaces testing is Selenium WebDriver. Being able to work with this tool means developing patterns to initialize and stop a web-driver, open and close a web-browse; creating waiting and web elements interacting methods, condition checking methods, etc. All these tasks are complicated, challenging and cruelly time-consuming.
Leadex Systems’ experts successfully use a range of tools and frameworks such as Gradle, Selenium WebDriver, Junit, Selenide, Java Video Recorder, Selenoid, Allure to facilitate and speed up the process of creating autotests, reduce a number of code lines, simplify it and finally make it a lot more comprehensive.
Our experts widely use Allure framework to generate detailed and accurate autotests reports. This tool allows to create the detailed autotest reports in which the step sequence, taken actions, validations and detected bugs are neatly displayed and divided into categories and entities. Moreover, we attach screenshots, screen records of the undergoing tests with highlighted clicks and validations and log files of the API response-reply to every single report. In that way, we have an ability to quickly interpret the autotests results, initially understand the reasons of the bugs, identify potential challenges in advance.
Once you have finished configuring Selenide, you will be able to start creating tests immediately. You will have to take over the responsibilities of a web driver initializing and setting up, along with adjusting a web-browser opening and closing settings. This tool is empowered with two main features: a build-in system of screenshots and friendly logging system.
We use Selenoid (the Selenium Hub implementation) to run autotests with multiple threads in parallel. Selenoid uses Docker-containers to start a web-browser. You can easily deploy scalable and stable Selenium Grid on any platform with the help of this tool. For instance, in one of our project we managed to reduce the runtime for 100 tests from 2 hours to 40 min running 3 threads in parallel.
But even working with these powerful tools we can achieve a better readability of tests cases and reduce time we spend on creating and maintaining those tests. One of the best ways to reach these goals is to choose the most suitable design pattern and programming language to create test cases. The patterns must be chosen according to your particular aims and requirements.
We usually code our tests in Kotlin. This programming language is Java compatible. Besides, it allows us to use the whole range of the Java toolkit using simplified Kotlin syntax.
Among the most useful Kotlin functions are: an extension function with infix modifier; operator overloading and when-expression. Thanks to these functions you can achieve amazing test cases code readability.
We use Java Video Recorder library to record a video of run tests. This tool allows you to record a video in the *avi format with the monte codec or in the *mp4 format with the ffmpeg codec. All files attached to Allure-report shall have the *mp4 extension.
When choosing ffmpeg you highly likely bump ConditionTimeoutException in the FFMpegRecorder class in the waitForVideoCompleted() method. We solved this tricky issue by using the monte codec to record a video and then converting the *avi file into the *mp4 one with the help of the Encoder class.
Encoder is the trivial class that converts *avi files into *mp4 ones with the same name. The encodeToMP4() method returns the *mp4 video-file totally ready to be attached to the report and then delete the original *avi file.
You have to mark all the methods involved into the testing process with the @Step annotation with description. Only this way Allure will thoroughly keep the records of the test steps and include them into the report. However, that is quite far from a finesse approach. We found out a lot more elegant decision to get rid of the repeated code.
As mentioned above, Selenide has a built-in logging system that tracks all web-driver events. We take advantage of this and implement LogEventListener in the StepBuilder class. This listener will form the current step in the onEvent() method and transit it to AllureLifecycle.
The override onEvent() method provides you with a certain amount of extra information. We only need data about some current actions.
Further we need to create an interface to transit elements headings which participating in interaction at the moment. You should concatenate them with the filtered events from onEvent() in StepBuilder.
So, the list of all tested elements and actions will be formed in a nice readable manner.
We usually run our tests via Selenoid in the docker-containers. It also has a power to start video-recorder for each of them in the form of a separate container. This container in its turn records video for each thread. There is only one thing left – to attach them to Allure as an html-page.
We also created the Highlighter class for the purposes of better visualisation. This class (with the help of Java Script) changes the element background color and makes it blinking before clicking the element or when checking it.
You have to register it in the method under the @Before annotation.
As a whole, all these tools, tips and tricks allow you to organise a highly effective UI testing system empowered with the flexible and comprehensive reports; to cut costs and reduce time spent on developing, running and maintaining autotests.
Project with examples: github.com/leadex/ui-test-automation-examples