Skip to content

Commit

Permalink
Attempt to avoid "BROWSERSTACK_QUEUE_SIZE_EXCEEDED" BrowserStack error
Browse files Browse the repository at this point in the history
  • Loading branch information
aik099 committed Jul 15, 2024
1 parent 6ebf48d commit e6b575b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
28 changes: 28 additions & 0 deletions tests/aik099/PHPUnit/Integration/BrowserStackAwareTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@


use aik099\PHPUnit\BrowserTestCase;
use Behat\Mink\Exception\DriverException;
use Behat\Mink\Session;

abstract class BrowserStackAwareTestCase extends BrowserTestCase
{
Expand All @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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');
Expand Down

0 comments on commit e6b575b

Please sign in to comment.