October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk6 min

How to Run Selenium Screenshot Tests in GitLab CI

Capture Selenium screenshots in CI, preserve them as GitLab job artifacts, and optionally surface them in failed test details through JUnit attachments.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To keep Selenium screenshots from a GitLab CI run, save them inside the checked-out project, then upload that directory as a job artifact. Set artifacts:when: always if you need images from failed jobs. To open an image from a failed test’s details, also publish JUnit XML with a relative [[ATTACHMENT|...]] path. GitLab stores and displays the evidence; it does not automatically compare screenshots for visual changes.

How to run Selenium screenshot tests in GitLab CI

The essential workflow is: create a project-relative directory, save screenshots there from WebDriver, and configure the job to upload that directory. The example below shows the shape of a Python test and a GitLab CI job. It is illustrative wiring, not a complete, tested project: install and pin the browser and driver appropriate to your runner, and configure your test framework to produce the named JUnit file.

As an Amazon Associate I earn from qualifying purchases.

Save a screenshot from the test

from pathlib import Path
from selenium import webdriver

Path("screenshots").mkdir(parents=True, exist_ok=True)
driver = webdriver.Chrome()
try:
    driver.get("https://example.com")
    driver.save_screenshot("screenshots/example.png")
finally:
    driver.quit()

save_screenshot captures the current browser view to an image file. Selenium’s documentation shows the Python method and examples for other language bindings: Working with windows and tabs. If you want a screenshot only when a test fails, call the same method in your framework’s failure hook and choose a unique filename per test; the hook is framework-specific.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Upload the directory in GitLab CI

selenium_screenshots:
  stage: test
  script:
    - python -m pytest
  artifacts:
    when: always
    paths:
      - screenshots/
      - junit.xml
    reports:
      junit: junit.xml

The test command and framework must actually create junit.xml; change the path in both places if your runner writes it elsewhere. GitLab uploads listed files as job artifacts. The always setting is important when you want artifacts even after a failed script. The project-relative paths must match where the job writes the files, under the checked-out project directory.

#1 Best Overall
CanaKit Raspberry Pi 4 4GB Starter PRO Kit - 4GB RAM
  • Includes Raspberry Pi 4 4GB Model B with 1.5GHz 64-bit quad-core CPU (4GB RAM)
  • Includes Pre-Loaded 32GB EVO+ Micro SD Card (Class 10), USB MicroSD Card Reader
  • CanaKit Premium High-Gloss Raspberry Pi 4 Case with Integrated Fan Mount, CanaKit Low Noise Bearing System Fan
  • CanaKit 3.5A USB-C Raspberry Pi 4 Power Supply (US Plug) with Noise Filter, Set of Heat Sinks, Display Cable - 6 foot (Supports up to 4K60p)
  • CanaKit USB-C PiSwitch (On/Off Power Switch for Raspberry Pi 4)

Choose how to retrieve screenshots

Browse or download job artifacts

Use artifacts:paths to retain the screenshot directory, then open the job’s artifacts from its details page to browse or download the files. Artifact retention and access depend on the job configuration and GitLab settings; check access controls if images may contain credentials, customer information, or other sensitive page content. See GitLab job artifacts.

Link an image from a failed test’s details

If the runner produces JUnit XML, add an attachment marker to the relevant test’s <system-out> content, using a path relative to $CI_PROJECT_DIR:

Rank #2
Raspberry SC15184 Pi 4 Model B 2019 Quad Core 64 Bit WiFi Bluetooth (2GB)
  • Broadcom BCM2711, quad-core Cortex-A72 (ARM v8) 64-bit SoC @ 1. 5GHz
  • 2. 4 GHz and 5. 0 GHz IEEE 802. 11b/g/n/ac wireless LAN, Bluetooth 5. 0, BLE
  • 2 × USB 3. 0 ports, 2 x USB 2. 0 Ports
  • 2 × micro HDMI ports supproting up to 4Kp60 video resolution
  • Micro SD card slot for loading operating system and data storage
[[ATTACHMENT|screenshots/failure.png]]

Publish the JUnit file with artifacts:reports:junit and upload the image itself with artifacts:paths. GitLab can then make the image accessible from the test details. The marker does not create the image: your test hook must save it at that path. The GitLab documentation describes the attachment format and report setup in Unit test reports.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Make CI failures remain failures

