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

Commit 1780264

Browse files
authored
Merge pull request #637 from OndraM/feature/fix-saucelabs
Improve test stability on SauceLabs
2 parents 2dbfa70 + 6d488ea commit 1780264

File tree

6 files changed

+26
-19
lines changed

6 files changed

+26
-19
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ matrix:
4949
jwt:
5050
secure: HPq5xFhosa1eSGnaRdJzeyEuaE0mhRlG1gf3G7+dKS0VniF30husSyrxZhbGCCKBGxmIySoAQzd43BCwL69EkUEVKDN87Cpid1Ce9KrSfU3cnN8XIb+4QINyy7x1a47RUAfaaOEx53TrW0ShalvjD+ZwDE8LrgagSox6KQ+nQLE=
5151
- php: 7.2
52-
env: SAUCELABS=1 BROWSER_NAME="chrome" VERSION="latest" PLATFORM="Windows 10"
52+
env: SAUCELABS=1 BROWSER_NAME="chrome" VERSION="74.0" PLATFORM="Windows 10"
5353
before_script:
5454
- php -S 127.0.0.1:8000 -t tests/functional/web/ &>>./logs/php-server.log &
5555
- until $(echo | nc localhost 8000); do sleep 1; echo waiting for PHP server on port 8000...; done; echo "PHP server started"
@@ -58,7 +58,7 @@ matrix:
5858
jwt:
5959
secure: HPq5xFhosa1eSGnaRdJzeyEuaE0mhRlG1gf3G7+dKS0VniF30husSyrxZhbGCCKBGxmIySoAQzd43BCwL69EkUEVKDN87Cpid1Ce9KrSfU3cnN8XIb+4QINyy7x1a47RUAfaaOEx53TrW0ShalvjD+ZwDE8LrgagSox6KQ+nQLE=
6060
- php: 7.2
61-
env: SAUCELABS=1 BROWSER_NAME="MicrosoftEdge" VERSION="15.15063" PLATFORM="Windows 10"
61+
env: SAUCELABS=1 BROWSER_NAME="MicrosoftEdge" VERSION="16.16299" PLATFORM="Windows 10"
6262
before_script:
6363
- php -S 127.0.0.1:8000 -t tests/functional/web/ &>>./logs/php-server.log &
6464
- until $(echo | nc localhost 8000); do sleep 1; echo waiting for PHP server on port 8000...; done; echo "PHP server started"

tests/functional/RemoteWebDriverTest.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ public function testShouldCloseWindow()
145145

