Features

Learn about event-driven testing with Selenium BiDi

WebDriver BiDi is a new protocol, standardized by the W3C. Even though it's still in draft mode, support for this new protocol has already been implemented in Chrome, Microsoft Edge and Firefox

The advantage of using this new protocol (based on WebSocket) over the older one (HTTP) is that it allows for bidirectional communication between the test script and the Selenium endpoint. This means your test scripts can now listen for certain events, generated by the (remote) browser under test.

Previously, a similar protocol was developed called CDP (Chrome DevTools Protocol), which only supported Chromium-based browsers (Chrome and Microsoft Edge). The new BiDi protocol is the new official standards-based alternative to CDP. It is supported on multiple browsers and is used for automation with Puppeteer.

Key Features of WebDriver BiDi Protocol

There are various advantages to using Selenium BiDi:

  • Event-Driven Automation:

    Allows your test scripts to listen to browser based events as they happen. This eliminates the need for polling and improves the overall test performance.

  • Standardization:

    The WebDriver BiDi protocol is a W3C standard, which means you'll get the same consistency and interoperability between browser flavors. You can run the same BiDi test script on multiple different browsers on the TestingBot browser grid.

  • Future Proof:

    The most popular browser vendors are committed to supporting the WebDriver BiDi Protocol. By adopting BiDi early on, you are future-proofing your test cases and ensuring compatibility with upcoming browser advancements.

  • Cross-Browser Compatibility

    Unlike CDP, which is restricted to a limited set of browsers, the WebDriver BiDi Protocol is designed to operate across various browsers, including Firefox.

Configuring Selenium BiDi

To get started with Selenium BiDi on TestingBot, you'll need to add several capabilities to your existing Selenium tests:

Selenium Version 4 is required

Selenium BiDi is only available on Selenium 4. We suggest using Selenium version 4.23.0 or higher.
Please specify the selenium-version capability in a tb:options capability.

Copy code
caps = {
  platformName: "Windows 10",
  browserName: "chrome",
  browserVersion: "latest",
  "tb:options" => {
    "selenium-version" : '4.23.0'
  }
}
Copy code
ChromeOptions chromeOpts = new ChromeOptions();
chromeOpts.setExperimentalOption("w3c", true);

MutableCapabilities tbOptions = new MutableCapabilities();
tbOptions.setCapability("key", "api_key");
tbOptions.setCapability("secret", "api_secret");
tbOptions.setCapability("selenium-version", "4.23.0");

DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability(ChromeOptions.CAPABILITY, chromeOpts);
caps.setCapability("platformName", "Windows 10");
caps.setCapability("tb:options", tbOptions);
caps.setCapability("browserName", "chrome");
Copy code
$options = new ChromeOptions();
$capabilities = DesiredCapabilities::chrome();
$capabilities->setPlatform('Windows 10');
$capabilities->setCapability('tb:options', array(
'selenium-version' => '4.23.0'
));
$capabilities->setCapability(ChromeOptions::CAPABILITY, $options);
Copy code
tbOptions = {
  'name': 'W3C Sample',
  'selenium-version': '4.23.0'
}

chromeOpts =  {
  'browserName': "chrome",
  'platformName': "Windows 10",
  'goog:chromeOptions': {'w3c': True},
  'tb:options': tbOptions
}

self.driver = webdriver.Remote(remote_url, desired_capabilities=chromeOpts)
Copy code
driver = await new webdriver.Builder().withCapabilities({
  "browserName": 'chrome',
  "platformName": 'Windows 10',
  "goog:chromeOptions" : { "w3c" : true },
  "tb:options": {
      "key": "api_key",
      "secret": "api_secret",
      "selenium-version": '4.23.0'
  }
}).usingServer("https://hub.testingbot.com/wd/hub").build();
Copy code
var chromeOptions = new ChromeOptions()
{
  BrowserVersion = "latest",
  PlatformName = "Windows 10",
  UseSpecCompliantProtocol = true
};
var tbOptions = new Dictionary<string, object>
{
  ["key"] = "api_key",
  ["secret"] = "api_secret",
  ["selenium-version"] = "4.23.0"
};

