|
3 | 3 | namespace Mink\WebdriverClassicDriver\Tests\Custom; |
4 | 4 |
|
5 | 5 | use Behat\Mink\Exception\DriverException; |
6 | | -use Behat\Mink\Tests\Driver\TestCase; |
7 | | -use Mink\WebdriverClassicDriver\WebdriverClassicDriver; |
8 | 6 |
|
9 | 7 | class TimeoutTest extends TestCase |
10 | 8 | { |
11 | | - /** |
12 | | - * @after |
13 | | - */ |
14 | | - protected function resetSessions(): void |
| 9 | + protected function tearDown(): void |
15 | 10 | { |
16 | | - $session = $this->getSession(); |
17 | | - $driver = $this->getSession()->getDriver(); |
18 | | - assert($driver instanceof WebdriverClassicDriver); |
| 11 | + $this->driver->setTimeouts([ |
| 12 | + 'script' => 30000, |
| 13 | + 'page' => 300000, |
| 14 | + 'implicit' => 0, |
| 15 | + ]); |
19 | 16 |
|
20 | | - // Stop the session instead of only resetting it, as timeouts are not reset (they are configuring the session itself) |
21 | | - if ($session->isStarted()) { |
22 | | - $session->stop(); |
23 | | - } |
24 | | - |
25 | | - // Reset the array of timeouts to avoid impacting other tests |
26 | | - $driver->setTimeouts([]); |
27 | | - |
28 | | - parent::resetSessions(); |
| 17 | + parent::tearDown(); |
29 | 18 | } |
30 | 19 |
|
31 | 20 | public function testInvalidTimeoutSettingThrowsException(): void |
32 | 21 | { |
33 | | - $this->getSession()->start(); |
34 | | - $driver = $this->getSession()->getDriver(); |
35 | | - assert($driver instanceof WebdriverClassicDriver); |
| 22 | + $this->driver->start(); |
36 | 23 |
|
37 | 24 | $this->expectException(DriverException::class); |
38 | 25 | $this->expectExceptionMessage('Invalid timeout type: invalid'); |
39 | 26 |
|
40 | | - $driver->setTimeouts(['invalid' => 0]); |
| 27 | + $this->driver->setTimeouts(['invalid' => 0]); |
41 | 28 | } |
42 | 29 |
|
43 | 30 | public function testShortTimeoutDoesNotWaitForElementToAppear(): void |
44 | 31 | { |
45 | | - $driver = $this->getSession()->getDriver(); |
46 | | - assert($driver instanceof WebdriverClassicDriver); |
47 | | - $driver->setTimeouts(['implicit' => 0]); |
| 32 | + $this->driver->start(); |
| 33 | + $this->driver->setTimeouts(['implicit' => 0]); |
48 | 34 |
|
49 | | - $this->getSession()->visit($this->pathTo('/js_test.html')); |
50 | | - $this->findById('waitable')->click(); |
51 | | - $element = $this->getSession()->getPage()->find('css', '#waitable > div'); |
| 35 | + $this->driver->visit($this->pathTo('/js_test.html')); |
| 36 | + $this->driver->click('//div[@id="waitable"]'); |
52 | 37 |
|
53 | | - $this->assertNull($element); |
| 38 | + $this->assertEmpty($this->driver->getText('//div[@id="waitable"]')); |
54 | 39 | } |
55 | 40 |
|
56 | 41 | public function testLongTimeoutWaitsForElementToAppear(): void |
57 | 42 | { |
58 | | - $driver = $this->getSession()->getDriver(); |
59 | | - assert($driver instanceof WebdriverClassicDriver); |
60 | | - $driver->setTimeouts(['implicit' => 5000]); |
| 43 | + $this->driver->start(); |
| 44 | + $this->driver->setTimeouts(['implicit' => 5000]); |
61 | 45 |
|
62 | | - $this->getSession()->visit($this->pathTo('/js_test.html')); |
63 | | - $this->findById('waitable')->click(); |
64 | | - $element = $this->getSession()->getPage()->find('css', '#waitable > div'); |
| 46 | + $this->driver->visit($this->pathTo('/js_test.html')); |
| 47 | + $this->driver->click('//div[@id="waitable"]'); |
65 | 48 |
|
66 | | - $this->assertNotNull($element); |
| 49 | + $this->assertNotEmpty($this->driver->getText('//div[@id="waitable"]/div')); |
67 | 50 | } |
68 | 51 |
|
69 | 52 | public function testShortPageLoadTimeoutThrowsException(): void |
70 | 53 | { |
71 | | - $session = $this->getSession(); |
72 | | - $driver = $session->getDriver(); |
73 | | - \assert($driver instanceof WebdriverClassicDriver); |
74 | | - |
75 | | - $driver->setTimeouts(['page' => 500]); |
| 54 | + $this->driver->start(); |
| 55 | + $this->driver->setTimeouts(['page' => 500]); |
76 | 56 |
|
77 | 57 | $this->expectException(DriverException::class); |
78 | 58 | $this->expectExceptionMessage('Page failed to load: '); |
79 | | - $session->visit($this->pathTo('/page_load.php?sleep=2')); |
| 59 | + |
| 60 | + $this->driver->visit($this->pathTo('/page_load.php?sleep=2')); |
80 | 61 | } |
81 | 62 | } |
0 commit comments