|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +/** This is project's console commands configuration for Robo task runner. |
| 8 | + * |
| 9 | + * @codingStandardsIgnoreStart |
| 10 | + * @see http://robo.li/ |
| 11 | + */ |
| 12 | +class RoboFile extends \Robo\Tasks |
| 13 | +{ |
| 14 | + use Robo\Task\Base\loadShortcuts; |
| 15 | + |
| 16 | + /** |
| 17 | + * Duplicate the Example configuration files used to customize the Project for customization. |
| 18 | + * |
| 19 | + * @return void |
| 20 | + */ |
| 21 | + function cloneFiles() |
| 22 | + { |
| 23 | + $this->_exec('cp -vn .env.example .env'); |
| 24 | + $this->_exec('cp -vf codeception.dist.yml codeception.yml'); |
| 25 | + $this->_exec('cp -vf dev' . DIRECTORY_SEPARATOR . 'tests'. DIRECTORY_SEPARATOR . 'functional' . DIRECTORY_SEPARATOR .'MFTF.suite.dist.yml dev' . DIRECTORY_SEPARATOR . 'tests'. DIRECTORY_SEPARATOR . 'functional' . DIRECTORY_SEPARATOR .'MFTF.suite.yml'); |
| 26 | + } |
| 27 | + |
| 28 | + /** |
| 29 | + * Duplicate the Example configuration files for the Project. |
| 30 | + * Build the Codeception project. |
| 31 | + * |
| 32 | + * @return void |
| 33 | + */ |
| 34 | + function buildProject() |
| 35 | + { |
| 36 | + $this->writeln("<error>This command will be removed in MFTF v3.0.0. Please use bin/mftf build:project instead.</error>\n"); |
| 37 | + $this->cloneFiles(); |
| 38 | + $this->_exec('vendor'. DIRECTORY_SEPARATOR .'bin'. DIRECTORY_SEPARATOR .'codecept build'); |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * Generate all Tests in PHP. |
| 43 | + * |
| 44 | + * @param array $tests |
| 45 | + * @param array $opts |
| 46 | + * @return void |
| 47 | + */ |
| 48 | + function generateTests(array $tests, $opts = ['config' => null, 'force' => true, 'nodes' => null, 'debug' => false]) |
| 49 | + { |
| 50 | + require 'dev' . DIRECTORY_SEPARATOR . 'tests'. DIRECTORY_SEPARATOR . 'functional' . DIRECTORY_SEPARATOR . '_bootstrap.php'; |
| 51 | + $GLOBALS['GENERATE_TESTS'] = true; |
| 52 | + if (!$this->isProjectBuilt()) { |
| 53 | + $this->say("<info>Please run bin/mftf build:project and configure your environment (.env) first.</info>"); |
| 54 | + exit(\Robo\Result::EXITCODE_ERROR); |
| 55 | + } |
| 56 | + $testsObjects = []; |
| 57 | + foreach ($tests as $test) { |
| 58 | + $testsObjects[] = Magento\FunctionalTestingFramework\Test\Handlers\TestObjectHandler::getInstance()->getObject($test); |
| 59 | + } |
| 60 | + if ($opts['force']) { |
| 61 | + $GLOBALS['FORCE_PHP_GENERATE'] = true; |
| 62 | + } |
| 63 | + $testsReferencedInSuites = \Magento\FunctionalTestingFramework\Suite\SuiteGenerator::getInstance()->generateAllSuites($opts['config']); |
| 64 | + \Magento\FunctionalTestingFramework\Util\TestGenerator::getInstance(null, $testsObjects, $opts['debug'])->createAllTestFiles($opts['config'], $opts['nodes'], $testsReferencedInSuites); |
| 65 | + $this->say("<comment>Generate Tests Command Run</comment>"); |
| 66 | + } |
| 67 | + |
| 68 | + /** |
| 69 | + * Check if MFTF has been properly configured |
| 70 | + * @return bool |
| 71 | + */ |
| 72 | + private function isProjectBuilt() |
| 73 | + { |
| 74 | + $actorFile = __DIR__ . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'Magento' . DIRECTORY_SEPARATOR . 'FunctionalTestingFramework' . DIRECTORY_SEPARATOR . '_generated' . DIRECTORY_SEPARATOR . 'AcceptanceTesterActions.php'; |
| 75 | + |
| 76 | + $login = !empty(getenv('MAGENTO_ADMIN_USERNAME')); |
| 77 | + $password = !empty(getenv('MAGENTO_ADMIN_PASSWORD')); |
| 78 | + $baseUrl = !empty(getenv('MAGENTO_BASE_URL')); |
| 79 | + $backendName = !empty(getenv('MAGENTO_BACKEND_NAME')); |
| 80 | + $test = (file_exists($actorFile) && $login && $password && $baseUrl && $backendName); |
| 81 | + return $test; |
| 82 | + } |
| 83 | + |
| 84 | + /** |
| 85 | + * Generate a suite based on name(s) passed in as args. |
| 86 | + * |
| 87 | + * @param array $args |
| 88 | + * @throws Exception |
| 89 | + * @return void |
| 90 | + */ |
| 91 | + function generateSuite(array $args) |
| 92 | + { |
| 93 | + if (empty($args)) { |
| 94 | + throw new Exception("Please provide suite name(s) after generate:suite command"); |
| 95 | + } |
| 96 | + |
| 97 | + require 'dev' . DIRECTORY_SEPARATOR . 'tests'. DIRECTORY_SEPARATOR . 'functional' . DIRECTORY_SEPARATOR . '_bootstrap.php'; |
| 98 | + $sg = \Magento\FunctionalTestingFramework\Suite\SuiteGenerator::getInstance(); |
| 99 | + |
| 100 | + foreach ($args as $arg) { |
| 101 | + $sg->generateSuite($arg); |
| 102 | + } |
| 103 | + } |
| 104 | + |
| 105 | + /** |
| 106 | + * Run all MFTF tests. |
| 107 | + * |
| 108 | + * @return void |
| 109 | + */ |
| 110 | + function mftf() |
| 111 | + { |
| 112 | + $this->_exec('.' . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . 'codecept run MFTF --skip-group skip'); |
| 113 | + } |
| 114 | + |
| 115 | + /** |
| 116 | + * Run all Tests with the specified @group tag, excluding @group 'skip'. |
| 117 | + * |
| 118 | + * @param string $args |
| 119 | + * @return void |
| 120 | + */ |
| 121 | + function group($args = '') |
| 122 | + { |
| 123 | + $this->taskExec('.' . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . 'codecept run --verbose --steps --skip-group skip --group')->args($args)->run(); |
| 124 | + } |
| 125 | + |
| 126 | + /** |
| 127 | + * Run all Functional tests located under the Directory Path provided. |
| 128 | + * |
| 129 | + * @param string $args |
| 130 | + * @return void |
| 131 | + */ |
| 132 | + function folder($args = '') |
| 133 | + { |
| 134 | + $this->taskExec('.' . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . 'codecept run ')->args($args)->run(); |
| 135 | + } |
| 136 | + |
| 137 | + /** |
| 138 | + * Run all Tests marked with the @group tag 'example'. |
| 139 | + * |
| 140 | + * @return void |
| 141 | + */ |
| 142 | + function example() |
| 143 | + { |
| 144 | + $this->_exec('.' . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . 'codecept run --group example --skip-group skip'); |
| 145 | + } |
| 146 | + |
| 147 | + /** |
| 148 | + * Generate the HTML for the Allure report based on the Test XML output - Allure v1.4.X |
| 149 | + * |
| 150 | + * @return \Robo\Result |
| 151 | + */ |
| 152 | + function allure1Generate() |
| 153 | + { |
| 154 | + return $this->_exec('allure generate tests'. DIRECTORY_SEPARATOR .'_output'. DIRECTORY_SEPARATOR .'allure-results'. DIRECTORY_SEPARATOR .' -o tests'. DIRECTORY_SEPARATOR .'_output'. DIRECTORY_SEPARATOR .'allure-report'. DIRECTORY_SEPARATOR .''); |
| 155 | + } |
| 156 | + |
| 157 | + /** |
| 158 | + * Generate the HTML for the Allure report based on the Test XML output - Allure v2.3.X |
| 159 | + * |
| 160 | + * @return \Robo\Result |
| 161 | + */ |
| 162 | + function allure2Generate() |
| 163 | + { |
| 164 | + return $this->_exec('allure generate tests'. DIRECTORY_SEPARATOR .'_output'. DIRECTORY_SEPARATOR .'allure-results'. DIRECTORY_SEPARATOR .' --output tests'. DIRECTORY_SEPARATOR .'_output'. DIRECTORY_SEPARATOR .'allure-report'. DIRECTORY_SEPARATOR .' --clean'); |
| 165 | + } |
| 166 | + |
| 167 | + /** |
| 168 | + * Open the HTML Allure report - Allure v1.4.X |
| 169 | + * |
| 170 | + * @return void |
| 171 | + */ |
| 172 | + function allure1Open() |
| 173 | + { |
| 174 | + $this->_exec('allure report open --report-dir tests'. DIRECTORY_SEPARATOR .'_output'. DIRECTORY_SEPARATOR .'allure-report'. DIRECTORY_SEPARATOR .''); |
| 175 | + } |
| 176 | + |
| 177 | + /** |
| 178 | + * Open the HTML Allure report - Allure v2.3.X |
| 179 | + * |
| 180 | + * @return void |
| 181 | + */ |
| 182 | + function allure2Open() |
| 183 | + { |
| 184 | + $this->_exec('allure open --port 0 tests'. DIRECTORY_SEPARATOR .'_output'. DIRECTORY_SEPARATOR .'allure-report'. DIRECTORY_SEPARATOR .''); |
| 185 | + } |
| 186 | + |
| 187 | + /** |
| 188 | + * Generate and open the HTML Allure report - Allure v1.4.X |
| 189 | + * |
| 190 | + * @return void |
| 191 | + */ |
| 192 | + function allure1Report() |
| 193 | + { |
| 194 | + $result1 = $this->allure1Generate(); |
| 195 | + |
| 196 | + if ($result1->wasSuccessful()) { |
| 197 | + $this->allure1Open(); |
| 198 | + } |
| 199 | + } |
| 200 | + |
| 201 | + /** |
| 202 | + * Generate and open the HTML Allure report - Allure v2.3.X |
| 203 | + * |
| 204 | + * @return void |
| 205 | + */ |
| 206 | + function allure2Report() |
| 207 | + { |
| 208 | + $result1 = $this->allure2Generate(); |
| 209 | + |
| 210 | + if ($result1->wasSuccessful()) { |
| 211 | + $this->allure2Open(); |
| 212 | + } |
| 213 | + } |
| 214 | +} |
0 commit comments