Skip to content

Commit e6b575b

Browse files
committed
Attempt to avoid "BROWSERSTACK_QUEUE_SIZE_EXCEEDED" BrowserStack error
1 parent 6ebf48d commit e6b575b

3 files changed

Lines changed: 31 additions & 3 deletions

File tree

tests/aik099/PHPUnit/Integration/BrowserStackAwareTestCase.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313

1414
use aik099\PHPUnit\BrowserTestCase;
15+
use Behat\Mink\Exception\DriverException;
16+
use Behat\Mink\Session;
1517

1618
abstract class BrowserStackAwareTestCase extends BrowserTestCase
1719
{
@@ -27,6 +29,32 @@ abstract class BrowserStackAwareTestCase extends BrowserTestCase
2729
),
2830
);
2931

32+
/**
33+
* Visit specified URL and automatically start session if not already running.
34+
*
35+
* @param Session $session Session.
36+
* @param string $url Url of the page.
37+
*
38+
* @return void
39+
* @throws DriverException
40+
*/
41+
protected function openPageWithBackoff(Session $session, $url)
42+
{
43+
try {
44+
$session->visit($url);
45+
}
46+
catch ( DriverException $e ) {
47+
if ( strpos($e->getMessage(), '[BROWSERSTACK_QUEUE_SIZE_EXCEEDED]') !== false ) {
48+
sleep(30);
49+
$this->openPageWithBackoff($session, $url);
50+
51+
return;
52+
}
53+
54+
throw $e;
55+
}
56+
}
57+
3058
/**
3159
* @before
3260
*/

tests/aik099/PHPUnit/Integration/IsolatedSessionStrategyTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class IsolatedSessionStrategyTest extends BrowserStackAwareTestCase
3737
public function testOne()
3838
{
3939
$session = $this->getSession();
40-
$session->visit('https://www.google.com');
40+
$this->openPageWithBackoff($session, 'https://www.google.com');
4141

4242
$this->assertTrue(true);
4343
}

tests/aik099/PHPUnit/Integration/SharedSessionStrategyTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class SharedSessionStrategyTest extends BrowserStackAwareTestCase
3737
public function testOpensPage()
3838
{
3939
$session = $this->getSession();
40-
$session->visit('https://www.google.com');
40+
$this->openPageWithBackoff($session, 'https://www.google.com');
4141

4242
$this->assertTrue(true);
4343
}
@@ -57,7 +57,7 @@ public function testUsesOpenedPage()
5757
public function testOpensPopups()
5858
{
5959
$session = $this->getSession();
60-
$session->visit('https://the-internet.herokuapp.com/windows');
60+
$this->openPageWithBackoff($session, 'https://the-internet.herokuapp.com/windows');
6161

6262
$page = $session->getPage();
6363
$page->clickLink('Click Here');

0 commit comments

Comments
 (0)