Migrate your test suites

A migration guide to help you run your existing test suites on BrowserStack Automate.

Overview

Migrating your existing Selenium tests to run on BrowserStack Automate is simple. In this guide, we will see how you’ll authenticate your test session, use the desired capabilities in your tests and run tests on the browsers in our cloud.

Authentication

Every test that runs on BrowserStack needs a username and access key so that we can authenticate your test runs, associate the builds to your accounts and help you run tests in parallel as per the parallels you purchased.

You can find your username and access key in the Automate dashboard. You’ll need to use these credentials while connecting to our platform to run the tests. For example:

public static final String USERNAME = "YOUR_USERNAME";
public static final String AUTOMATE_KEY = "YOUR_ACCESS_KEY";
public static final String URL = "https://" + USERNAME + ":" + AUTOMATE_KEY + "@hub-cloud.browserstack.com/wd/hub";
var userName = "YOUR_USERNAME";
var accessKey = "YOUR_ACCESS_KEY"
var browserstackURL = 'https://' + userName + ':' + accessKey + '@hub-cloud.browserstack.com/wd/hub';
string USERNAME = "YOUR_USERNAME";
string AUTOMATE_KEY = "YOUR_ACCESS_KEY";
$USERNAME = "YOUR_USERNAME";
$AUTOMATE_KEY = "YOUR_ACCESS_KEY";
$BROWSERSTACK_URL = "https://$USERNAME:$AUTOMATE_KEY@hub-cloud.browserstack.com/wd/hub";
BROWSERSTACK_URL = 'https://YOUR_USERNAME:YOUR_ACCESS_KEY@hub-cloud.browserstack.com/wd/hub'
USERNAME = "YOUR_USERNAME"
AUTOMATE_KEY = "YOUR_ACCESS_KEY"
browserstack_url = "https://" + USERNAME + ":" + AUTOMATE_KEY + "@hub-cloud.browserstack.com/wd/hub"
my $USERNAME = "YOUR_USERNAME";
my $AUTOMATE_KEY = "YOUR_ACCESS_KEY";
my $BROWSERSTACK_URL = "$USERNAME:$AUTOMATE_KEY\@hub-cloud.browserstack.com";

Capabilities

Capabilities (or desired capabilities) are configuration options that let you specify your desired browser, OS or a device to run the tests on, and set up the browser for testing in a desired manner before running the test.

Let’s say you want to run your tests on Chrome (version 80) on Windows 10. This is how you’d mention the same in capabilities:

DesiredCapabilities caps = new DesiredCapabilities();

caps.setCapability("os", "Windows");
caps.setCapability("os_version", "10");
caps.setCapability("browser", "Chrome");
caps.setCapability("browser_version", "80");
caps.SetCapability("name", "My First Test");
caps.SetCapability("build", "Build #1");
caps.SetCapability("project", "Sample sandbox project");
var capabilities = {
  'os': 'Windows',
  'os_version': '10',
  'browserName': 'Chrome',
  'browser_version': '80',
  'name': 'My First Test',
  'build': 'Build #1',
  'project': 'Sample sandbox project'
}
DesiredCapabilities caps = new DesiredCapabilities();

caps.SetCapability("os", "Windows");
caps.SetCapability("os_version", "10");
caps.SetCapability("browser", "Chrome");
caps.SetCapability("browser_version", "80");
caps.SetCapability("browserstack.user", USERNAME);
caps.SetCapability("browserstack.key", AUTOMATE_KEY);
caps.SetCapability("name", "My First Test");
caps.SetCapability("build", "Build #1");
caps.SetCapability("project", "Sample sandbox project");
$caps = array(

  'os' => 'Windows',
  'os_version' => '10',
  'browser' => 'Chrome',
  'browser_version' => '80',
  'name' => 'My First Test',
  'build' => 'Build #1',
  'project' => 'Sample sandbox project'
);
desired_cap = {
    'os': 'Windows',
    'os_version': '10',
    'browser': 'Chrome',
    'browser_version': '80',
    'name': 'My First Test',
    'build': 'Build #1',
    'project': 'Sample sandbox project',
}
caps = Selenium::WebDriver::Remote::Capabilities.new

caps['os'] = 'Windows'
caps['os_version'] = '10'
caps['browser'] = 'Chrome'
caps['browser_version'] = '80'
caps['name'] = 'My First Test'
caps['build'] = 'Build #1'
caps['project'] = 'Sample sandbox project'
my $caps = {

  'os' => 'Windows',
  'os_version' => '10',
  'browser' => 'Chrome',
  'browser_version' => '80',
  'name' => 'My First Test',
  'build' => 'Build #1',
  'project' => 'Sample sandbox project'
};

Running the tests on Remote WebDriver

Now that you are aware of how to authenticate and mention the capabilities, let’s see how to put it all together and start running your tests on Automate.

If you were running tests on your local machine until now, you will probably need to change your test script to start using a remote WebDriver along with your desired capabilities.

Just send the capabilities to https://hub-cloud.browserstack.com/wd/hub with your authentication details, and we are all set!. Here is how it is done:

import org.openqa.selenium.By;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import java.net.URL;

public class BrowserStackSampleTest {
public static final String USERNAME = "YOUR_USERNAME";
public static final String AUTOMATE_KEY = "YOUR_ACCESS_KEY";
public static final String URL = "https://" + USERNAME + ":" + AUTOMATE_KEY + "@hub-cloud.browserstack.com/wd/hub";
public static void main(String[] args) throws Exception {
        DesiredCapabilities caps = new DesiredCapabilities();

        caps.setCapability("os", "Windows");
        caps.setCapability("os_version", "10");
        caps.setCapability("browser", "Chrome");
        caps.setCapability("browser_version", "80");
        caps.SetCapability("name", "My First Test");
        caps.SetCapability("build", "Build #1");
        caps.SetCapability("project", "Sample sandbox project");

        WebDriver driver = new RemoteWebDriver(new URL(URL), caps);
        driver.get("http://www.google.com");

        // Your test script like you usually write

        driver.quit();
}
}
var webdriver = require('selenium-webdriver');

