Selenium Java Agent

Overview

The Selenium Agent is a JVM agent which is loaded at runtime and intercepts RemoteWebDriver method invocations to translate Selenium actions to mabl actions. No code changes are necessary when using this method. It is only necessary to load the mabl Selenium Agent by passing a JVM argument when you execute your Java Selenium Tests.

🚧

Supported Selenium versions

The Selenium Java Agent currently supports only Selenium 3.x. Other versions may work with the Selenium proxy method described in Java migration using Selenium proxy

Obtain an API key

When using the Java Selenium Agent, the first step is to obtain an API key for your workspace. Open the mabl application in your browser, and navigate to Settings => APIs. Click the Create API Key button, and then select Java Selenium Agent as the key type. Enter a name for the key, such as Selenium Migration, and then click the Create button.

757757

Create API key

Download the agent

Next, download the mabl Selenium Agent jar file from here. Place this jar file in a location such as C:\mabl\mabl-selenium-agent.jar on Windows or ~/mabl/mabl-selenium-agent.jar on Linux/Mac.

Execute Selenium tests with the agent enabled

To migrate your Java Selenium tests, run your tests as you normally would but with an extra JVM argument:

-javaagent:/path/to/mabl-selenium-agent.jar=apiKey=[your-api-key]

For example, if you execute your tests using an IDE like Eclipse, create/edit a Run Configuration and add the agent to the JVM arguments:

10931093

Run configuration image

🚧

When using Java 16 or newer

If your JVM is version 16 or newer you will need to add additional VM arguments in the same location where the -javaagent argument is specified:

--add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.util.stream=ALL-UNNAMED

Without these arguments you will see an error similar to the following:

Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field private java.util.Spliterator java.util.stream.AbstractPipeline.sourceSpliterator accessible: module java.base does not "opens java.util.stream" to unnamed module

Agent arguments

The agent accepts a number of parameters:

Name

Value

Required?

apiKey

mabl API key to use

Yes

httpProxy

Proxy to use to connect to mabl, specified as host:port

No

proxyUser

Username for proxy auth

No

proxyPassword

Password for proxy auth

No

name

The name to use when saving the test to mabl

No

Parameters are passed as comma-delimited key-value pairs. The following is an example showing how to pass multiple arguments to the agent:

-javaagent:/path/to/mabl-selenium-agent.jar=apiKey=your-api-key,httpProxy=proxy.example.com:8080,proxyUser=myuser,proxyPass=mypassword