1313
1414namespace Symfony \Component \Panther \Tests ;
1515
16+ use Facebook \WebDriver \JavaScriptExecutor ;
1617use Facebook \WebDriver \Remote \RemoteWebElement ;
1718use Facebook \WebDriver \WebDriver ;
1819use Facebook \WebDriver \WebDriverExpectedCondition ;
@@ -35,6 +36,7 @@ public function testCreateClient()
3536 $ client = self ::createPantherClient ();
3637 $ this ->assertInstanceOf (BrowserKitClient::class, $ client );
3738 $ this ->assertInstanceOf (WebDriver::class, $ client );
39+ $ this ->assertInstanceOf (JavaScriptExecutor::class, $ client );
3840 $ this ->assertInstanceOf (KernelInterface::class, self ::$ kernel );
3941 }
4042
@@ -47,6 +49,30 @@ public function testWaitFor()
4749 $ this ->assertSame ('Hello ' , $ crawler ->filter ('#hello ' )->text ());
4850 }
4951
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+
5076 /**
5177 * @dataProvider clientFactoryProvider
5278 */
0 commit comments