Skip to content

Commit 029b431

Browse files
authored
Fix PHP 7.1 compat (symfony#86)
* Fix PHP 7.1 compat * Fix PHPDoc. Add test.
1 parent d09ad17 commit 029b431

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

src/Client.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
namespace Symfony\Component\Panther;
1515

16+
use Facebook\WebDriver\Exception\NoSuchElementException;
17+
use Facebook\WebDriver\Exception\TimeOutException;
18+
use Facebook\WebDriver\Remote\RemoteWebElement;
1619
use Facebook\WebDriver\WebDriver;
1720
use Facebook\WebDriver\WebDriverBy;
1821
use Facebook\WebDriver\WebDriverCapabilities;
@@ -226,7 +229,13 @@ public function getCookieJar()
226229
return new CookieJar($this->webDriver);
227230
}
228231

229-
public function waitFor(string $cssSelector, int $timeoutInSecond = 30, int $intervalInMillisecond = 250): object
232+
/**
233+
* @throws NoSuchElementException
234+
* @throws TimeOutException
235+
*
236+
* @return RemoteWebElement
237+
*/
238+
public function waitFor(string $cssSelector, int $timeoutInSecond = 30, int $intervalInMillisecond = 250)
230239
{
231240
return $this->wait($timeoutInSecond, $intervalInMillisecond)->until(
232241
WebDriverExpectedCondition::visibilityOfElementLocated(WebDriverBy::cssSelector($cssSelector))

tests/ClientTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace Symfony\Component\Panther\Tests;
1515

16+
use Facebook\WebDriver\Remote\RemoteWebElement;
1617
use Facebook\WebDriver\WebDriver;
1718
use Symfony\Component\BrowserKit\Client as BrowserKitClient;
1819
use Symfony\Component\BrowserKit\Cookie;
@@ -34,6 +35,15 @@ public function testCreateClient()
3435
$this->assertInstanceOf(WebDriver::class, $client);
3536
}
3637

38+
public function testWaitFor()
39+
{
40+
$client = self::createPantherClient();
41+
$crawler = $client->request('GET', '/waitfor.html');
42+
$c = $client->waitFor('#hello');
43+
$this->assertInstanceOf(RemoteWebElement::class, $c);
44+
$this->assertSame('Hello', $crawler->filter('#hello')->text());
45+
}
46+
3747
/**
3848
* @dataProvider clientFactoryProvider
3949
*/

tests/fixtures/waitfor.html

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>WaitFor</title>
6+
</head>
7+
<body>
8+
<div id="root"></div>
9+
10+
<template id="t-hello">
11+
<p id="hello">Hello</p>
12+
</template>
13+
14+
<script>
15+
window.setTimeout(function () {
16+
document.getElementById('root').appendChild(
17+
document.importNode(document.getElementById('t-hello').content, true)
18+
);
19+
}, 1000);
20+
</script>
21+
</body>
22+
</html>

0 commit comments

Comments
 (0)