Selenium-Jupiter: Selenium Tests with JUnit

Selenium is a widely used open source framework for end-to-end web testing nowadays. JUnit 5 is the latest version of this popular Java open source unit testing framework and implements a brand-new programming and extension model named Jupiter. This talk presents Selenium-Jupiter. This is an open-source JUnit 5 extension that provides seamless integration with Selenium. It allows creating Selenium tests using local or remote browsers, reducing the required boilerplate thanks to the dependency injection mechanism supported in JUnit 5. Moreover, it will enable us to use different types of web browsers and Android devices in Docker containers out of the box. All in all, Selenium-Jupiter can be used to carry out different types of tests for web and mobile applications, including functional, compatibility (using test templates to define different devices or browsers -types and versions-) or performance (using a significant number of browsers through Kubernetes) tests.

Selenium-Jupiter provides also advance capabilities for diagnostics, i.e., finding the root cause of a failed Selenium test. The first one is screenshotting. When a failure is detected, the state of the browser just before the failure happens can provide the clue to determine the nature of the problem. If the screenshot is not enough, the next step is to watch the browser during the test to observe the evolution of the web under test. This process is straightforward when running a test with the local browser, but it can be tricky in the usual case of running a test in a headless environment, such as Jenkins or Travis to name a few. In Selenium-Jupiter, this is done very smoothly thanks to the use of web browsers and Android mobile devices in Docker containers, in which the GUI session is recorded using VNC and FFmpeg. The last mechanism proposed is the access to browser logs to debug the JavaScript traces of our applications. Unfortunately, the Selenium API only allows us to do it when Chrome is used as a browser. The solution proposed is to use monkey patching in the console object at JavaScript level in a cross-platform browser extension, which is used to instrumentalize the browser (e.g., Firefox, Opera) controlled with Selenium WebDriver. To ease the access to such information, Selenium-Jupiter provides seamless integration with Jenkins and Slack, publishing the resulting files (PNG screenshots, MP4 recordings, and TXT logs) in the Jenkins GUI or Slack channel when a test fails.

Video producer: https://seleniumconf.in/