From 13d19ebe4260d188ac8bfe3d9297ed566c54e0c7 Mon Sep 17 00:00:00 2001 From: javier gomez Date: Tue, 9 Jun 2015 13:53:47 +0200 Subject: [PATCH 1/3] Adds idividual test run command This pull adds two new commands to Robo --- RoboFile.php | 115 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 111 insertions(+), 4 deletions(-) diff --git a/RoboFile.php b/RoboFile.php index 738c554..e7a378f 100644 --- a/RoboFile.php +++ b/RoboFile.php @@ -31,13 +31,14 @@ class RoboFile extends \Robo\Tasks } /** - * Executes Selenium System Tests in your machine + * Executes all the Selenium System Tests in a suite on your machine * - * @param null $seleniumPath Optional path to selenium-standalone-server-x.jar + * @param string $seleniumPath Optional path to selenium-standalone-server-x.jar + * @param string $suite Optional, the name of the tests suite * * @return mixed */ - public function testAcceptance($seleniumPath = null) + public function runTests($seleniumPath = null, $suite = 'acceptance') { $this->setExecExtension(); @@ -108,7 +109,7 @@ class RoboFile extends \Robo\Tasks $this->_exec('php' . $this->extension . ' vendor/bin/codecept build'); $this->taskCodecept() - ->suite('acceptance') + ->suite($suite) ->arg('--steps') ->arg('--debug') ->run() @@ -128,4 +129,110 @@ class RoboFile extends \Robo\Tasks } */ } + + /** + * Executes a specific Selenium System Tests in your machine + * + * @param string $seleniumPath Optional path to selenium-standalone-server-x.jar + * @param string $pathToTestFile Optional name of the test to be run + * @param string $suite Optional name of the suite containing the tests, Acceptance by default. + * + * @return mixed + */ + public function runTest($seleniumPath = null, $pathToTestFile = null, $suite = 'acceptance') + { + if (!$seleniumPath) { + if (!file_exists('selenium-server-standalone.jar')) { + $this->say('Downloading Selenium Server, this may take a while.'); + $this->taskExec('wget') + ->arg('http://selenium-release.storage.googleapis.com/2.45/selenium-server-standalone-2.45.0.jar') + ->arg('-O selenium-server-standalone.jar') + ->printed(false) + ->run(); + } + $seleniumPath = 'selenium-server-standalone.jar'; + } + + // Make sure we have Composer + if (!file_exists('./composer.phar')) { + $this->_exec('curl -sS https://getcomposer.org/installer | php'); + } + $this->taskComposerUpdate()->run(); + + // Running Selenium server + $this->_exec("java -jar $seleniumPath > selenium-errors.log 2>selenium.log &"); + + $this->taskWaitForSeleniumStandaloneServer() + ->run() + ->stopOnFail(); + + // Make sure to Run the Build Command to Generate AcceptanceTester + $this->_exec("php vendor/bin/codecept build"); + + if (!$pathToTestFile) + { + $tests = array(); + $this->say('Available tests in the system:'); + $filesInSuite = scandir(getcwd() . '/tests/' . $suite); + + $i = 1; + foreach ($filesInSuite as $file) + { + // Make sure the file is a Test file + if (strripos($file, 'cept.php') || strripos($file, 'cest.php')) + { + $tests[$i] = $file; + $this->say('[' . $i . '] ' . $file); + $i++; + } + } + $this->say(''); + $testNumber = $this->ask('Type the number of the test in the list that you want to run...'); + $pathToTestFile = "tests/$suite/" . $tests[$testNumber]; + } + + $this->taskCodecept() + ->test($pathToTestFile) + ->arg('--steps') + ->arg('--debug') + ->run() + ->stopOnFail(); + + // Kill selenium server + // $this->_exec('curl http://localhost:4444/selenium-server/driver/?cmd=shutDownSeleniumServer'); + + $this->say('Printing Selenium Log files'); + $this->say('------ selenium-errors.log (start) ---------'); + $seleniumErrors = file_get_contents('selenium-errors.log'); + if ($seleniumErrors) { + $this->say(file_get_contents('selenium-errors.log')); + } + else { + $this->say('no errors were found'); + } + $this->say('------ selenium-errors.log (end) -----------'); + + /* + // Uncomment if you need to debug issues in selenium + $this->say(''); + $this->say('------ selenium.log (start) -----------'); + $this->say(file_get_contents('selenium.log')); + $this->say('------ selenium.log (end) -----------'); + */ + } + + /** + * Creates a testing Joomla site for running the tests (use it before run:test) + */ + public function createTestingSite() + { + // Get Joomla Clean Testing sites + if (is_dir('tests/joomla-cms3')) + { + $this->taskDeleteDir('tests/joomla-cms3')->run(); + } + + $this->_exec('git' . $this->extension . ' clone -b staging --single-branch --depth 1 https://github.com/joomla/joomla-cms.git tests/joomla-cms3'); + $this->say('Joomla CMS site created at tests/joomla-cms3'); + } } \ No newline at end of file From 7a5964e8dd1f86a6f83c2587190c04f5caebacf0 Mon Sep 17 00:00:00 2001 From: javier gomez Date: Tue, 9 Jun 2015 16:19:16 +0200 Subject: [PATCH 2/3] Make travis use the new Robo function --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 96e906a..fb9db7e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,4 +28,4 @@ before_script: script: - mv tests/acceptance.suite.dist.yml tests/acceptance.suite.yml -- php vendor/bin/robo test:acceptance +- php vendor/bin/robo run:tests \ No newline at end of file From 0d46dab53448f5c2bf2d7f7f212fa608a28abf65 Mon Sep 17 00:00:00 2001 From: zero-24 Date: Tue, 9 Jun 2015 19:10:05 +0200 Subject: [PATCH 3/3] Give the robo some CS love --- RoboFile.php | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/RoboFile.php b/RoboFile.php index e7a378f..3c08480 100644 --- a/RoboFile.php +++ b/RoboFile.php @@ -141,8 +141,10 @@ class RoboFile extends \Robo\Tasks */ public function runTest($seleniumPath = null, $pathToTestFile = null, $suite = 'acceptance') { - if (!$seleniumPath) { - if (!file_exists('selenium-server-standalone.jar')) { + if (!$seleniumPath) + { + if (!file_exists('selenium-server-standalone.jar')) + { $this->say('Downloading Selenium Server, this may take a while.'); $this->taskExec('wget') ->arg('http://selenium-release.storage.googleapis.com/2.45/selenium-server-standalone-2.45.0.jar') @@ -150,11 +152,13 @@ class RoboFile extends \Robo\Tasks ->printed(false) ->run(); } + $seleniumPath = 'selenium-server-standalone.jar'; } // Make sure we have Composer - if (!file_exists('./composer.phar')) { + if (!file_exists('./composer.phar')) + { $this->_exec('curl -sS https://getcomposer.org/installer | php'); } $this->taskComposerUpdate()->run(); @@ -174,8 +178,8 @@ class RoboFile extends \Robo\Tasks $tests = array(); $this->say('Available tests in the system:'); $filesInSuite = scandir(getcwd() . '/tests/' . $suite); - $i = 1; + foreach ($filesInSuite as $file) { // Make sure the file is a Test file @@ -186,8 +190,9 @@ class RoboFile extends \Robo\Tasks $i++; } } + $this->say(''); - $testNumber = $this->ask('Type the number of the test in the list that you want to run...'); + $testNumber = $this->ask('Type the number of the test in the list that you want to run...'); $pathToTestFile = "tests/$suite/" . $tests[$testNumber]; } @@ -204,10 +209,13 @@ class RoboFile extends \Robo\Tasks $this->say('Printing Selenium Log files'); $this->say('------ selenium-errors.log (start) ---------'); $seleniumErrors = file_get_contents('selenium-errors.log'); - if ($seleniumErrors) { + + if ($seleniumErrors) + { $this->say(file_get_contents('selenium-errors.log')); } - else { + else + { $this->say('no errors were found'); } $this->say('------ selenium-errors.log (end) -----------'); @@ -235,4 +243,4 @@ class RoboFile extends \Robo\Tasks $this->_exec('git' . $this->extension . ' clone -b staging --single-branch --depth 1 https://github.com/joomla/joomla-cms.git tests/joomla-cms3'); $this->say('Joomla CMS site created at tests/joomla-cms3'); } -} \ No newline at end of file +}