Skip to content

Commit

Permalink
Driver: Limit attempts and seconds for starting a test at BrowserStack
Browse files Browse the repository at this point in the history
  • Loading branch information
chibimagic committed Apr 15, 2015
1 parent 9ee73d0 commit 58c3744
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions WebDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ class WebDriver {
public static $ImplicitWaitMS = 0; // How long to wait for elements to appear on the page
public static $CurlConnectTimeoutSec = 30; // How long to wait to connect to the server
public static $CurlTimeoutSec = 120; // How long to wait for the server's response to any single command
public static $BrowserStackMaxAttempts = 100; // Maximum number of times to try to start a session at BrowserStack
public static $BrowserStackMaxSeconds = 120; // Maximum number of seconds to try to start a session at BrowserStack

// See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element/:id/value
// Example: $my_web_element->send_keys(WebDriver::ReturnKey());
Expand Down
6 changes: 4 additions & 2 deletions WebDriver/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static function InitAtSauce($sauce_username, $sauce_key, $os, $browser, $
return new WebDriver_Driver("http://" . $sauce_username . ":" . $sauce_key . "@ondemand.saucelabs.com:80/wd/hub", $capabilities);
}

public static function InitAtBrowserStack($browserstack_username, $browserstack_value, $os, $browser, $version = false, $additional_options = array()) {
public static function InitAtBrowserStack($browserstack_username, $browserstack_value, $os, $browser, $version = false, $additional_options = array(), $starting_time = time(), $attempt = 1) {
try {
$capabilities = array_merge(array(
'browserstack.debug' => true,
Expand All @@ -87,8 +87,10 @@ public static function InitAtBrowserStack($browserstack_username, $browserstack_
}
return new WebDriver_Driver("http://" . $browserstack_username . ":" . $browserstack_value . "@hub.browserstack.com/wd/hub", $capabilities);
} catch (WebDriver_OverParallelLimitException $e) {
PHPUnit_Framework_Assert::assertTrue(time() < $starting_time + WebDriver::$BrowserStackMaxSeconds);
PHPUnit_Framework_Assert::assertTrue($attempt < WebDriver::$BrowserStackMaxAttempts);
sleep(1);
return WebDriver_Driver::InitAtBrowserStack($browserstack_username, $browserstack_value, $os, $browser, $version, $additional_options);
return WebDriver_Driver::InitAtBrowserStack($browserstack_username, $browserstack_value, $os, $browser, $version, $additional_options, $starting_time, $attempt + 1);
}
}

Expand Down

0 comments on commit 58c3744

Please sign in to comment.