JUnit reports are for displaying test results, not setting the job’s exit status. GitLab states in its Unit test reports documentation: “Unit test reports require the JUnit XML format and do not affect job status.” Ensure the test command exits non-zero when tests fail. In screenshot cleanup or exception handling, avoid swallowing the original test exception or returning success just because image capture failed.

Rank #3
Raspberry Pi 4 Model B (2GB)
  • Broadcom BCM2711, Quad core Cortex-A72 (ARM v8) 64-bit SoC @ 1.5GHz
  • 1GB, 2GB, 4GB or 8GB LPDDR4-3200 SDRAM (depending on model)
  • 2.4 GHz and 5.0 GHz IEEE 802.11ac wireless, Bluetooth 5.0, BLE Gigabit Ethernet
  • 2 USB 3.0 ports; 2 USB 2.0 ports.
  • Raspberry Pi standard 40 pin GPIO header (fully backwards compatible with previous boards)

Run the browser locally or through Selenium Grid

Browser in the test job

Starting the browser in the same job is a straightforward topology for a single runner. It keeps browser startup and the test process in one job environment, but you must provide a compatible browser, driver, and runtime configuration. Pin versions in the project’s actual image or installation setup if repeatable rendering matters.

Remote Selenium service or Grid

A remote WebDriver endpoint or Selenium Grid can support execution across multiple machines and browsers. Selenium presents Grid as a way to scale browser automation; GitLab’s gitlab-selenium-server example illustrates a remote service setup. This approach adds endpoint availability, network access, and service configuration to troubleshoot. In particular, a service container and job container do not share the same localhost: a service cannot reach an application in the job container by treating the job’s loopback address as its own. Confirm the correct network address for both the WebDriver endpoint and the application under test.

Rank #4
Vilros Raspberry Pi 4 Complete Starter Kit- Includes Raspberry Pi 4 Board, Fan Cooled Case, 64GB Preloaded Micro SD Card and More (4GB, Clear Transparent Case)
  • Vilros Complete Starter Kit for Pi 4 Includes Raspberry Pi 4 Model B Board and all the accessories you need to get started.
  • 9-PART KIT WILL HAVE YOU READY TO GET UP AND RUNNING: Kit Includes 1. Raspberry Pi 4 Model B Board 2. Case With Easy to connect Built-in fan 3. 64GB Micro SD card Preloaded with RP OS 4. Vilros Pi 4 Compatible Power Supply with Inline on/off switch (power supply color may vary white/black) 5. Micro HDMI to Standard HDMI cable (5ft) 6. Micro SD to USB adapter to reflash card if desired 7. Neoprene Storage Bag to store all parts when not in use 8. Set of 4 Heatsinks 9. Vilros QuickStart Guide instruction booklet for Pi 4
  • PASSIVE & ACTIVE COOLING: The included case is well-vented and the kit also includes a set of heatsinks with thermal stickers for easy application and a pre-installed fan to keep the board cool in any use.
  • CONVENIENT ACCESSORIES: The power supply features an inline on/off switch neoprene bag that holds and protects all the parts when not in use and the QuickStart guide is updated and written for Raspberry Pi 4.
  • IMPORTANT: Kit does NOT include Keyboard, Mouse or Monitor

Choose the topology based on browser and operating-system coverage, runner networking, concurrency, reproducibility, and where logs and images will be retained. The cited guidance does not establish one universally best setup. GitLab’s overview of CI testing and reports is at Test with GitLab CI/CD.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Keep screenshots useful for debugging and comparison

When a test fails, inspect the image alongside the exception, test output, and browser or page state. A screenshot can reveal what the browser actually displayed when an exception alone does not explain the failure; GitLab’s testing guide recommends screenshot inspection as part of diagnosing failed JavaScript specs: Testing best practices. Save useful logs with the images where appropriate, but exclude secrets.

Best Value
CanaKit Raspberry Pi 4 4GB Basic Kit with PiSwitch (4GB RAM)
  • Includes Raspberry Pi 4 4GB Model B with 1.5GHz 64-bit quad-core CPU (4GB RAM)
  • CanaKit 3.5A USB-C Power Supply with Noise Filter (UL Listed) specially designed for the Raspberry Pi 4 (5-foot cable)
  • CanaKit USB-C PiSwitch (On/Off Power Switch)
  • Set of 3 Aluminum Heat Sinks for the Raspberry Pi 4