chromeOptions.AddAdditionalCapability("tb:options", tbOptions, true);

driver = new RemoteWebDriver(new Uri("https://hub.testingbot.com/wd/hub"),
  chromeOptions.ToCapabilities(), TimeSpan.FromSeconds(600));

webSocketUrl capability

Please specify the webSocketUrl capability to indicate to Selenium that you want to use the BiDi protocol.

Copy code
caps = {
  platformName: "Windows 10",
  browserName: "chrome",
  browserVersion: "latest",
  "selenium-version": "4.23.0",
  webSocketUrl: true
}
Copy code
ChromeOptions chromeOpts = new ChromeOptions();
chromeOpts.setExperimentalOption("w3c", true);

MutableCapabilities tbOptions = new MutableCapabilities();
tbOptions.setCapability("key", "api_key");
tbOptions.setCapability("secret", "api_secret");
tbOptions.setCapability("selenium-version", "4.23.0");

DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability(ChromeOptions.CAPABILITY, chromeOpts);
caps.setCapability("platformName", "Windows 10");
caps.setCapability("webSocketUrl", true);
caps.setCapability("tb:options", tbOptions);
caps.setCapability("browserName", "chrome");
Copy code
$options = new ChromeOptions();
$capabilities = DesiredCapabilities::chrome();
$capabilities->setPlatform('Windows 10');
$capabilities->setCapability('webSocketUrl', true);
$capabilities->setCapability('tb:options', array(
'selenium-version' => '4.23.0'
));
$capabilities->setCapability(ChromeOptions::CAPABILITY, $options);
Copy code
tbOptions = {
  'name': 'W3C Sample',
  'selenium-version': '4.23.0'
}

chromeOpts =  {
  'browserName': "chrome",
  'platformName': "Windows 10",
  'webSocketUrl': True,
  'goog:chromeOptions': {'w3c': True},
  'tb:options': tbOptions
}

self.driver = webdriver.Remote(remote_url, desired_capabilities=chromeOpts)
Copy code
driver = await new webdriver.Builder().withCapabilities({
  "browserName": 'chrome',
  "platformName": 'Windows 10',
  "goog:chromeOptions" : { "w3c" : true },
  "webSocketUrl": true,
  "tb:options": {
      "key": "api_key",
      "secret": "api_secret",
      "selenium-version": '4.23.0'
  }
}).usingServer("https://hub.testingbot.com/wd/hub").build();
Copy code
var chromeOptions = new ChromeOptions()
{
  BrowserVersion = "latest",
  PlatformName = "Windows 10",
  webSocketUrl = true,
  UseSpecCompliantProtocol = true
};
var tbOptions = new Dictionary<string, object>
{
  ["key"] = "api_key",
  ["secret"] = "api_secret",
  ["selenium-version"] = "4.23.0"
};

chromeOptions.AddAdditionalCapability("tb:options", tbOptions, true);

driver = new RemoteWebDriver(new Uri("https://hub.testingbot.com/wd/hub"),
  chromeOptions.ToCapabilities(), TimeSpan.FromSeconds(600));

Listen to console.log events

This example shows how to use Selenium BiDi to collect events generated by the browser in realtime, such as the console.log events. It will navigate to a website and click a button that generates console.log entries.

Copy code
require "rubygems"
require "selenium-webdriver" 

tb_options = {
  "name" => "My Bidi Test",
  "browserName" => "chrome",
  "platform" => "WIN10",
  "version" => "latest",
  "selenium-version" => "4.23.0"
}

options = Selenium::WebDriver::Chrome::Options.new
options.add_option('tb:options', tb_options)

driver = Selenium::WebDriver.for(
  :remote,
  :url => "https://key:secret@hub.testingbot.com/wd/hub",
  :capabilities => options)
driver.navigate.to "https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html"

driver.script.add_console_message_handler { |log| puts log }