var userName = "YOUR_USERNAME";
var accessKey = "YOUR_ACCESS_KEY"
var browserstackURL = 'https://' + userName + ':' + accessKey + '@hub-cloud.browserstack.com/wd/hub';

var capabilities = {
  'os': 'Windows',
  'os_version': '10',
  'browserName': 'Chrome',
  'browser_version': '80',
  'name': 'My First Test',
  'build': 'Build #1',
  'project': 'Sample sandbox project'
}

var driver = new webdriver.Builder().
usingServer(browserstackURL).
withCapabilities(capabilities).
build();

driver.get('http://www.google.com').then(function() {
  // Your test script like you usually write

  driver.quit();
});
using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;

namespace SeleniumTest {
  class Program {
    static void Main(string[] args) {
      string USERNAME = "YOUR_USERNAME";
      string AUTOMATE_KEY = "YOUR_ACCESS_KEY";

      DesiredCapabilities caps = new DesiredCapabilities();

      caps.SetCapability("os", "Windows");
      caps.SetCapability("os_version", "10");
      caps.SetCapability("browser", "Chrome");
      caps.SetCapability("browser_version", "80");
      caps.SetCapability("browserstack.user", USERNAME);
      caps.SetCapability("browserstack.key", AUTOMATE_KEY);
      caps.SetCapability("name", "My First Test");
      caps.SetCapability("build", "Build #1");
      caps.SetCapability("project", "Sample sandbox project");

      IWebDriver driver;
      driver = new RemoteWebDriver(
        new Uri("https://hub-cloud.browserstack.com/wd/hub/"), caps
      );
      driver.Navigate().GoToUrl("http://www.google.com");

      // Your test script like you usually write

      driver.Quit();
    }
  }
}
<?php

  require_once('vendor/autoload.php');
  use Facebook\WebDriver\Remote\RemoteWebDriver;
  use Facebook\WebDriver\WebDriverBy;

  $USERNAME = "YOUR_USERNAME";
  $AUTOMATE_KEY = "YOUR_ACCESS_KEY";
  $BROWSERSTACK_URL = "https://$USERNAME:$AUTOMATE_KEY@hub-cloud.browserstack.com/wd/hub";

  $caps = array(

    'os' => 'Windows',
    'os_version' => '10',
    'browser' => 'Chrome',
    'browser_version' => '80',
    'name' => 'My First Test',
    'build' => 'Build #1',
    'project' => 'Sample sandbox project'
  );

  $web_driver = RemoteWebDriver::create(
      $BROWSERSTACK_URL,
      $caps
  );

  $web_driver->get("https://google.com");

  // Your test script like you usually write

  $web_driver->quit();
from selenium import webdriver

BROWSERSTACK_URL = 'https://YOUR_USERNAME:YOUR_ACCESS_KEY@hub-cloud.browserstack.com/wd/hub'

desired_cap = {
    'os': 'Windows',
    'os_version': '10',
    'browser': 'Chrome',
    'browser_version': '80',
    'name': 'My First Test',
    'build': 'Build #1',
    'project': 'Sample sandbox project',
}

driver = webdriver.Remote(
    command_executor=BROWSERSTACK_URL,
    desired_capabilities=desired_cap
)

driver.get("https://www.google.com")

# Your test script like you usually write

driver.quit()
require 'rubygems'
require 'selenium-webdriver'

caps = Selenium::WebDriver::Remote::Capabilities.new

USERNAME = 'YOUR_USERNAME'.freeze
AUTOMATE_KEY = 'YOUR_ACCESS_KEY'.freeze
browserstack_url = 'https://' + USERNAME + ':' + AUTOMATE_KEY + '@hub-cloud.browserstack.com/wd/hub'

caps['os'] = 'Windows'
caps['os_version'] = '10'
caps['browser'] = 'Chrome'
caps['browser_version'] = '80'
caps['name'] = 'My First Test'
caps['build'] = 'Build #1'
caps['project'] = 'Sample sandbox project'

driver = Selenium::WebDriver.for(:remote,
                                 url: browserstack_url,
                                 desired_capabilities: caps)
driver.navigate.to 'https://www.google.com'

# Your test script like you usually write

driver.quit
use Selenium::Remote::Driver;
my $USERNAME = "YOUR_USERNAME";
my $AUTOMATE_KEY = "YOUR_ACCESS_KEY";
my $BROWSERSTACK_URL = "$USERNAME:$AUTOMATE_KEY\@hub-cloud.browserstack.com";

my $caps = {

  'os' => 'Windows',
  'os_version' => '10',
  'browser' => 'Chrome',
  'browser_version' => '80',
  'name' => 'My First Test',
  'build' => 'Build #1',
  'project' => 'Sample sandbox project'
};

my $driver = new Selenium::Remote::Driver('remote_server_addr' => $BROWSERSTACK_URL,
  'port' => '80', 'extra_capabilities' => $caps);

$driver->get('http://www.google.com');

# Your test script like you usually write

$driver->quit();
Note: Make sure you quit the driver (which basically closes the browser) once you are done with your test. We time out any test that is idle (i.e., no Selenium command received) for 90 seconds.

Next Steps

  1. If your tests test applications that are accessible on localhost or any internal / staging environment, learn more about setting up a Local Testing connection.
  2. Learn more about the different debugging options that are available on Automate.
  3. Explore the various features that we provide that can help you automate more test scenarios.

We're sorry to hear that. Please share your feedback so we can do better






Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback