Features

Selenium 4

Starting from Selenium 3.11.0 and higher, Selenium uses the new WebDriver W3C Protocol.

TestingBot has full support for this new protocol. Below is more information on how to make this transition.

Updating your tests

With the new W3C protocol, some restrictions apply to using capabilities with your test.
Before the W3C protocol (the so called JSONWP), you could simply add all our custom TestingBot capabilities to your test in the desiredCapabilities.


With the new W3C protocol, only browserName, browserVersion and platformName are allowed inside the capabilities.


All other capabilities are treated as Extension capabilities and should be namespaced, in our case, inside a tb:options namespace.

Please see the table below on how the capabilities need to be changed:


Capability JSONWP Capability W3C
browserName browserName
version browserVersion
platform platformName
selenium-version, chromedriverVersion,
extra, name and more
"tb:options" : {
  "selenium-version": '...',
  "chromedriverVersion": '...',
  "extra": '...',
  "name": '...'
}

Example

Before

#!/usr/bin/env ruby
require 'rubygems'
require 'selenium-webdriver'

caps = {
  :browserName => "chrome",
  :version => "latest-1",
  :platform => "WIN10",
  :screenrecorder => true,
  :build => "testbuild",
  :name => "testname"
}

client = Selenium::WebDriver::Remote::Http::Default.new
client.timeout = 480

driver = Selenium::WebDriver.for(
  :remote,
  :url => "https://API_KEY:API_SECRET@hub.testingbot.com/wd/hub",
  :http_client => client,
  :desired_capabilities => caps)
driver.navigate.to "http://www.google.com"
element = driver.find_element(:name, 'q')
element.send_keys "TestingBot"
element.submit
puts driver.title
driver.quit
        
<?php
require_once('vendor/autoload.php');
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\WebDriverBy;
  
  $capabilities = array(
    'browserName' => "chrome",
    'version' => "latest-1",
    'platform' => "WIN10",
    'screenrecorder' => true,
    'build' => "testbuild",
    'name' => "testname"
  );
  $web_driver = RemoteWebDriver::create(
    "https://api_key:api_secret@hub.testingbot.com/wd/hub",
    $capabilities, 240000
  );
  $web_driver->get("http://google.com");

  $element = $web_driver->findElement(WebDriverBy::name("q"));
  if($element) {
      $element->sendKeys("TestingBot");
      $element->submit();
  }
  print $web_driver->getTitle();
  $web_driver->quit();
?>
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 JavaSample {

  public static final String KEY = "KEY";
  public static final String SECRET = "SECRET";
  public static final String URL = "https://" + KEY + ":" + SECRET + "@hub.testingbot.com/wd/hub";

  public static void main(String[] args) throws Exception {

    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setCapability("browserName", "chrome");
    caps.setCapability("version", "latest-1");
    caps.setCapability("platform", "WIN10");
    caps.setCapability("screenrecorder", true);
    caps.setCapability("build", "testbuild");
    caps.setCapability("name", "testname");

    WebDriver driver = new RemoteWebDriver(new URL(URL), caps);
    driver.get("http://www.google.com/ncr");
    WebElement element = driver.findElement(By.name("q"));

    element.sendKeys("TestingBot");
    element.submit();

    System.out.println(driver.getTitle());
    driver.quit();

  }
}
import unittest
import sys

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from testingbotclient import TestingBotClient

class TestTestingBotClient(unittest.TestCase):

    def setUp(self):
      desired_cap = {
        'browserName': 'chrome',
        'version': 'latest-1',
        'platform': 'WIN10',
        'screenrecorder': true,
        'build': 'testbuild',
        'name' : 'testname',
      }

      self.driver = webdriver.Remote(
        command_executor='http://key:secret@hub.testingbot.com/wd/hub',
        desired_capabilities=desired_cap)

    def test_google_example(self):
      self.driver.get("http://www.google.com")
      if not "Google" in self.driver.title:
          raise Exception("Unable to load google page!")
      elem = self.driver.find_element_by_name("q")
      elem.send_keys("TestingBot")
      elem.submit()

    def tearDown(self):
      self.driver.quit()
      status = sys.exc_info() == (None, None, None)
      tb_client = TestingBotClient('key', 'secret')
      tb_client.tests.update_test(self.driver.session_id, self._testMethodName, status)

if __name__ == '__main__':
    unittest.main()
var wd = require('wd'),
testingbotKey = "api_key",
testingbotSecret = "api_secret"
 
desiredCaps = {
  'browserName': 'chrome',
  'version': 'latest-1',
  'platform': 'WIN10',
  'screenrecorder': true,
  'build': 'testbuild',
  'name' : 'testname',
}