wait = Selenium::WebDriver::Wait.new(timeout: 10)
consoleLog = wait.until {
  element = driver.find_element(id: 'consoleLog')
  element if element.displayed?
}
consoleLog.click
driver.quit
Copy code
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.bidi.module.LogInspector;
import org.openqa.selenium.remote.Augmenter;
import org.openqa.selenium.MutableCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;


public class ListenToConsoleLogs {
  public static final String KEY = "KEY";
  public static final String SECRET = "SECRET";
  public static final String REMOTE_URL = "https://" + KEY + ":" + SECRET + "@hub.testingbot.com/wd/hub";
  static Boolean success = false;

   public static void main(String[] args) throws MalformedURLException {
       MutableCapabilities capabilities = new MutableCapabilities();
       capabilities.setCapability("browserName", "chrome");
       capabilities.setCapability("webSocketUrl", true);
       HashMap<String, Object> testingbotOptions = new HashMap<>();
       testingbotOptions.put("selenium-version", "4.23.0");
       capabilities.setCapability("tb:options", testingbotOptions);

       WebDriver driver = new RemoteWebDriver(new URL(REMOTE_URL), capabilities);

       try {
           Augmenter augmenter = new Augmenter();
           driver = augmenter.augment(driver);

           try (LogInspector logInspector = new LogInspector(driver)) {
               logInspector.onConsoleEntry(consoleLogEntry -> {
                   System.out.println("text: " + consoleLogEntry.getText());
                   System.out.println("level: " + consoleLogEntry.getLevel());
                   success = true;
               });

               String page = "https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html";
               driver.get(page);
               driver.findElement(By.id("consoleLog")).click();
  
               if (success) {
                   markTestStatus(true, "Console logs streaming", driver);
               } else {
                   markTestStatus(false, "Console logs did not stream", driver);
               }
               driver.quit();
           }
       } catch (Exception e) {
          markTestStatus(false, "Exception!", driver);
          e.printStackTrace();
          driver.quit();
       }
   }

   public static void markTestStatus(Boolean status, String reason, WebDriver driver) {
    TestingbotREST r = new TestingbotREST("key", "secret");
    Map<String, String> data = new HashMap<String, String>();
    data.put("success", "1");
    data.put("name", "My Test");
    r.updateTest(driver.getSessionId(), data);
   }
}
Copy code
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait

def console_log():
    tb_options = {
      'name': 'TestingBot Sample Test',
      'webSocketUrl': True,
      'selenium-version': '4.23.0'
    }

    options = webdriver.ChromeOptions()
    options.browser_version = 'latest'
    options.platform_name = 'Windows 10'
    options.enable_bidi = True
    options.set_capability('tb:options', tb_options)

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

    driver.get('https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html')
    log_entries = []

    driver.script.add_console_message_handler(log_entries.append)

    driver.find_element(By.ID, "consoleLog").click()
    WebDriverWait(driver, 5).until(lambda _: log_entries)
    print(log_entries[0].text)
    driver.quit()
Copy code
const webdriver = require('selenium-webdriver');

const USERNAME = process.env.TB_KEY;
const ACCESS_KEY = process.env.TB_SECRET;

(async () => {
  const driver = await (new webdriver.Builder()
    .withCapabilities({
      browserName: 'chrome',
      platformName: 'WIN10',
      webSocketUrl: true,
      'tb:options': {
        'selenium-version': '4.23.0'
      },
    })
    .usingServer(
      `https://${USERNAME}:${ACCESS_KEY}@hub.testingbot.com/wd/hub`
    )
    .build());

  // Add a listener for log events.
  await driver.script().addConsoleMessageHandler((logEntry) => {
    console.log(logEntry.text);
  });

  await driver.get(
    'https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html'
  );

  // Trigger a console log on the demo page.
  await driver.findElement({ id: 'consoleLog' }).click();
  await driver.quit();
})();

Listen to JavaScript Exceptions

You can use this API to listen for JavaScript exceptions and register callbacks in your test, to process the exception details. These exception details can help in further inspecting the cause of a failing test.

