If you’re coming to mabl from Selenium, you can import your existing set of Selenium tests to mabl via the mabl CLI. The mabl CLI can migrate tests to mabl from all Selenium frameworks and programming languages, including Java, Protractor, .NET, and Python, with support for different browser and runtime environments, such as local/remote, WebDriver, Selenium Grid, SauceLabs, and Browserstack.
The mabl CLI runs a local proxy between your Selenium test and the Selenium server, captures the WebDriver session, and hands off the capture to mabl’s cloud test authoring agent, which authors the corresponding mabl test asynchronously.
Before you start
The cloud test authoring agent authors a complete mabl test from your captured session, including assertions, variables, and waits. Because the CLI captures the session through a proxy, it only sees WebDriver traffic. A few things are invisible to it and may need to be added by hand after authoring (see Step 5 below). In particular, in-process assertions such as assertEquals calls that never reach the browser aren’t captured by the proxy; if your test’s intent depends on them, use the Selenium Java Agent instead.
Step 1: Install the mabl CLI
If the mabl CLI isn’t installed on your machine, run the following command:
npm install -g @mablhq/mabl-cli
Step 2: Add application, environment, and credentials to mabl
Before running the import, make sure you have added the application, environment, and target URL to your mabl workspace. If your test uses credentials, add those credentials to mabl.
When you run the import, the mabl agent uses the URLs and credentials from the recording to pick the matching entities in your mabl workspace.
Step 3: Modify existing Selenium tests
Make a small configuration change to the tests so that the proxy running inside the mabl CLI can listen in to the Selenium traffic. The change that you need to make depends on the programming language and Selenium framework used.
For examples of modified Selenium tests ready for migration to mabl, check out this Github repository.
Java
To migrate Java-based Selenium tests to mabl, use one of the following options:
- Selenium Java Agent: this method doesn’t require changes to your Java code. To continue the Selenium migration process using the Selenium Java Agent, skip over to this article for complete instructions.
-
Java migration using Selenium proxy: a language-agnostic option for migrating tests. See an import example here. Create a
RemoteWebDriverinstance with a customHttpClientFactorythat is configured to use a proxy.
Protractor
See a Protractor Selenium import example here.
To migrate Protractor-based Selenium tests to mabl, add the following setting to your Protractor configuration file:
webDriverProxy: 'http://localhost:8889',
Ruby
See a Ruby Selenium import example here.
Configure a proxy inside the remote web driver client: replace “http://localhost:9515” with the URL of your remote web driver or Selenium Grid.
client = Selenium::WebDriver::Remote::Http::Default.new
client.proxy = Selenium::WebDriver::Proxy.new(http: "http://localhost:8889")
driver = Selenium::WebDriver.for :remote, http_client: client, url: "http://localhost:9515"
C
See a C# Selenium import example here.
Configure a proxy inside the remote web driver client: replace “http://localhost:9515” with the URL of your remote web driver or Selenium Grid.
ChromeOptions options = new ChromeOptions();
var p = new WebProxy("http://localhost:8889/");
HttpCommandExecutor commandExecutor = new HttpCommandExecutor(new Uri("http://localhost:9515"), TimeSpan.FromSeconds(600));
commandExecutor.Proxy = p;
RemoteWebDriver driver = new(commandExecutor, options.ToCapabilities());
Step 4: Log into the mabl CLI
After you modify the Selenium tests, log into the mabl CLI:
mabl auth login --auto
This command prompts the mabl CLI to open the mabl login page in a browser window. Log into mabl using your usual method: username and password, Google auth, or SSO. The mabl CLI automatically copies the authorization code from the browser window and pastes it into the terminal window to finish logging in.
Step 5: Import tests
In the mabl CLI, start an import session with the command mabl tests import selenium. For example:
# Importing a test with mabl credentials
mabl tests import selenium --credentialsId [mabl-credentials-id]
For a full list of import options, run mabl tests import selenium -h in the CLI or see the reference article on importing tests in the mabl CLI.
The CLI starts the proxy and waits for your test:
Configure your test to use a selenium proxy at localhost:8889 and run the test now.
Import will end automatically when the Selenium session is closed or CTRL+C is pressed
Run your Selenium test(s). The CLI captures the session and stops automatically when the test completes. If this event isn’t properly detected, press CTRL+C to end the import at any time.
When capture ends, the CLI prompts you to confirm the handoff:
? Submit 1 captured session to mabl for test authoring? (Y/n)
Enter Y to submit the captured session to mabl’s cloud test authoring agent. The CLI then prints a link to the running authoring session:
Submitting session to mabl for test generation (planning enabled)...
Test authoring session initiated: session={session-id} instance={instance-id}
https://app.mabl.com/workspaces/{workspace-id}/agents/tasks/{session-id}
Open the link to watch the test get authored in real time. Import is asynchronous: the CLI returns as soon as the authoring session has been initiated and doesn’t block waiting for the test to finish. The finished test appears in your workspace when authoring completes.
To skip the prompt and submit automatically — useful in scripts and CI — pass --auto-save.
Importing multiple tests
Use --multi to import several tests in one session; the proxy keeps listening across Selenium sessions until you press CTRL+C. If you don’t pass --name, mabl generates a descriptive name for each test from its captured session.
Step 6: Review the imported test
The cloud test authoring agent authors a complete mabl test from your captured Selenium session, including assertions, variables, and waits. We still recommend reviewing the test after authoring completes.
Verify the application and environment
Make sure the test chose the correct application, environment, and, if using, credentials, in mabl. If the captured run started on a third-party identity provider page, or visited multiple hosts, double-check that the test is bound to the right application/environment in mabl.
Add anything that wasn’t visible in the recording
A few actions are inherently invisible to the proxy and may need to be added manually after authoring:
- Assertions made inside your test process (the proxy only sees WebDriver traffic, not in-process
assertEqualscalls. Use the Selenium Java Agent if your test’s intent depends on in-process assertions) - File downloads and uploads
- Drag and drop actions
- Hover actions
- Steps that interact with elements inside an iframe
- Cookie inspection
Edit the test in the mabl Trainer to add any of these that your test needs.
Use flows for common step sequences
If you’re importing multiple Selenium tests with common sequences of steps, you can add flows to minimize overall refactoring:
- Import an initial subset of tests with common sequences of steps
- Manually edit and convert those common steps into reusable flows
- Import the rest of the tests. Subsequent imports will be able to use the flows you just created.