146146
/**
147147
* @covers ::executeScript
148+
* @group exclude-saucelabs
148149
*/
149150
public function testShouldExecuteScriptAndDoNotBlockExecution()
150151
{
@@ -153,17 +154,18 @@ public function testShouldExecuteScriptAndDoNotBlockExecution()
153154
$element = $this->driver->findElement(WebDriverBy::id('id_test'));
154155
$this->assertSame('Test by ID', $element->getText());
155156

157+
$start = microtime(true);
156158
$this->driver->executeScript('
157159
setTimeout(
158-
function(){document.getElementById("id_test").innerHTML = "Text changed by script"},
159-
500
160+
function(){document.getElementById("id_test").innerHTML = "Text changed by script";},
161+
250
160162
)');
163+
$end = microtime(true);
161164

162-
// Make sure the script don't block the test execution
163-
$this->assertSame('Test by ID', $element->getText());
165+
$this->assertLessThan(250, $end - $start, 'executeScript() should not block execution');
164166

165-
// If we wait, the script should be executed
166-
usleep(1000000); // wait 1000 ms
167+
// If we wait, the script should be executed and its value changed
168+
usleep(300000); // wait 300 ms
167169
$this->assertSame('Text changed by script', $element->getText());
168170
}
169171

@@ -180,6 +182,7 @@ public function testShouldExecuteAsyncScriptAndWaitUntilItIsFinished()
180182
$element = $this->driver->findElement(WebDriverBy::id('id_test'));
181183
$this->assertSame('Test by ID', $element->getText());
182184

185+
$start = microtime(true);
183186
$this->driver->executeAsyncScript(
184187
'var callback = arguments[arguments.length - 1];
185188
setTimeout(
@@ -190,6 +193,13 @@ function(){
190193
250
191194
);'
192195
);
196+
$end = microtime(true);
197+
198+
$this->assertGreaterThan(
199+
0.250,
200+
$end - $start,
201+
'executeAsyncScript() should block execution until callback() is called'
202+
);
193203

194204
// The result must be immediately available, as the executeAsyncScript should block the execution until the
195205
// callback is called.
@@ -204,7 +214,7 @@ public function testShouldTakeScreenshot()
204214
if (!extension_loaded('gd')) {
205215
$this->markTestSkipped('GD extension must be enabled');
206216
}
207-
if ($this->desiredCapabilities->getBrowserName() == WebDriverBrowserType::HTMLUNIT) {
217+
if ($this->desiredCapabilities->getBrowserName() === WebDriverBrowserType::HTMLUNIT) {
208218
$this->markTestSkipped('Screenshots are not supported by HtmlUnit browser');
209219
}
210220

@@ -227,7 +237,7 @@ public function testShouldSaveScreenshotToFile()
227237
if (!extension_loaded('gd')) {
228238
$this->markTestSkipped('GD extension must be enabled');
229239
}
230-
if ($this->desiredCapabilities->getBrowserName() == WebDriverBrowserType::HTMLUNIT) {
240+
if ($this->desiredCapabilities->getBrowserName() === WebDriverBrowserType::HTMLUNIT) {
231241
$this->markTestSkipped('Screenshots are not supported by HtmlUnit browser');
232242
}
233243

tests/functional/WebDriverActionsTest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,7 @@ public function testShouldDoubleClickOnElement()
122122
->doubleClick($element)
123123
->perform();
124124

125-
$this->assertSame(
126-
['mouseover item-3', 'mousedown item-3', 'mouseup item-3', 'click item-3', 'dblclick item-3'],
127-
$this->retrieveLoggedEvents()
128-
);
125+
$this->assertContains('dblclick item-3', $this->retrieveLoggedEvents());
129126
}
130127

131128
/**

tests/functional/WebDriverTestCase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ protected function setUp()
4444
{
4545
$this->desiredCapabilities = new DesiredCapabilities();
4646

47-
if ($this->isSauceLabsBuild()) {
47+
if (static::isSauceLabsBuild()) {
4848
$this->setUpSauceLabs();
4949
} else {
5050
if (getenv('BROWSER_NAME')) {
@@ -87,7 +87,7 @@ protected function tearDown()
8787
/**
8888
* @return bool
8989
*/
90-
public function isSauceLabsBuild()
90+
public static function isSauceLabsBuild()
9191
{
9292
return getenv('SAUCELABS') ? true : false;
9393
}

tests/functional/WebDriverTimeoutsTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function testShouldGetDelayedElementWithImplicitWait()
4242
{
4343
$this->driver->get($this->getTestPageUrl('delayed_element.html'));
4444

45-
$this->driver->manage()->timeouts()->implicitlyWait(1);
45+
$this->driver->manage()->timeouts()->implicitlyWait(2);
4646
$element = $this->driver->findElement(WebDriverBy::id('delayed'));
4747

4848
$this->assertInstanceOf(RemoteWebElement::class, $element);
@@ -54,7 +54,7 @@ public function testShouldGetDelayedElementWithImplicitWait()
5454
*/
5555
public function testShouldFailIfPageIsLoadingLongerThanPageLoadTimeout()
5656
{
57-
if ($this->desiredCapabilities->getBrowserName() == WebDriverBrowserType::HTMLUNIT) {
57+
if ($this->desiredCapabilities->getBrowserName() === WebDriverBrowserType::HTMLUNIT) {
5858
$this->markTestSkipped('Not supported by HtmlUnit browser');
5959
}
6060

tests/functional/web/delayed_element.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
setTimeout(function () {
1313
var wrapper = document.getElementById("wrapper");
1414
wrapper.innerHTML = '<div id="delayed">Element appearing after 500ms</div>';
15-
}, 500);
15+
}, 1500);
1616
</script>
1717

1818
</body>

0 commit comments

Comments
 (0)