For visual regression work, stable inputs matter. Keep the browser version and viewport dimensions consistent; Selenium documents browser sizing alongside its screenshot examples at Working with windows and tabs. Also consider stabilizing test data, fonts, animations, and time-dependent content in your own test design. GitLab and Selenium provide capture and artifact mechanics, not an automatic image-diff system or a universal baseline policy. Select and configure any comparison method separately.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Common problems and fixes

  • The artifact is present but the screenshot is missing: Confirm the test wrote the image beneath the checked-out project and that the spelling and relative location match artifacts:paths. A path outside the project or a mismatch in the job’s working directory will not be covered by the configured path.
  • Artifacts disappear after a failed test: Check the job’s artifact policy and set artifacts:when: always when failure evidence must be uploaded.
  • The test details show no screenshot link: Verify that JUnit XML was generated and published with artifacts:reports:junit, that the XML contains the attachment marker in the expected test output, and that the image path is relative to $CI_PROJECT_DIR and uploaded too.
  • The job passes despite a failed test: Check the test command’s exit code and exception handling. JUnit report display does not determine job status.
  • The remote browser cannot reach the app: Check the service and job network topology. Do not assume a service container’s localhost refers to the job container; use an address reachable from the browser service.
  • Images differ between runs: Check viewport and browser versions first, then investigate variable data, font availability, animations, and time-dependent page elements. Capture mechanics alone do not make a visual test deterministic.
  • Artifacts reveal sensitive page content: Review who can access job artifacts and what retention/access settings apply to your project before saving authenticated pages or production-like data.

Or skip the browser setup

If the goal is a clean page capture rather than a Selenium interaction test, ScreenshotNeo is a website screenshot API and MCP server. One GET request returns an image or PDF; its API can accept consent banners and remove 60+ known consent platforms, newsletter popups, and chat widgets before capture. Each response identifies page verdict and billing status: bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing. Its MCP server exposes screenshot tools for AI agents, and the free plan includes 1,000 shots a month with no card; paid plans start at $5 for 3,000.

For API options and response details, see the ScreenshotNeo documentation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp

This is a capture API, not a replacement for tests that need to drive a browser through interactions or assert application behavior. Sign up for ScreenshotNeo to get 1,000 screenshots a month free, with no card required.

Quick Recap

Bestseller No. 1
CanaKit Raspberry Pi 4 4GB Starter PRO Kit - 4GB RAM
CanaKit Raspberry Pi 4 4GB Starter PRO Kit - 4GB RAM
Includes Raspberry Pi 4 4GB Model B with 1.5GHz 64-bit quad-core CPU (4GB RAM); Includes Pre-Loaded 32GB EVO+ Micro SD Card (Class 10), USB MicroSD Card Reader
$159.99
Bestseller No. 2
Raspberry SC15184 Pi 4 Model B 2019 Quad Core 64 Bit WiFi Bluetooth (2GB)
Raspberry SC15184 Pi 4 Model B 2019 Quad Core 64 Bit WiFi Bluetooth (2GB)
Broadcom BCM2711, quad-core Cortex-A72 (ARM v8) 64-bit SoC @ 1. 5GHz; 2. 4 GHz and 5. 0 GHz IEEE 802. 11b/g/n/ac wireless LAN, Bluetooth 5. 0, BLE
$87.88
Bestseller No. 3
Raspberry Pi 4 Model B (2GB)
Raspberry Pi 4 Model B (2GB)
Broadcom BCM2711, Quad core Cortex-A72 (ARM v8) 64-bit SoC @ 1.5GHz; 1GB, 2GB, 4GB or 8GB LPDDR4-3200 SDRAM (depending on model)
$83.00
Bestseller No. 5
CanaKit Raspberry Pi 4 4GB Basic Kit with PiSwitch (4GB RAM)
CanaKit Raspberry Pi 4 4GB Basic Kit with PiSwitch (4GB RAM)
Includes Raspberry Pi 4 4GB Model B with 1.5GHz 64-bit quad-core CPU (4GB RAM); CanaKit USB-C PiSwitch (On/Off Power Switch)
$139.99

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.