Migrate Your Selenium Test Suite
Already have Selenium tests running locally? You can run them on the TestMu AI cloud grid with three changes: swap the driver URL, add your credentials, and set the desired capabilities. Your test logic stays the same.
If you are moving from BrowserStack or Sauce Labs, use these dedicated migration guides with capability mapping tables.
- Migrate from BrowserStack to TestMu AI - hub URL, capability mapping, and feature equivalents
- Migrate from Sauce Labs to TestMu AI - hub URL, capability mapping, and feature equivalents
Prerequisites
Make sure you have the following set up before you start.
- Create a TestMu AI account if you don't have one.
- Get your Username and Access Key from the TestMu AI Dashboard.
- An existing Selenium test suite in any supported language (Java, JavaScript, Python, C#, PHP, or Ruby).
Step 1: Set Your Credentials
Add your TestMu AI credentials as environment variables so your tests can authenticate with the grid.
- macOS / Linux
- Windows
export LT_USERNAME="undefined"
export LT_ACCESS_KEY="undefined"
set LT_USERNAME="undefined"
set LT_ACCESS_KEY="undefined"
Step 2: Replace Your Local Driver With RemoteWebDriver
Point your tests to the TestMu AI hub instead of launching a local browser.
Find where your test creates the WebDriver instance and replace it with a RemoteWebDriver pointing to the TestMu AI hub URL:
https://{YOUR_USERNAME}:{YOUR_ACCESS_KEY}@hub.lambdatest.com/wd/hub
Here is what the change looks like in each language:
- Java
- JavaScript
- Python
- C#
- PHP
- Ruby
Before (local):
WebDriver driver = new ChromeDriver();
After (cloud):
String username = System.getenv("LT_USERNAME");
String accessKey = System.getenv("LT_ACCESS_KEY");
String hubURL = "https://" + username + ":" + accessKey + "@hub.lambdatest.com/wd/hub";
ChromeOptions browserOptions = new ChromeOptions();
browserOptions.setPlatformName("Windows 10");
browserOptions.setBrowserVersion("latest");
HashMap<String, Object> ltOptions = new HashMap<String, Object>();
ltOptions.put("build", "My First Cloud Build");
ltOptions.put("name", "Sample Test");
ltOptions.put("w3c", true);
browserOptions.setCapability("LT:Options", ltOptions);
WebDriver driver = new RemoteWebDriver(new URL(hubURL), browserOptions);
Before (local):
const driver = new Builder().forBrowser('chrome').build();
After (cloud):
const username = process.env.LT_USERNAME;
const accessKey = process.env.LT_ACCESS_KEY;
const hubURL = `https://${username}:${accessKey}@hub.lambdatest.com/wd/hub`;
const capabilities = {
browserName: 'Chrome',
browserVersion: 'latest',
'LT:Options': {
platformName: 'Windows 10',
build: 'My First Cloud Build',
name: 'Sample Test',
w3c: true,
}
};
const driver = new Builder()
.usingServer(hubURL)
.withCapabilities(capabilities)
.build();
Before (local):
driver = webdriver.Chrome()
After (cloud):
import os
from selenium import webdriver
username = os.getenv("LT_USERNAME")
access_key = os.getenv("LT_ACCESS_KEY")
hub_url = f"https://{username}:{access_key}@hub.lambdatest.com/wd/hub"
options = webdriver.ChromeOptions()
options.platform_name = "Windows 10"
options.browser_version = "latest"
lt_options = {
"build": "My First Cloud Build",
"name": "Sample Test",
"w3c": True,
}
options.set_capability("LT:Options", lt_options)
driver = webdriver.Remote(command_executor=hub_url, options=options)
Before (local):
IWebDriver driver = new ChromeDriver();
After (cloud):
string username = Environment.GetEnvironmentVariable("LT_USERNAME");
string accessKey = Environment.GetEnvironmentVariable("LT_ACCESS_KEY");
string hubURL = $"https://{username}:{accessKey}@hub.lambdatest.com/wd/hub";
var options = new ChromeOptions();
options.PlatformName = "Windows 10";
options.BrowserVersion = "latest";
var ltOptions = new Dictionary<string, object>
{
{ "build", "My First Cloud Build" },
{ "name", "Sample Test" },
{ "w3c", true }
};
options.AddAdditionalOption("LT:Options", ltOptions);
IWebDriver driver = new RemoteWebDriver(new Uri(hubURL), options);
Before (local):
$driver = ChromeDriver::start();
After (cloud):
$username = getenv("LT_USERNAME");
$accessKey = getenv("LT_ACCESS_KEY");
$hubURL = "https://{$username}:{$accessKey}@hub.lambdatest.com/wd/hub";
$capabilities = [
"browserName" => "Chrome",
"browserVersion" => "latest",
"LT:Options" => [
"platformName" => "Windows 10",
"build" => "My First Cloud Build",
"name" => "Sample Test",
"w3c" => true,
]
];
$driver = RemoteWebDriver::create($hubURL, $capabilities);
Before (local):
driver = Selenium::WebDriver.for :chrome
After (cloud):
username = ENV["LT_USERNAME"]
access_key = ENV["LT_ACCESS_KEY"]
hub_url = "https://#{username}:#{access_key}@hub.lambdatest.com/wd/hub"
options = Selenium::WebDriver::Options.chrome(
platform_name: "Windows 10",
browser_version: "latest",
"LT:Options": {
build: "My First Cloud Build",
name: "Sample Test",
w3c: true,
}
)
driver = Selenium::WebDriver.for :remote, url: hub_url, capabilities: options
Use the Capabilities Generator to auto-generate the capabilities code for any browser, version, and OS combination.
Step 3: Run Your Tests
Execute your tests the same way you normally would. The only difference is they now run on the cloud.
# Java (Maven)
mvn test
# JavaScript (npm)
npm test
# Python (pytest)
pytest
# C# (dotnet)
dotnet test
# PHP (PHPUnit)
vendor/bin/phpunit
# Ruby (RSpec)
bundle exec rspec
Step 4: View Your Results
Check the Automation Dashboard to see exactly what happened during your test.
Visit the TestMu AI Automation Dashboard to see your results. Each session captures video playback, screenshots, console logs, network logs, and Selenium command logs.
What Stays the Same
Everything except the driver setup. Here is what does not change when you move to the cloud.
| What | Changes? |
|---|---|
| Test logic (assertions, flows, waits) | No |
| Page Object Models | No |
| Test framework config (TestNG XML, pytest.ini, etc.) | No |
| CI/CD pipeline commands | No |
| Driver setup (URL + capabilities) | Yes |
| Local browser install requirement | Removed |
