@@ -62,9 +62,18 @@ public function testShouldGetPageSource()
6262
6363 /**
6464 * @covers ::getSessionID
65+ * @covers ::isW3cCompliant
6566 */
6667 public function testShouldGetSessionId ()
6768 {
69+ // This tests is intentionally included in another test, to not slow down build.
70+ // @TODO Remove following in 2.0
71+ if (self ::isW3cProtocolBuild ()) {
72+ $ this ->assertTrue ($ this ->driver ->isW3cCompliant ());
73+ } else {
74+ $ this ->assertFalse ($ this ->driver ->isW3cCompliant ());
75+ }
76+
6877 $ sessionId = $ this ->driver ->getSessionID ();
6978
7079 $ this ->assertInternalType ('string ' , $ sessionId );
@@ -171,13 +180,17 @@ public function testShouldExecuteScriptAndDoNotBlockExecution()
171180 $ this ->assertSame ('Test by ID ' , $ element ->getText ());
172181
173182 $ start = microtime (true );
174- $ this ->driver ->executeScript ('
183+ $ scriptResult = $ this ->driver ->executeScript ('
175184 setTimeout(
176185 function(){document.getElementById("id_test").innerHTML = "Text changed by script";},
177186 250
178- ) ' );
187+ );
188+ return "returned value";
189+ ' );
179190 $ end = microtime (true );
180191
192+ $ this ->assertSame ('returned value ' , $ scriptResult );
193+
181194 $ this ->assertLessThan (250 , $ end - $ start , 'executeScript() should not block execution ' );
182195
183196 // If we wait, the script should be executed and its value changed
@@ -199,18 +212,20 @@ public function testShouldExecuteAsyncScriptAndWaitUntilItIsFinished()
199212 $ this ->assertSame ('Test by ID ' , $ element ->getText ());
200213
201214 $ start = microtime (true );
202- $ this ->driver ->executeAsyncScript (
215+ $ scriptResult = $ this ->driver ->executeAsyncScript (
203216 'var callback = arguments[arguments.length - 1];
204217 setTimeout(
205218 function(){
206219 document.getElementById("id_test").innerHTML = "Text changed by script";
207- callback();
220+ callback("returned value" );
208221 },
209222 250
210223 ); '
211224 );
212225 $ end = microtime (true );
213226
227+ $ this ->assertSame ('returned value ' , $ scriptResult );
228+
214229 $ this ->assertGreaterThan (
215230 0.250 ,
216231 $ end - $ start ,
@@ -222,6 +237,31 @@ function(){
222237 $ this ->assertSame ('Text changed by script ' , $ element ->getText ());
223238 }
224239
240+ /**
241+ * @covers ::executeScript
242+ * @covers ::prepareScriptArguments
243+ * @group exclude-saucelabs
244+ */
245+ public function testShouldExecuteScriptWithParamsAndReturnValue ()
246+ {
247+ $ this ->driver ->manage ()->timeouts ()->setScriptTimeout (1 );
248+
249+ $ this ->driver ->get ($ this ->getTestPageUrl ('index.html ' ));
250+
251+ $ element1 = $ this ->driver ->findElement (WebDriverBy::id ('id_test ' ));
252+ $ element2 = $ this ->driver ->findElement (WebDriverBy::className ('test_class ' ));
253+
254+ $ scriptResult = $ this ->driver ->executeScript (
255+ 'var element1 = arguments[0];
256+ var element2 = arguments[1];
257+ return "1: " + element1.innerText + ", 2: " + element2.innerText;
258+ ' ,
259+ [$ element1 , $ element2 ]
260+ );
261+
262+ $ this ->assertSame ('1: Test by ID, 2: Test by Class ' , $ scriptResult );
263+ }
264+
225265 /**
226266 * @covers ::takeScreenshot
227267 */
0 commit comments