diff --git a/tests/aik099/PHPUnit/Integration/BrowserStackAwareTestCase.php b/tests/aik099/PHPUnit/Integration/BrowserStackAwareTestCase.php index 2cb17a8..7bec46a 100644 --- a/tests/aik099/PHPUnit/Integration/BrowserStackAwareTestCase.php +++ b/tests/aik099/PHPUnit/Integration/BrowserStackAwareTestCase.php @@ -12,6 +12,8 @@ use aik099\PHPUnit\BrowserTestCase; +use Behat\Mink\Exception\DriverException; +use Behat\Mink\Session; abstract class BrowserStackAwareTestCase extends BrowserTestCase { @@ -27,6 +29,32 @@ abstract class BrowserStackAwareTestCase extends BrowserTestCase ), ); + /** + * Visit specified URL and automatically start session if not already running. + * + * @param Session $session Session. + * @param string $url Url of the page. + * + * @return void + * @throws DriverException + */ + protected function openPageWithBackoff(Session $session, $url) + { + try { + $session->visit($url); + } + catch ( DriverException $e ) { + if ( strpos($e->getMessage(), '[BROWSERSTACK_QUEUE_SIZE_EXCEEDED]') !== false ) { + sleep(30); + $this->openPageWithBackoff($session, $url); + + return; + } + + throw $e; + } + } + /** * @before */ diff --git a/tests/aik099/PHPUnit/Integration/IsolatedSessionStrategyTest.php b/tests/aik099/PHPUnit/Integration/IsolatedSessionStrategyTest.php index 65a46bc..ffa4597 100644 --- a/tests/aik099/PHPUnit/Integration/IsolatedSessionStrategyTest.php +++ b/tests/aik099/PHPUnit/Integration/IsolatedSessionStrategyTest.php @@ -37,7 +37,7 @@ class IsolatedSessionStrategyTest extends BrowserStackAwareTestCase public function testOne() { $session = $this->getSession(); - $session->visit('https://www.google.com'); + $this->openPageWithBackoff($session, 'https://www.google.com'); $this->assertTrue(true); } diff --git a/tests/aik099/PHPUnit/Integration/SharedSessionStrategyTest.php b/tests/aik099/PHPUnit/Integration/SharedSessionStrategyTest.php index ad0ce2a..ee4cb62 100644 --- a/tests/aik099/PHPUnit/Integration/SharedSessionStrategyTest.php +++ b/tests/aik099/PHPUnit/Integration/SharedSessionStrategyTest.php @@ -37,7 +37,7 @@ class SharedSessionStrategyTest extends BrowserStackAwareTestCase public function testOpensPage() { $session = $this->getSession(); - $session->visit('https://www.google.com'); + $this->openPageWithBackoff($session, 'https://www.google.com'); $this->assertTrue(true); } @@ -57,7 +57,7 @@ public function testUsesOpenedPage() public function testOpensPopups() { $session = $this->getSession(); - $session->visit('https://the-internet.herokuapp.com/windows'); + $this->openPageWithBackoff($session, 'https://the-internet.herokuapp.com/windows'); $page = $session->getPage(); $page->clickLink('Click Here');