This Jenkins pipeline is designed to execute Selenium UI tests using Maven, JDK 11, and ChromeDriver on an Ubuntu Server environment. The pipeline leverages Xvfb (X Virtual Framebuffer) to create a virtual display for running tests and records the test execution as a video using FFmpeg. The primary goal is to provide a visual representation of the test run.
DISPLAY
: Specifies the X server display number (":99") for Xvfb.VIDEO_FILE_NAME
: Specifies the name of the video file generated during the test execution (default is 'test.mp4').
- Maven version 3.8.3 is used (
maven 'mvn3.8.3'
). - JDK version 11 is used (
jdk 'jdk11'
).
- Installs FFmpeg and sets up Xvfb to create a virtual display for headless test execution.
- Starts recording the virtual display using FFmpeg.
- Downloads the ChromeDriver package from a specific URL and extracts it into Jenkins workspace.
- Kills the Xvfb and FFmpeg processes to clean up resources post execution of tests.
Xvfb is a virtual framebuffer X server. It allows you to run graphical applications without a physical display. In the provided Jenkins pipeline, Xvfb is used to create a virtual display, and the tests are executed on this virtual display.
Xvfb :99 -ac -screen 0 1280x1024x24 &
: Starts Xvfb with the following options::99
: Specifies the display number as 99.-ac
: Disables access control for X server, allowing connections from any host.-screen 0 1280x1024x24
: Defines the screen parameters, specifying a screen with resolution 1280x1024 and 24-bit color.
FFmpeg is a powerful multimedia processing tool that can be used to encode, decode, and transcode multimedia files. In the provided Jenkins pipeline, FFmpeg is used to capture the virtual display created by Xvfb and save it as a video file.
-
sudo apt-get update && sudo apt-get install ffmpeg -y
: Updates the package list and installs theffmpeg
package. This can be baked into Jenkins agent AMI. -
ffmpeg -f x11grab -i :99 -c:v libx264 -preset ultrafast -tune zerolatency -crf 25 ./${VIDEO_FILE_NAME} &
: Uses ffmpeg to record the virtual display:-f x11grab
: Specifies the input format as x11grab.-i :99
: Specifies the input source as the Xvfb display on:99
.-c:v libx264
: Specifies the video codec as libx264.-preset ultrafast
: Sets the encoding preset to ultrafast for fast encoding.-tune zerolatency
: Optimizes the encoding for low-latency streaming.-crf 25
: Sets the Constant Rate Factor (CRF) for video quality (lower values result in higher quality)../${VIDEO_FILE_NAME} &
: Specifies the output file for the recorded video.
-
System.setProperty("webdriver.chrome.driver", "chromedriver-linux64/chromedriver");
- Sets the path for the ChromeDriver executable. Pipeline is currently downloading the linux chromedriver in workspace. It's recommended to use java project level chromedriver management.
-
System.setProperty("DISPLAY", ":99");
- Specifies the X server display number for the virtual display (Xvfb). Optional to specify here when it is specified as environmental variables in Jenkinsfile.
-
Creates a ChromeOptions instance for additional configurations.
-
options.setBinary("/usr/bin/google-chrome-stable");
- Sets the binary location for the Chrome browser. Change to the chrome install path based on the environment.
mvn clean test
Note: Adjust configurations based on your specific testing needs and the characteristics of your web application.
-
Ensure that the Jenkins agent running this pipeline has sufficient resources to handle the virtual display and video recording.
-
Depending on the complexity of your UI tests, you may need to adjust the screen resolution and color depth parameters in the Xvfb options.
-
Verify that the specified ChromeDriver version is compatible with the version of the Chrome browser used in your UI tests.