Skip to content

Commit

Permalink
Merge pull request #413 from OndraM/feature/saucelabs-testing
Browse files Browse the repository at this point in the history
Run functional tests on SauceLabs
  • Loading branch information
OndraM committed Feb 13, 2017
2 parents ff3c556 + 6f3e340 commit 0549087
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 56 deletions.
30 changes: 28 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,39 @@ php:

matrix:
include:
# Add build to run tests against Firefox (other runs are agains HtmlUnit by default)
# Add build to run tests against Firefox inside Travis environment (other runs are agains HtmlUnit by default)
- php: 7.0
env: BROWSER_NAME="firefox"
addons:
firefox: "latest-esr"

# Build with lowest possible dependencies
- php: 7.0
env: dependencies="--prefer-lowest"

# Saucelabs builds
- php: 7.0
env: SAUCELABS=1 BROWSER_NAME="firefox" VERSION="47.0" PLATFORM="Windows 10"
before_script: php -S localhost:8000 -t tests/functional/web/ &>>./logs/php-server.log &
addons:
sauce_connect: true
jwt:
secure: HPq5xFhosa1eSGnaRdJzeyEuaE0mhRlG1gf3G7+dKS0VniF30husSyrxZhbGCCKBGxmIySoAQzd43BCwL69EkUEVKDN87Cpid1Ce9KrSfU3cnN8XIb+4QINyy7x1a47RUAfaaOEx53TrW0ShalvjD+ZwDE8LrgagSox6KQ+nQLE=
- php: 7.0
env: SAUCELABS=1 BROWSER_NAME="firefox" VERSION="45.0" PLATFORM="Linux"
before_script: php -S localhost:8000 -t tests/functional/web/ &>>./logs/php-server.log &
addons:
sauce_connect: true
jwt:
secure: HPq5xFhosa1eSGnaRdJzeyEuaE0mhRlG1gf3G7+dKS0VniF30husSyrxZhbGCCKBGxmIySoAQzd43BCwL69EkUEVKDN87Cpid1Ce9KrSfU3cnN8XIb+4QINyy7x1a47RUAfaaOEx53TrW0ShalvjD+ZwDE8LrgagSox6KQ+nQLE=
- php: 7.0
env: SAUCELABS=1 BROWSER_NAME="chrome" VERSION="latest" PLATFORM="Windows 10"
before_script: php -S localhost:8000 -t tests/functional/web/ &>>./logs/php-server.log &
addons:
sauce_connect: true
jwt:
secure: HPq5xFhosa1eSGnaRdJzeyEuaE0mhRlG1gf3G7+dKS0VniF30husSyrxZhbGCCKBGxmIySoAQzd43BCwL69EkUEVKDN87Cpid1Ce9KrSfU3cnN8XIb+4QINyy7x1a47RUAfaaOEx53TrW0ShalvjD+ZwDE8LrgagSox6KQ+nQLE=

# Add PHP 7 build to check codestyle only in PHP 7 build
- php: 7.0
env: CHECK_CODESTYLE=1
Expand Down Expand Up @@ -62,7 +89,6 @@ after_success:
- travis_retry php vendor/bin/coveralls -v

addons:
firefox: "latest-esr"
apt:
packages:
- oracle-java8-installer
2 changes: 1 addition & 1 deletion tests/functional/FileUploadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function testShouldUploadAFile()

