Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit 45d8357

Browse files
committed
Improve code coverage
1 parent 630863c commit 45d8357

File tree

3 files changed

+47
-24
lines changed

3 files changed

+47
-24
lines changed

lib/Remote/RemoteTargetLocator.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,11 @@
2525
*/
2626
class RemoteTargetLocator implements WebDriverTargetLocator
2727
{
28-
/**
29-
* @var ExecuteMethod
30-
*/
28+
/** @var ExecuteMethod */
3129
protected $executor;
32-
/**
33-
* @var WebDriver
34-
*/
30+
/** @var WebDriver */
3531
protected $driver;
36-
/**
37-
* @var bool
38-
*/
32+
/** @var bool */
3933
protected $isW3cCompliant;
4034

4135
public function __construct($executor, $driver, $isW3cCompliant = false)

tests/functional/RemoteTargetLocatorTest.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@ public function testShouldSwitchToWindow()
5555
$this->assertNotSame($originalWindowHandle, $this->driver->getWindowHandle());
5656
}
5757

58-
/**
59-
* @cover ::activeElement
60-
*/
6158
public function testActiveElement()
6259
{
6360
$this->driver->get($this->getTestPageUrl('index.html'));
@@ -72,9 +69,6 @@ public function testActiveElement()
7269
$this->assertSame('test_name', $activeElement->getAttribute('name'));
7370
}
7471

75-
/**
76-
* @cover ::frame
77-
*/
7872
public function testShouldSwitchToFrameByItsId()
7973
{
8074
$parentPage = 'This is the host page which contains an iFrame';
@@ -98,9 +92,6 @@ public function testShouldSwitchToFrameByItsId()
9892
$this->assertContains($parentPage, $this->driver->getPageSource());
9993
}
10094

101-
/**
102-
* @cover ::frame
103-
*/
10495
public function testShouldSwitchToFrameByElement()
10596
{
10697
$this->driver->get($this->getTestPageUrl('page_with_frame.html'));
@@ -112,7 +103,6 @@ public function testShouldSwitchToFrameByElement()
112103
}
113104

114105
/**
115-
* @cover ::frame
116106
* @group exclude-saucelabs
117107
*/
118108
public function testShouldNotAcceptStringAsFrameIdInW3cMode()
@@ -130,7 +120,6 @@ public function testShouldNotAcceptStringAsFrameIdInW3cMode()
130120
}
131121

132122
/**
133-
* @cover ::frame
134123
* @group exclude-saucelabs
135124
*/
136125
public function testShouldAcceptStringAsFrameIdInJsonWireMode()

tests/functional/RemoteWebDriverTest.php

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)