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 importer tool in the mabl CLI can import the following actions: setting viewport size, navigating to URLs, entering text into input fields and clicking on elements. Other actions, including assertions, variables, conditional logic, and loop logic are not supported.
If you choose to migrate Selenium tests, follow the steps for updating tests at the end of this article to set your mabl tests up for success.
- Install the mabl CLI
- Modify existing Selenium tests
- Log into the mabl CLI
- Import tests
- Update tests in mabl
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
If you've already installed the mabl CLI, run the following command to update to the latest version:
npm install -g @mablhq/mabl-cli@latest
Step 2: 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 RemoteWebDriver instance with
a custom HttpClientFactory that 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 3: Log into the mabl CLI
After you modify the Selenium tests, log into the mabl CLI:
mabl auth login
This command prompts the mabl CLI to open the mabl login page in a browser window. To complete authentication:
- Log into mabl using your usual method: username and password, Google auth, or SSO.
- Copy the authorization code from the browser window.
- Paste the authorization code in the mabl CLI.
- Press enter to finish logging in.
Step 4: Import tests
In the mabl CLI, start an import session with the command mabl tests import selenium
. For a full list of import options, run the command mabl tests import selenium -h
in the CLI or see the reference article on importing tests in the mabl CLI.
Run your Selenium test(s). The import should automatically stop when the test has completed. If this event is not properly detected, press CTRL + C to end the import at any time.
If you are importing multiple tests, the mabl CLI automatically determines when one test run ends and another one starts. All imported tests have the same name in mabl with a number appended at the end.
When the import session finishes, choose from one of the following options:
- View the test description
- Run the test locally
- Save the test
- Discard the test and exit
Step 5: Update tests in mabl
The following Selenium actions are not migrated during the import session:
- Assertions
- Variables
- File downloads
- File uploads
- Drag and drop actions
- Conditional logic
- Loop logic
- Steps that interact with elements in an iframe
- Hover actions
- Cookies
To set your migrated tests up for success, we strongly recommend taking the following next steps:
Add missing steps
Edit the test in the mabl Trainer. Add in missing steps that were not migrated.
Use flows for common step sequences
If you imported multiple Selenium tests, save common sequences of steps as flows and import into other migrated tests to minimize the refactoring effort.