The example test script below will navigate to a web page and click a button that will throw an exception. Selenium BiDi will forward this to your test script.

Copy code
require "rubygems"
require "selenium-webdriver" 

tb_options = {
  "name" => "My Bidi Test",
  "browserName" => "chrome",
  "platform" => "WIN10",
  "version" => "latest",
  "selenium-version" => "4.23.0"
}

options = Selenium::WebDriver::Chrome::Options.new
options.add_option('tb:options', tb_options)

driver = Selenium::WebDriver.for(
  :remote,
  :url => "https://key:secret@hub.testingbot.com/wd/hub",
  :capabilities => options)
driver.navigate.to "https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html"

driver.script.add_console_message_handler { |log| puts log }

wait = Selenium::WebDriver::Wait.new(timeout: 10)
consoleLog = wait.until {
  element = driver.find_element(id: 'consoleLog')
  element if element.displayed?
}
consoleLog.click
driver.quit
Copy code
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.bidi.module.LogInspector;
import org.openqa.selenium.remote.Augmenter;
import org.openqa.selenium.MutableCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;


public class ListenToConsoleLogs {
  public static final String KEY = "KEY";
  public static final String SECRET = "SECRET";
  public static final String REMOTE_URL = "https://" + KEY + ":" + SECRET + "@hub.testingbot.com/wd/hub";
  static Boolean success = false;

   public static void main(String[] args) throws MalformedURLException {
       MutableCapabilities capabilities = new MutableCapabilities();
       capabilities.setCapability("browserName", "chrome");
       capabilities.setCapability("webSocketUrl", true);
       HashMap<String, Object> testingbotOptions = new HashMap<>();
       testingbotOptions.put("selenium-version", "4.23.0");
       capabilities.setCapability("tb:options", testingbotOptions);

       WebDriver driver = new RemoteWebDriver(new URL(REMOTE_URL), capabilities);

       try {
           Augmenter augmenter = new Augmenter();
           driver = augmenter.augment(driver);

           try (LogInspector logInspector = new LogInspector(driver)) {
               logInspector.onJavaScriptException(logEntry -> {
                   System.out.println("text: " + logEntry.getText());
                   System.out.println("level: " + logEntry.getLevel());
                   success = true;
               });

               String page = "https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html";
               driver.get(page);
               driver.findElement(By.id("jsException")).click();
               Thread.sleep(1500);
               if (success) {
                   markTestStatus(true, "Caught a JS exception successfully", driver);
               } else {
                   markTestStatus(false, "Failed to catch the JS exception", driver);
               }
               driver.quit();
           }
       } catch (Exception e) {
          markTestStatus(false, "Exception!", driver);
          e.printStackTrace();
          driver.quit();
       }
   }

   public static void markTestStatus(Boolean status, String reason, WebDriver driver) {
    TestingbotREST r = new TestingbotREST("key", "secret");
    Map<String, String> data = new HashMap<String, String>();
    data.put("success", "1");
    data.put("name", "My Test");
    r.updateTest(driver.getSessionId(), data);
   }
}
Copy code
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait

def console_log():
    tb_options = {
      'name': 'TestingBot Sample Test',
      'webSocketUrl': True,
      'selenium-version': '4.23.0'
    }

    options = webdriver.ChromeOptions()
    options.browser_version = 'latest'
    options.platform_name = 'Windows 10'
    options.enable_bidi = True
    options.set_capability('tb:options', tb_options)

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

    driver.get('https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html')
    log_entries = []

    driver.script.add_javascript_error_handler(log_entries.append)

    driver.find_element(By.ID, "jsException").click()
    WebDriverWait(driver, 5).until(lambda _: log_entries)
    print(log_entries[0].text)
    driver.quit()
Copy code
const webdriver = require('selenium-webdriver');

const USERNAME = process.env.TB_KEY;
const ACCESS_KEY = process.env.TB_SECRET;

