Skip to content

Commit

Permalink
Tests now run in chrome, firefox, edge and IE (joomla#96)
Browse files Browse the repository at this point in the history
* Now works on chrome, firefox, edge and IE

* update branch

* update branch

* fix mac detection and codestyle

* updating dependencies
  • Loading branch information
compojoom authored and yvesh committed Dec 11, 2016
1 parent 29e4296 commit 24f7798
Show file tree
Hide file tree
Showing 6 changed files with 494 additions and 222 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@ If you want to see steps then you can use `--steps` option of codeception. Check

**Note**:You can modify the timeout time by setting the value of **TIMEOUT** constant lower for fast machines and higher for slow computers. The constant located in the file `tests/codeception/acceptance/_bootstrap.php`

Changing the browser the tests are running with?
---
In your acceptance.suite.yml just change the browser name. Possible values are firefox, chrome, internet explorer and MicrosoftEdge.

Note: If you are running Windows Insiders builds, then you need to set MicrosoftEdgeInsiders to true.

Do you have suggestions?
---
Please create an issue here https://github.com/joomla-projects/gsoc16_browser-automated-tests/issues we will be happy to discuss and improve project.
Expand Down
108 changes: 88 additions & 20 deletions RoboFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ class RoboFile extends \Robo\Tasks
*
* @since __DEPLOY_VERSION__
*
* @return void
*/
public function __construct()
{
Expand Down Expand Up @@ -269,11 +268,11 @@ public function runSelenium()
{
if (!$this->isWindows())
{
$this->_exec($this->testsPath . "vendor/bin/selenium-server-standalone >> selenium.log 2>&1 &");
$this->_exec($this->testsPath . "vendor/bin/selenium-server-standalone " . $this->getWebDriver() . ' >> selenium.log 2>&1 &');
}
else
{
$this->_exec("START java.exe -jar .\\tests\\codeception\\vendor\\joomla-projects\\selenium-server-standalone\\bin\\selenium-server-standalone.jar");
$this->_exec("START java.exe -jar " . $this->getWebDriver() . ' tests\codeception\vendor\joomla-projects\selenium-server-standalone\bin\selenium-server-standalone.jar ');
}

if ($this->isWindows())
Expand Down Expand Up @@ -311,7 +310,7 @@ public function runTests($opts = ['use-htaccess' => false, 'env' => 'desktop'])
$this->runSelenium();

// Make sure to run the build command to generate AcceptanceTester
if($this->isWindows())
if ($this->isWindows())
{
$this->_exec('php ' . $this->getWindowsPath($this->testsPath . 'vendor/bin/codecept') . ' build');
$pathToCodeception = $this->getWindowsPath($this->testsPath . 'vendor/bin/codecept');
Expand Down Expand Up @@ -403,19 +402,6 @@ public function runTests($opts = ['use-htaccess' => false, 'env' => 'desktop'])
->arg($this->testsPath . 'acceptance/frontend/')
->run()
->stopOnFail();

/*
// Uncomment this lines if you need to debug selenium errors
$seleniumErrors = file_get_contents('selenium.log');
if ($seleniumErrors)
{
$this->say('Printing Selenium Log files');
$this->say('------ selenium.log (start) ---------');
$this->say($seleniumErrors);
$this->say('------ selenium.log (end) -----------');
}
*/
}

/**
Expand All @@ -435,7 +421,7 @@ public function runTest($pathToTestFile = null, $suite = 'acceptance')
// Make sure to run the build command to generate AcceptanceTester

$path = 'tests/codeception/vendor/bin/codecept';
$this->_exec('php ' . $this->isWindows() ? $this->getWindowsPath($path) : $path .' build');
$this->_exec('php ' . $this->isWindows() ? $this->getWindowsPath($path) : $path . ' build');

if (!$pathToTestFile)
{
Expand Down Expand Up @@ -522,7 +508,7 @@ public function runTest($pathToTestFile = null, $suite = 'acceptance')

$testPathCodecept = $this->testsPath . 'vendor/bin/codecept';

$this->taskCodecept($this->isWindows() ? $this->getWindowsPath($testPathCodecept): $testPathCodecept)
$this->taskCodecept($this->isWindows() ? $this->getWindowsPath($testPathCodecept) : $testPathCodecept)
->test($pathToTestFile)
->arg('--steps')
->arg('--debug')
Expand All @@ -543,12 +529,94 @@ private function isWindows()
/**
* Return the correct path for Windows
*
* param string $path - The linux path
* @param string $path - The linux path
*
* @return string
*/
private function getWindowsPath($path)
{
return str_replace('/', DIRECTORY_SEPARATOR, $path);
}

/**
* Detect the correct driver for selenium
*
* @return string the webdriver string to use with selenium
*
* @since version
*/
public function getWebdriver()
{
$suiteConfig = Symfony\Component\Yaml\Yaml::parse(file_get_contents('tests/codeception/acceptance.suite.yml'));
$codeceptMainConfig = \Codeception\Configuration::config();
$browser = $suiteConfig['modules']['config']['JoomlaBrowser']['browser'];

if ($browser == 'chrome')
{
$driver['type'] = 'webdriver.chrome.driver';
}
elseif ($browser == 'firefox')
{
$driver['type'] = 'webdriver.gecko.driver';
}
elseif ($browser == 'MicrosoftEdge')
{
$driver['type'] = 'webdriver.edge.driver';

// Check if we are using Windows Insider builds
if ($suiteConfig['modules']['config']['AcceptanceHelper']['MicrosoftEdgeInsiders'])
{
$browser = 'MicrosoftEdgeInsiders';
}
}
elseif ($browser == 'internet explorer')
{
$driver['type'] = 'webdriver.ie.driver';
}

// Check if we have a path for this browser and OS in the codeception settings
if (isset($codeceptMainConfig['webdrivers'][$browser][$this->getOs()]))
{
$driverPath = $codeceptMainConfig['webdrivers'][$browser][$this->getOs()];
}
else
{
$this->yell('No driver for your browser. Check your browser in acceptance.suite.yml and the webDrivers in codeception.yml');

// We can't do anything without a driver, exit
exit(1);
}

$driver['path'] = $driverPath;

return '-D' . implode('=', $driver);
}

/**
* Return the os name
*
* @return string
*
* @since version
*/
private function getOs()
{
$os = php_uname('s');

if (strpos(strtolower($os), 'windows') !== false)
{
$os = 'windows';
}
// Who have thought that Mac is actually Darwin???
elseif (strpos(strtolower($os), 'darwin') !== false)
{
$os = 'mac';
}
else
{
$os = 'linux';
}

return $os;
}
}
15 changes: 15 additions & 0 deletions codeception.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,18 @@ modules:
user: ''
password: ''
dump: tests/codeception/_data/dump.sql
webdrivers:
firefox:
windows: tests\codeception\vendor\joomla-projects\selenium-server-standalone\bin\webdrivers\gecko\geckodriver64.exe
mac: tests/codeception/vendor/joomla-projects/selenium-server-standalone/bin/webdrivers/gecko/geckodriver_mac
linux: tests/codeception/vendor/joomla-projects/selenium-server-standalone/bin/webdrivers/gecko/geckodriver_linux_64
chrome:
windows: tests\codeception\vendor\joomla-projects\selenium-server-standalone\bin\webdrivers\chrome\chromedriver.exe
mac: tests/codeception/vendor/joomla-projects/selenium-server-standalone/bin/webdrivers/chrome/chromedriver_mac
linux: tests/codeception/vendor/joomla-projects/selenium-server-standalone/bin/webdrivers/chrome/chromedriver_linux_64
internet explorer:
windows: tests\codeception\vendor\joomla-projects\selenium-server-standalone\bin\webdrivers\internet-explorer32\IEDriverServer.exe
MicrosoftEdge:
windows: tests\codeception\vendor\joomla-projects\selenium-server-standalone\bin\webdrivers\edge\MicrosoftWebDriver.exe
MicrosoftEdgeInsiders:
windows: tests\codeception\vendor\joomla-projects\selenium-server-standalone\bin\webdrivers\edge-insiders\MicrosoftWebDriver.exe
3 changes: 2 additions & 1 deletion tests/codeception/acceptance.suite.dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ modules:
config:
JoomlaBrowser:
url: 'http://localhost/tests/codeception/joomla-cms3' # the url that points to the joomla installation at /tests/system/joomla-cms
browser: 'firefox'
browser: 'chrome'
window_size: 1024x768
capabilities:
unexpectedAlertBehaviour: 'accept'
Expand All @@ -31,6 +31,7 @@ modules:
language: 'English (United Kingdom)' # Language in which you want the Application to be Installed
AcceptanceHelper:
url: 'http://localhost/tests/codeception/joomla-cms3' # the url that points to the joomla installation at /tests/system/joomla-cms - we need it twice here
MicrosoftEdgeInsiders: false # set this to true, if you are on Windows Insiders
error_level: "E_ALL & ~E_STRICT & ~E_DEPRECATED"
gherkin:
contexts:
Expand Down
2 changes: 1 addition & 1 deletion tests/codeception/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"require-dev": {
"codeception/codeception": "~2.2",
"joomla-projects/joomla-browser": "v3.4.8.3",
"joomla-projects/selenium-server-standalone": "v2.53.1.1",
"joomla-projects/selenium-server-standalone": "v3.0.1.1",
"codegyre/robo": "~0.6",
"joomla-projects/robo": "dev-master",
"fzaninotto/faker": "^1.5",
Expand Down
Loading

0 comments on commit 24f7798

Please sign in to comment.