public function xtestUselessFileDetectorSendKeys()
{
$this->driver->get($this->getTestPath('upload.html'));
$this->driver->get($this->getTestPageUrl('upload.html'));

$file_input = $this->driver->findElement(WebDriverBy::id('upload'));
$file_input->sendKeys($this->getTestFilePath());
Expand Down
6 changes: 3 additions & 3 deletions tests/functional/RemoteWebDriverCreateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function testShouldStartBrowserAndCreateInstanceOfRemoteWebDriver()
$this->assertInstanceOf(RemoteWebDriver::class, $this->driver);

$this->assertInstanceOf(HttpCommandExecutor::class, $this->driver->getCommandExecutor());
$this->assertSame($this->serverUrl, $this->driver->getCommandExecutor()->getAddressOfRemoteServer());
$this->assertNotEmpty($this->driver->getCommandExecutor()->getAddressOfRemoteServer());

$this->assertInternalType('string', $this->driver->getSessionID());
$this->assertNotEmpty($this->driver->getSessionID());
Expand Down Expand Up @@ -65,14 +65,14 @@ public function testShouldCreateInstanceFromExistingSessionId()
{
// Create driver instance and load page "index.html"
$originalDriver = RemoteWebDriver::create($this->serverUrl, $this->desiredCapabilities);
$originalDriver->get($this->getTestPath('index.html'));
$originalDriver->get($this->getTestPageUrl('index.html'));
$this->assertContains('/index.html', $originalDriver->getCurrentURL());

// Store session ID
$sessionId = $originalDriver->getSessionID();

// Create new RemoteWebDriver instance based on the session ID
$this->driver = RemoteWebDriver::createBySessionID($sessionId);
$this->driver = RemoteWebDriver::createBySessionID($sessionId, $this->serverUrl);

// Check we reused the previous instance (window) and it has the same URL
$this->assertContains('/index.html', $this->driver->getCurrentURL());
Expand Down
8 changes: 4 additions & 4 deletions tests/functional/RemoteWebDriverFindElementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ class RemoteWebDriverFindElementTest extends WebDriverTestCase
{
public function testShouldThrowExceptionOfElementCannotBeFound()
{
$this->driver->get($this->getTestPath('index.html'));
$this->driver->get($this->getTestPageUrl('index.html'));

$this->setExpectedException(NoSuchElementException::class, 'Unable to locate element');
$this->driver->findElement(WebDriverBy::id('not_existing'));
}

public function testShouldFindElementIfExistsOnAPage()
{
$this->driver->get($this->getTestPath('index.html'));
$this->driver->get($this->getTestPageUrl('index.html'));

$element = $this->driver->findElement(WebDriverBy::id('id_test'));

Expand All @@ -43,7 +43,7 @@ public function testShouldFindElementIfExistsOnAPage()

public function testShouldReturnEmptyArrayIfElementsCannotBeFound()
{
$this->driver->get($this->getTestPath('index.html'));
$this->driver->get($this->getTestPageUrl('index.html'));

$elements = $this->driver->findElements(WebDriverBy::cssSelector('not_existing'));

Expand All @@ -53,7 +53,7 @@ public function testShouldReturnEmptyArrayIfElementsCannotBeFound()

public function testShouldFindMultipleElements()
{
$this->driver->get($this->getTestPath('index.html'));
$this->driver->get($this->getTestPageUrl('index.html'));

$elements = $this->driver->findElements(WebDriverBy::cssSelector('ul > li'));

Expand Down
32 changes: 18 additions & 14 deletions tests/functional/RemoteWebDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class RemoteWebDriverTest extends WebDriverTestCase
*/
public function testShouldGetPageTitle()
{
$this->driver->get($this->getTestPath('index.html'));
$this->driver->get($this->getTestPageUrl('index.html'));

$this->assertEquals(
'php-webdriver test page',
Expand All @@ -43,7 +43,7 @@ public function testShouldGetPageTitle()
*/
public function testShouldGetCurrentUrl()
{
$this->driver->get($this->getTestPath('index.html'));
$this->driver->get($this->getTestPageUrl('index.html'));

$this->assertContains(
'/index.html',
Expand All @@ -56,7 +56,7 @@ public function testShouldGetCurrentUrl()
*/
public function testShouldGetPageSource()
{
$this->driver->get($this->getTestPath('index.html'));
$this->driver->get($this->getTestPageUrl('index.html'));

$source = $this->driver->getPageSource();
$this->assertContains('<h1 id="welcome">', $source);
Expand All @@ -79,7 +79,9 @@ public function testShouldGetSessionId()
*/
public function testShouldGetAllSessions()
{
$sessions = RemoteWebDriver::getAllSessions();
$this->skipOnSauceLabs('getAllSessions() is not supported on SauceLabs');

$sessions = RemoteWebDriver::getAllSessions($this->serverUrl);

$this->assertInternalType('array', $sessions);
$this->assertCount(1, $sessions);
Expand All @@ -96,12 +98,14 @@ public function testShouldGetAllSessions()
*/
public function testShouldQuitAndUnsetExecutor()
{
$this->assertCount(1, RemoteWebDriver::getAllSessions());
$this->skipOnSauceLabs('getAllSessions() is not supported on SauceLabs');

$this->assertCount(1, RemoteWebDriver::getAllSessions($this->serverUrl));
$this->assertInstanceOf(HttpCommandExecutor::class, $this->driver->getCommandExecutor());

$this->driver->quit();

$this->assertCount(0, RemoteWebDriver::getAllSessions());
$this->assertCount(0, RemoteWebDriver::getAllSessions($this->serverUrl));
$this->assertNull($this->driver->getCommandExecutor());
}

Expand All @@ -111,7 +115,7 @@ public function testShouldQuitAndUnsetExecutor()
*/
public function testShouldGetWindowHandles()
{
$this->driver->get($this->getTestPath('open_new_window.html'));
$this->driver->get($this->getTestPageUrl('open_new_window.html'));

$windowHandle = $this->driver->getWindowHandle();
$windowHandles = $this->driver->getWindowHandles();
Expand All @@ -135,7 +139,7 @@ public function testShouldGetWindowHandles()
*/
public function testShouldCloseWindow()
{
$this->driver->get($this->getTestPath('open_new_window.html'));
$this->driver->get($this->getTestPageUrl('open_new_window.html'));
$this->driver->findElement(WebDriverBy::cssSelector('a'))->click();

$this->assertCount(2, $this->driver->getWindowHandles());
Expand All @@ -150,22 +154,22 @@ public function testShouldCloseWindow()
*/
public function testShouldExecuteScriptAndDoNotBlockExecution()
{
$this->driver->get($this->getTestPath('index.html'));
$this->driver->get($this->getTestPageUrl('index.html'));

$element = $this->driver->findElement(WebDriverBy::id('id_test'));
$this->assertSame('Test by ID', $element->getText());

$this->driver->executeScript('
setTimeout(
function(){document.getElementById("id_test").innerHTML = "Text changed by script"},
250
500
)');

// Make sure the script don't block the test execution
$this->assertSame('Test by ID', $element->getText());

// If we wait, the script should be executed
usleep(300000); // wait 300 ms
usleep(550000); // wait 550 ms
$this->assertSame('Text changed by script', $element->getText());
}

Expand All @@ -176,7 +180,7 @@ public function testShouldExecuteAsyncScriptAndWaitUntilItIsFinished()
{
$this->driver->manage()->timeouts()->setScriptTimeout(1);

$this->driver->get($this->getTestPath('index.html'));
$this->driver->get($this->getTestPageUrl('index.html'));

$element = $this->driver->findElement(WebDriverBy::id('id_test'));
$this->assertSame('Test by ID', $element->getText());
Expand Down Expand Up @@ -209,7 +213,7 @@ public function testShouldTakeScreenshot()
$this->markTestSkipped('Screenshots are not supported by HtmlUnit browser');
}

$this->driver->get($this->getTestPath('index.html'));
$this->driver->get($this->getTestPageUrl('index.html'));

$outputPng = $this->driver->takeScreenshot();

Expand All @@ -234,7 +238,7 @@ public function testShouldSaveScreenshotToFile()

$screenshotPath = sys_get_temp_dir() . '/selenium-screenshot.png';

$this->driver->get($this->getTestPath('index.html'));
$this->driver->get($this->getTestPageUrl('index.html'));

$this->driver->takeScreenshot($screenshotPath);

Expand Down
24 changes: 12 additions & 12 deletions tests/functional/RemoteWebElementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class RemoteWebElementTest extends WebDriverTestCase
*/
public function testShouldGetText()
{
$this->driver->get($this->getTestPath('index.html'));
$this->driver->get($this->getTestPageUrl('index.html'));
$elementWithSimpleText = $this->driver->findElement(WebDriverBy::id('text-simple'));
$elementWithTextWithSpaces = $this->driver->findElement(WebDriverBy::id('text-with-spaces'));

Expand All @@ -38,7 +38,7 @@ public function testShouldGetText()
*/
public function testShouldGetAttributeValue()
{
$this->driver->get($this->getTestPath('index.html'));
$this->driver->get($this->getTestPageUrl('index.html'));

$element = $this->driver->findElement(WebDriverBy::id('text-simple'));

Expand All @@ -52,7 +52,7 @@ public function testShouldGetAttributeValue()
*/
public function testShouldGetLocation()
{
$this->driver->get($this->getTestPath('index.html'));
$this->driver->get($this->getTestPageUrl('index.html'));

$element = $this->driver->findElement(WebDriverBy::id('element-with-location'));

Expand All @@ -67,7 +67,7 @@ public function testShouldGetLocation()
*/
public function testShouldGetSize()
{
$this->driver->get($this->getTestPath('index.html'));
$this->driver->get($this->getTestPageUrl('index.html'));

$element = $this->driver->findElement(WebDriverBy::id('element-with-location'));

Expand All @@ -82,7 +82,7 @@ public function testShouldGetSize()
*/
public function testShouldGetCssValue()
{
$this->driver->get($this->getTestPath('index.html'));
$this->driver->get($this->getTestPageUrl('index.html'));

$elementWithBorder = $this->driver->findElement(WebDriverBy::id('text-simple'));
$elementWithoutBorder = $this->driver->findElement(WebDriverBy::id('text-with-spaces'));
Expand All @@ -99,7 +99,7 @@ public function testShouldGetCssValue()
*/
public function testShouldGetTagName()
{
$this->driver->get($this->getTestPath('index.html'));
$this->driver->get($this->getTestPageUrl('index.html'));

$paragraphElement = $this->driver->findElement(WebDriverBy::id('id_test'));

Expand All @@ -111,7 +111,7 @@ public function testShouldGetTagName()
*/
public function testShouldClick()
{
$this->driver->get($this->getTestPath('index.html'));
$this->driver->get($this->getTestPageUrl('index.html'));
$linkElement = $this->driver->findElement(WebDriverBy::id('a-form'));

$linkElement->click();
Expand All @@ -126,7 +126,7 @@ public function testShouldClick()
*/
public function testShouldClearFormElementText()
{
$this->driver->get($this->getTestPath('form.html'));
$this->driver->get($this->getTestPageUrl('form.html'));

$input = $this->driver->findElement(WebDriverBy::id('input-text'));
$textarea = $this->driver->findElement(WebDriverBy::id('textarea'));
Expand All @@ -145,7 +145,7 @@ public function testShouldClearFormElementText()
*/
public function testShouldSendKeysToFormElement()
{
$this->driver->get($this->getTestPath('form.html'));
$this->driver->get($this->getTestPageUrl('form.html'));

$input = $this->driver->findElement(WebDriverBy::id('input-text'));
$textarea = $this->driver->findElement(WebDriverBy::id('textarea'));
Expand All @@ -168,7 +168,7 @@ public function testShouldSendKeysToFormElement()
*/
public function testShouldDetectEnabledInputs()
{
$this->driver->get($this->getTestPath('form.html'));
$this->driver->get($this->getTestPageUrl('form.html'));

$inputEnabled = $this->driver->findElement(WebDriverBy::id('input-text'));
$inputDisabled = $this->driver->findElement(WebDriverBy::id('input-text-disabled'));
Expand All @@ -182,7 +182,7 @@ public function testShouldDetectEnabledInputs()
*/
public function testShouldSelectedInputsOrOptions()
{
$this->driver->get($this->getTestPath('form.html'));
$this->driver->get($this->getTestPageUrl('form.html'));

$checkboxSelected = $this->driver->findElement(
WebDriverBy::cssSelector('input[name=checkbox][value=second]')
Expand Down Expand Up @@ -263,7 +263,7 @@ public function testShouldSubmitFormByClickOnSubmitInput()
*/
public function testShouldCompareEqualsElement()
{
$this->driver->get($this->getTestPath('index.html'));
$this->driver->get($this->getTestPageUrl('index.html'));

$firstElement = $this->driver->findElement(WebDriverBy::cssSelector('ul.list'));
$differentElement = $this->driver->findElement(WebDriverBy::cssSelector('#text-simple'));
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/WebDriverAlertTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected function setUp()
{
parent::setUp();

$this->driver->get($this->getTestPath('alert.html'));
$this->driver->get($this->getTestPageUrl('alert.html'));
}

public function testShouldAcceptAlert()
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/WebDriverByTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function testShouldFindTextElementByLocator(
$expectedText = null,
$expectedAttributeValue = null
) {
$this->driver->get($this->getTestPath('index.html'));
$this->driver->get($this->getTestPageUrl('index.html'));

$by = call_user_func([WebDriverBy::class, $webDriverByLocatorMethod], $webDriverByLocatorValue);
$element = $this->driver->findElement($by);
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/WebDriverSelectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected function setUp()
{
parent::setUp();

$this->driver->get($this->getTestPath('form.html'));
$this->driver->get($this->getTestPageUrl('form.html'));
}

public function testShouldCreateNewInstanceForSelectElementAndDetectIfItIsMultiple()
Expand Down
Loading

0 comments on commit 0549087

Please sign in to comment.