driver = wd.remote("https://" + testingbotKey + ":" + testingbotSecret + "@" + "hub.testingbot.com/wd/hub")
driver.init(desiredCaps, function() {
  driver.get('https://www.google.com', function() {
    driver.title(function(err, title) {
        console.log(title)
        driver.quit()
    })
  })
})

After

#!/usr/bin/env ruby
require 'rubygems'
require 'selenium-webdriver'

caps = {
  :browserName => "chrome",
  :browserVersion => "latest-1",
  :platformName => "WIN10",
  "tb:options" => {
    :screenrecorder => true,
    :build => "testbuild",
    :name => "testname",
    "selenium-version" => "3.11.0"
  }
}

client = Selenium::WebDriver::Remote::Http::Default.new
client.timeout = 480

driver = Selenium::WebDriver.for(
  :remote,
  :url => "https://API_KEY:API_SECRET@hub.testingbot.com/wd/hub",
  :http_client => client,
  :desired_capabilities => caps)
driver.navigate.to "http://www.google.com"
element = driver.find_element(:name, 'q')
element.send_keys "TestingBot"
element.submit
puts driver.title
driver.quit
        
<?php
require_once('vendor/autoload.php');
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\WebDriverBy;
  
  $capabilities = array(
    'browserName' => "chrome",
    'browserVersion' => "latest-1",
    'platformName' => "WIN10",
    'tb:options' => {
      'screenrecorder' => true,
      'build' => "testbuild",
      'name' => "testname",
      'selenium-version' => "3.11.0"
    }
  );
  $web_driver = RemoteWebDriver::create(
    "https://api_key:api_secret@hub.testingbot.com/wd/hub",
    $capabilities, 240000
  );
  $web_driver->get("http://google.com");

  $element = $web_driver->findElement(WebDriverBy::name("q"));
  if($element) {
      $element->sendKeys("TestingBot");
      $element->submit();
  }
  print $web_driver->getTitle();
  $web_driver->quit();
?>
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 JavaSample {

  public static final String KEY = "KEY";
  public static final String SECRET = "SECRET";
  public static final String URL = "https://" + KEY + ":" + SECRET + "@hub.testingbot.com/wd/hub";

  public static void main(String[] args) throws Exception {
    MutableCapabilities tbOpts = new MutableCapabilities();
    tbOpts.setCapability("screenrecorder", true);
    tbOpts.setCapability("build", "testbuild");
    tbOpts.setCapability("name", "testname");
    tbOpts.setCapability("selenium-version", "3.11.0");

    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setCapability("browserName", "chrome");
    caps.setCapability("browserVersion", "latest-1");
    caps.setCapability("platformName", "WIN10");
    caps.setCapability("tb:options", tbOpts);

    WebDriver driver = new RemoteWebDriver(new URL(URL), caps);
    driver.get("http://www.google.com/ncr");
    WebElement element = driver.findElement(By.name("q"));

    element.sendKeys("TestingBot");
    element.submit();

    System.out.println(driver.getTitle());
    driver.quit();

  }
}
import unittest
import sys

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from testingbotclient import TestingBotClient

class TestTestingBotClient(unittest.TestCase):

    def setUp(self):
      desired_cap = {
        'browserName': 'chrome',
        'browserVersion': 'latest-1',
        'platformName': 'WIN10',
        'tb:options' : {
          'screenrecorder': true,
          'build': 'testbuild',
          'name' : 'testname',
          'selenium-version' : '3.11.0'
        }
      }

      self.driver = webdriver.Remote(
        command_executor='http://key:secret@hub.testingbot.com/wd/hub',
        desired_capabilities=desired_cap)

    def test_google_example(self):
      self.driver.get("http://www.google.com")
      if not "Google" in self.driver.title:
          raise Exception("Unable to load google page!")
      elem = self.driver.find_element_by_name("q")
      elem.send_keys("TestingBot")
      elem.submit()

    def tearDown(self):
      self.driver.quit()
      status = sys.exc_info() == (None, None, None)
      tb_client = TestingBotClient('key', 'secret')
      tb_client.tests.update_test(self.driver.session_id, self._testMethodName, status)

if __name__ == '__main__':
    unittest.main()
var wd = require('wd'),
testingbotKey = "api_key",
testingbotSecret = "api_secret"
 
desiredCaps = {
  'browserName': 'chrome',
  'browserVersion': 'latest-1',
  'platformName': 'WIN10',
  'tb:options' : {
    'screenrecorder': true,
    'build': 'testbuild',
    'name' : 'testname',
    'selenium-version' : '3.11.0'
  }
}

driver = wd.remote("https://" + testingbotKey + ":" + testingbotSecret + "@" + "hub.testingbot.com/wd/hub")
driver.init(desiredCaps, function() {
  driver.get('https://www.google.com', function() {
    driver.title(function(err, title) {
        console.log(title)
        driver.quit()
    })
  })
})