Features

Custom WebDriver Commands by TestingBot

TestingBot has added custom WebDriver commands for Chrome browsers, version 62 and higher.

We are working on making these commands available for other browsers as well.

With these custom commands, you can retrieve various metrics, throttle network speed and monitor/adjust network requests during your test.

These custom commands can be used with WebDriver's JavascriptExecutor.

Important: to be able to use these commands, you need to pass debugging: true in your desired capabilities.

Throttle Network

Description:

This call allows you to throttle network speed, or even simulate no network connection (offline-mode).

Copy code
driver.execute_script("tb:throttle", "3G")
# or
driver.execute_script("tb:throttle", {
    "downloadSpeed": 10 * 1024,
    "uploadSpeed": 10 * 1024,
    "latency": 0,
    "loss": 0
})
Copy code
((JavascriptExecutor) driver).executeScript("tb:throttle", "3G");
// or
Map<String, Object> throttleMap = new HashMap<>();
throttleMap.put("downloadSpeed", 10 * 1024);
throttleMap.put("uploadSpeed", 10 * 1024);
throttleMap.put("latency", 0);
throttleMap.put("loss", 0);
((JavascriptExecutor) driver).executeScript("tb:throttle", throttleMap);
Copy code
$driver->executeScript("tb:throttle", ["3G"]);
// or
$driver->executeScript("tb:throttle", [
	"downloadSpeed" => 10 * 1024,
	"uploadSpeed" => 10 * 1024,
	"latency" => 0,
	"loss" => 0
]);
Copy code
driver.execute_script("tb:throttle", "3G")
# or
driver.execute_script("tb:throttle", {
	"downloadSpeed" => 10 * 1024,
	"uploadSpeed" => 10 * 1024,
	"latency" => 0,
	"loss" => 0
})
Copy code
browser.execute('tb:throttle', '3G')
// or
browser.execute('tb:throttle', { 
    "downloadSpeed" => 10 * 1024,
	"uploadSpeed" => 10 * 1024,
	"latency" => 0,
	"loss" => 0
})
Copy code
((IJavaScriptExecutor)driver).ExecuteScript("tb:throttle", "3G");
# or
((IJavaScriptExecutor)driver).ExecuteScript("tb:throttle", "{\"downloadSpeed\":10*1024, \"uploadSpeed\": 10*1024, \"latency\": 0, \"loss\": 0}");

Options:

tb:throttle
Specifying a predefined condition
Condition Download Speed (kb/sec) Upload Speed (kb/sec) Latency (ms)
airplane
Simulate Offline Mode
0 0 0
disable
Default - useful if you want to undo the offline command.
no throttle no throttle no throttle
edge 250 150 300
3G 400 100 100
4G 18000 9000 100
tb:throttle
Specify custom settings
downloadSpeed uploadSpeed latency
... kb / sec ... kb / sec ... ms

Intercept/Mock

Description:

With these commands, you can intercept and even fake responses during your test.
Blacklist requests, add/modify headers, mock responses, ...

The url parameter supports wildcard statements, for example: https://www.testingbot.com/*.

Redirect a URL

Instructs Chrome to redirect to redirect upon navigating to url.

Copy code
driver.execute_script("tb:intercept", {
  "redirect": "https://www.google.com",
  "url": "https://testingbot.com",
})
Copy code
Map<String, Object> interceptMap = new HashMap<>();
interceptMap.put("redirect", "https://www.google.com");
interceptMap.put("url", "https://testingbot.com");
((JavascriptExecutor) driver).executeScript("tb:intercept", interceptMap);
Copy code
$driver->executeScript("tb:intercept", [
  "redirect" => "https://google.com",
  "url" => "https://testingbot.com",
 ]
]);
Copy code
driver.execute_script("tb:intercept", {
  "redirect": "https://google.com",
  "url": "https://testingbot.com"
})
Copy code
browser.execute('tb:intercept', { 
  "redirect": "https://google.com",
  "url": "https://testingbot.com"
})
Copy code
((IJavaScriptExecutor)driver).ExecuteScript("tb:intercept", "{\"redirect\":\"https://www.google.com\", \"url\": \"https://testingbot.com\"}}");

