Skip to content

Commit

Permalink
Wrap WebDriver exception about failed to load page into DriverExcepti…
Browse files Browse the repository at this point in the history
…on (#39)

Adjustments per review
  • Loading branch information
aik099 authored Nov 3, 2024
1 parent 630842f commit d18d4ea
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/WebdriverClassicDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use Behat\Mink\Exception\DriverException;
use Facebook\WebDriver\Exception\NoSuchCookieException;
use Facebook\WebDriver\Exception\NoSuchElementException;
use Facebook\WebDriver\Exception\ScriptTimeoutException;
use Facebook\WebDriver\Exception\TimeoutException;
use Facebook\WebDriver\Exception\UnsupportedOperationException;
use Facebook\WebDriver\Exception\WebDriverException;
use Facebook\WebDriver\Remote\DesiredCapabilities;
Expand Down Expand Up @@ -151,7 +153,11 @@ public function reset(): void

public function visit(string $url): void
{
$this->getWebDriver()->navigate()->to($url);
try {
$this->getWebDriver()->navigate()->to($url);
} catch (TimeoutException|ScriptTimeoutException $e) {
throw new DriverException('Page failed to load: ' . $e->getMessage(), 0, $e);
}
}

public function getCurrentUrl(): string
Expand Down
14 changes: 14 additions & 0 deletions tests/Custom/TimeoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public function testInvalidTimeoutSettingThrowsException(): void
assert($driver instanceof WebdriverClassicDriver);

$this->expectException(DriverException::class);
$this->expectExceptionMessage('Invalid timeout type: invalid');

$driver->setTimeouts(['invalid' => 0]);
}
Expand Down Expand Up @@ -64,4 +65,17 @@ public function testLongTimeoutWaitsForElementToAppear(): void

$this->assertNotNull($element);
}

public function testShortPageLoadTimeoutThrowsException(): void
{
$session = $this->getSession();
$driver = $session->getDriver();
\assert($driver instanceof WebdriverClassicDriver);

$driver->setTimeouts(['page' => 500]);

$this->expectException(DriverException::class);
$this->expectExceptionMessage('Page failed to load: ');
$session->visit($this->pathTo('/page_load.php?sleep=2'));
}
}

0 comments on commit d18d4ea

Please sign in to comment.