Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wrap WebDriver exception about failed to load page into DriverException
Browse files Browse the repository at this point in the history
Adjustments per review
aik099 committed Nov 3, 2024
1 parent eba0ed4 commit 4bacd30
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
@@ -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;
@@ -155,7 +157,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
14 changes: 14 additions & 0 deletions tests/Custom/TimeoutTest.php
Original file line number Diff line number Diff line change
@@ -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]);
}
@@ -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 4bacd30

Please sign in to comment.