(async () => {
  const driver = await (new webdriver.Builder()
    .withCapabilities({
      browserName: 'chrome',
      platformName: 'WIN10',
      webSocketUrl: true,
      'tb:options': {
        'selenium-version': '4.23.0'
      },
    })
    .usingServer(
      `https://${USERNAME}:${ACCESS_KEY}@hub.testingbot.com/wd/hub`
    )
    .build());

  // Add a listener for error events.
  await driver.script().addJavaScriptErrorHandler((logEntry) => {
    console.error(logEntry.text);
  });

  await driver.get(
    'https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html'
  );

  // Trigger a console log on the demo page.
  await driver.findElement({ id: 'jsException' }).click();
  await driver.quit();
})();

Intercept Network Request

You can intercept and modify network requests with Selenium BiDi. Monitor network traffic, or mock outgoing requests. Modify request details such as headers, body, cookies, method and URL.

Copy code
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.bidi.module.LogInspector;
import org.openqa.selenium.remote.Augmenter;
import org.openqa.selenium.MutableCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

public class ListenToConsoleLogs {
  public static final String KEY = "KEY";
  public static final String SECRET = "SECRET";
  public static final String REMOTE_URL = "https://" + KEY + ":" + SECRET + "@hub.testingbot.com/wd/hub";
  static Boolean success = false;

   public static void main(String[] args) throws MalformedURLException {
       MutableCapabilities capabilities = new MutableCapabilities();
       capabilities.setCapability("browserName", "chrome");
       capabilities.setCapability("webSocketUrl", true);
       HashMap<String, Object> testingbotOptions = new HashMap<>();
       testingbotOptions.put("selenium-version", "4.23.0");
       capabilities.setCapability("tb:options", testingbotOptions);

       WebDriver driver = new RemoteWebDriver(new URL(REMOTE_URL), capabilities);

       try {
           Augmenter augmenter = new Augmenter();
           driver = augmenter.augment(driver);

           try (Network network = new Network(driver)) {
               network.addIntercept(new AddInterceptParameters(InterceptPhase.BEFORE_REQUEST_SENT));
               CountDownLatch latch = new CountDownLatch(1);
               network.onBeforeRequestSent(
                       beforeRequestSent -> {
                           network.continueRequest(
                                   new ContinueRequestParameters(beforeRequestSent.getRequest().getRequestId()));
                           latch.countDown();
                       });
               driver.get("https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html");
               boolean countdown = latch.await(5, TimeUnit.SECONDS);
               if (countdown) {
                   markTestStatus(true, "Network request intercepted successfully", driver);
               } else {
                   markTestStatus(false, "Network request failed to intercept", driver);
               }
               driver.quit();
           }
       } catch (Exception e) {
          markTestStatus(false, "Exception!", driver);
          e.printStackTrace();
          driver.quit();
       }
   }

   public static void markTestStatus(Boolean status, String reason, WebDriver driver) {
    TestingbotREST r = new TestingbotREST("key", "secret");
    Map<String, String> data = new HashMap<String, String>();
    data.put("success", "1");
    data.put("name", "My Test");
    r.updateTest(driver.getSessionId(), data);
   }
}

Intercept Network Response

You can intercept and modify incoming network responses with Selenium BiDi. Monitor incoming network traffic, or mock incoming requests. Modify request details such as headers, body, cookies, method, URL and status code.

Copy code
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.bidi.module.LogInspector;
import org.openqa.selenium.remote.Augmenter;
import org.openqa.selenium.MutableCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

public class ListenToConsoleLogs {
  public static final String KEY = "KEY";
  public static final String SECRET = "SECRET";
  public static final String REMOTE_URL = "https://" + KEY + ":" + SECRET + "@hub.testingbot.com/wd/hub";
  static Boolean success = false;