Trigger Failure

Allows you to return a specific error for a specific request.

Possible errors:

  • Failed
  • Aborted
  • TimedOut
  • AccessDenied
  • ConnectionClosed
  • ConnectionReset
  • ConnectionRefused
  • ConnectionAborted
  • ConnectionFailed
  • NameNotResolved
  • InternetDisconnected
  • AddressUnreachable
  • BlockedByClient
  • BlockedByResponse
Copy code
driver.execute_script("tb:intercept", {
  "redirect": "https://www.google.com",
  "url": "https://testingbot.com",
})
Copy code
Map<String, Object> interceptMap = new HashMap<>();
interceptMap.put("redirect", "https://www.google.com");
interceptMap.put("url", "https://testingbot.com");
((JavascriptExecutor) driver).executeScript("tb:intercept", interceptMap);
Copy code
$driver->executeScript("tb:intercept", [
  "redirect" => "https://www.google.com",
  "url" => "https://testingbot.com",
 ]
]);
Copy code
driver.execute_script("tb:intercept", {
  "redirect": "https://www.google.com",
  "url": "https://testingbot.com"
})
Copy code
browser.execute('tb:intercept', { 
  "redirect": "https://www.google.com",
  "url": "https://testingbot.com"
})
Copy code
((IJavaScriptExecutor)driver).ExecuteScript("tb:intercept", "{\"redirect\":\"https://www.google.com\", \"url\": \"https://testingbot.com\"}}");

Mock Response

Allows you to return a different response (body or headers).

Copy code
driver.execute_script("tb:intercept", {
  "response": {
    "statusCode": 200,
    "headers": {
       "x-a-header": "Sample"
    },
    "body": "Hello World"
  },
  "url": "https://testingbot.com"
})
Copy code
Map<String, Object> mockMap = new HashMap<>();
Map<String, Object> headersMap = new HashMap<>();
headersMap.put("x-a-header", "Sample");
Map<String, Object> responseMap = new HashMap<>();
responseMap.put("statusCode", 200);
responseMap.put("headers", headersMap);
responseMap.put("body", "Hello World");
mockMap.put("response", responseMap);
mockMap.put("url", "https://testingbot.com");
((JavascriptExecutor) driver).executeScript("tb:intercept", mockMap);
Copy code
$driver->executeScript("tb:intercept", [
  "response" => [
   "statusCode" => 200,
   "headers" => [
    "x-a-header" => "Sample"
   ],
   "body" => "Hello World"
  ],
  "url" => "https://testingbot.com"
]);
Copy code
driver.execute_script("tb:intercept", {
  "response": {
    "statusCode": 200,
    "headers": {
       "x-a-header": "Sample"
    },
    "body": "Hello World"
  },
  "url": "https://testingbot.com"
})
Copy code
browser.execute_script("tb:intercept", {
  "response": {
    "statusCode": 200,
    "headers": {
       "x-a-header": "Sample"
    },
    "body": "Hello World"
  },
  "url": "https://testingbot.com"
})
Copy code
((IJavaScriptExecutor)driver).ExecuteScript("tb:intercept", "{\"response\":{\"statusCode\": 200, \"headers\": { \"x-a-header\": \"Sample\"}, \"body\": \"Hello World\" }}, \"url\": \"https://testingbot.com\"}}");

Retrieve Network Log

Description:

With the tb:network command you can fetch a log of network calls from Chrome.

Copy code
driver.execute_script("tb:network")
Copy code
((JavascriptExecutor) driver).executeScript("tb:network");
Copy code
$driver->executeScript("tb:network");
Copy code
driver.execute_script("tb:network")
Copy code
browser.execute('tb:network')
Copy code
((IJavaScriptExecutor)driver).ExecuteScript("tb:network");