Upgrade to Selenium 4

Selenium 4 uses the W3C WebDriver standard. This mainly affects capabilities and the actions class. The Selenium 4 documentation at www.selenium.dev has all the details.

Upgrading to Selenium 4 from an earlier version of Selenium requires changes to the dependencies in your test project's pom.xml file and to your test scripts. This article provides detailed instructions, including some Perfecto-specific changes.

We suggest that you start by watching the video, which explains how to use Selenium 4 for desktop web testing, and then read through the procedures for step-by-step instructions.

Tip: You can download the tests used in the video by clicking here. To use those tests, edit them to include your security token and cloud name.

Prerequisites

For desktop web testing, make sure you work with:

  • Selenium 4.0.0 or later

For testing on real mobile devices, make sure you work with:

  • Selenium 4.4.0 or later

  • Appium Java client 8.1.1 or later

Upgrade dependencies

The pom.xml file handles all of your project's dependencies. This is where you need to update the Selenium version.

To update the pom.xml file:

  1. Open your project's pom.xml file.

  2. For the following dependencies, change the Selenium version to 4.x.x. For example:

    Copy
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>4.0.0></version
    <dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-api</artifactId>
        <version>4.0.0></version
    <dependency>
  3. (Optional) Change the version of the Appium Java client to 8.x. For example:

    Copy
    <dependency>
        <groupId>io.appium</groupId>
        <artifactId>java-client</artifactId>
        <version>8.1.0></version
    <dependency>
  4. Save your file.

Update the test scripts

In Selenium 4, DesiredCapabilities and capabilities.setCapability have changed. You need to update your test scripts accordingly. The changes slightly differ for each browser, operating system version, or mobile device.

Important: These instructions do not include changes for Mozilla Firefox and Google Chrome on MacOS.

To view the steps, expand the relevant section.

Identify Selenium 4 in reports

You can identify a test's execution framework by using the Details option inside the single test report (STR).

To identify the execution framework in a report:

  1. In the Report Library, click the report in the table to open the STR.

  2. In the STR, click the Report Details button .

  3. In the Report Details dialog box, on the Device tab, click Show Desired Capabilities.

  4. Scroll down to verify the seleniumVersion field. It should display a value of 4.0.0.

Related articles