   public static void main(String[] args) throws MalformedURLException {
       MutableCapabilities capabilities = new MutableCapabilities();
       capabilities.setCapability("browserName", "chrome");
       capabilities.setCapability("webSocketUrl", true);
       HashMap<String, Object> testingbotOptions = new HashMap<>();
       testingbotOptions.put("selenium-version", "4.23.0");
       capabilities.setCapability("tb:options", testingbotOptions);

       WebDriver driver = new RemoteWebDriver(new URL(REMOTE_URL), capabilities);

       try {
           Augmenter augmenter = new Augmenter();
           driver = augmenter.augment(driver);

           try (Network network = new Network(driver)) {
               network.addIntercept(new AddInterceptParameters(InterceptPhase.RESPONSE_STARTED));
               CountDownLatch latch = new CountDownLatch(1);
               network.onResponseStarted(
                       responseDetails -> {
                           network.continueResponse(
                                   new ContinueResponseParameters(responseDetails.getRequest().getRequestId()));
                           latch.countDown();
                       });
               network.onResponseStarted(
                       responseDetails -> {
                           network.continueResponse(
                                   new ContinueResponseParameters(responseDetails.getRequest().getRequestId()));
                           latch.countDown();
                       });
               driver.get("https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html");
               boolean countdown = latch.await(5, TimeUnit.SECONDS);
               if (countdown) {
                   markTestStatus(true, "Network request intercepted successfully", driver);
               } else {
                   markTestStatus(false, "Network request failed to intercept", driver);
               }
               driver.quit();
           }
       } catch (Exception e) {
          markTestStatus(false, "Exception!", driver);
          e.printStackTrace();
          driver.quit();
       }
   }

   public static void markTestStatus(Boolean status, String reason, WebDriver driver) {
    TestingbotREST r = new TestingbotREST("key", "secret");
    Map<String, String> data = new HashMap<String, String>();
    data.put("success", "1");
    data.put("name", "My Test");
    r.updateTest(driver.getSessionId(), data);
   }
}

Basic Auth

By default, Selenium does not support providing an username and password when testing a website behind a Basic Auth protection.

The following test example will open a website and enter sample credentials in the basic auth popup window.

Copy code
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.bidi.module.LogInspector;
import org.openqa.selenium.remote.Augmenter;
import org.openqa.selenium.MutableCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

public class ListenToConsoleLogs {
  public static final String KEY = "KEY";
  public static final String SECRET = "SECRET";
  public static final String REMOTE_URL = "https://" + KEY + ":" + SECRET + "@hub.testingbot.com/wd/hub";
  static Boolean success = false;

   public static void main(String[] args) throws MalformedURLException {
       MutableCapabilities capabilities = new MutableCapabilities();
       capabilities.setCapability("browserName", "chrome");
       capabilities.setCapability("webSocketUrl", true);
       HashMap<String, Object> testingbotOptions = new HashMap<>();
       testingbotOptions.put("selenium-version", "4.23.0");
       capabilities.setCapability("tb:options", testingbotOptions);

       WebDriver driver = new RemoteWebDriver(new URL(REMOTE_URL), capabilities);

       try (Network network = new Network(driver)) {
               network.addIntercept(new AddInterceptParameters(InterceptPhase.AUTH_REQUIRED));
               network.onAuthRequired(
                       responseDetails ->
                               network.continueWithAuth(
                                       responseDetails.getRequest().getRequestId(),
                                       new UsernameAndPassword("foo", "bar")));
               driver.get("http://httpbin.org/basic-auth/foo/bar");
               String text = driver.findElement(By.tagName("body")).getText();
               System.out.println(text);
               if (text.contains("authenticated")) {
                   markTestStatus(true, "Authentication entered successfully", driver);
               } else {
                   markTestStatus(false, "Failed to enter authentication credentials", driver);
               }
               driver.quit();
           }
       } catch (Exception e) {
          markTestStatus(false, "Exception!", driver);
          e.printStackTrace();
          driver.quit();
       }
   }

   public static void markTestStatus(Boolean status, String reason, WebDriver driver) {
    TestingbotREST r = new TestingbotREST("key", "secret");
    Map<String, String> data = new HashMap<String, String>();
    data.put("success", "1");
    data.put("name", "My Test");
    r.updateTest(driver.getSessionId(), data);
   }
}