13
13
14
14
namespace Symfony \Component \Panther \Tests ;
15
15
16
+ use Facebook \WebDriver \JavaScriptExecutor ;
16
17
use Facebook \WebDriver \Remote \RemoteWebElement ;
17
18
use Facebook \WebDriver \WebDriver ;
18
19
use Facebook \WebDriver \WebDriverExpectedCondition ;
@@ -35,6 +36,7 @@ public function testCreateClient()
35
36
$ client = self ::createPantherClient ();
36
37
$ this ->assertInstanceOf (BrowserKitClient::class, $ client );
37
38
$ this ->assertInstanceOf (WebDriver::class, $ client );
39
+ $ this ->assertInstanceOf (JavaScriptExecutor::class, $ client );
38
40
$ this ->assertInstanceOf (KernelInterface::class, self ::$ kernel );
39
41
}
40
42
@@ -47,6 +49,30 @@ public function testWaitFor()
47
49
$ this ->assertSame ('Hello ' , $ crawler ->filter ('#hello ' )->text ());
48
50
}
49
51
52
+ public function testExecuteScript ()
53
+ {
54
+ $ client = self ::createPantherClient ();
55
+ $ client ->request ('GET ' , '/basic.html ' );
56
+ $ innerText = $ client ->executeScript ('return document.querySelector(arguments[0]).innerText; ' , ['.p-1 ' ]);
57
+ $ this ->assertSame ('P1 ' , $ innerText );
58
+ }
59
+
60
+ public function testExecuteAsyncScript ()
61
+ {
62
+ $ client = self ::createPantherClient ();
63
+ $ client ->request ('GET ' , '/basic.html ' );
64
+ $ innerText = $ client ->executeAsyncScript (<<<JS
65
+ setTimeout(function (parentArgs) {
66
+ const callback = parentArgs[parentArgs.length - 1];
67
+ const t = document.querySelector(parentArgs[0]).innerText;
68
+ callback(t);
69
+ }, 100, arguments);
70
+ JS
71
+ , ['.p-1 ' ]);
72
+
73
+ $ this ->assertSame ('P1 ' , $ innerText );
74
+ }
75
+
50
76
/**
51
77
* @dataProvider clientFactoryProvider
52
78
*/
0 commit comments