Skip to content

Commit bf24553

Browse files
authored
Merge pull request #63 from magento/CD-develop
Deliver changes from Contribution Day ### Fixed Issues (if relevant) 1. Resolve #56: Add "block" type to list of existing section element types 2. Resolve #57: Debug flag exists in robo generate:tests to print action sequence of test steps 3. Resolve #58: Allow browser type to be configured in env file 4. Resolve #60: Build interactive configuration tool for populating .env properties 5. Resolve #61: Validate build:project was run before attempting to generate tests
2 parents b35c503 + 2109b0d commit bf24553

21 files changed

+6177
-28
lines changed

.env.example

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#Copyright © Magento, Inc. All rights reserved.
2+
#See COPYING.txt for license details.
3+
4+
#*** Set the base URL for your Magento instance ***#
5+
MAGENTO_BASE_URL=http://devdocs.magento.com/
6+
7+
#*** Set the Admin Username and Password for your Magento instance ***#
8+
MAGENTO_BACKEND_NAME=admin
9+
MAGENTO_ADMIN_USERNAME=admin
10+
MAGENTO_ADMIN_PASSWORD=123123q
11+
12+
#*** Path to CLI entry point and command parameter name. Uncomment and change if folder structure differs from standard Magento installation
13+
#MAGENTO_CLI_COMMAND_PATH=dev/tests/acceptance/utils/command.php
14+
#MAGENTO_CLI_COMMAND_PARAMETER=command
15+
16+
#*** Selenium Server Protocol, Host, Port, and Path, with local defaults. Uncomment and change if not running Selenium locally.
17+
#SELENIUM_HOST=127.0.0.1
18+
#SELENIUM_PORT=4444
19+
#SELENIUM_PROTOCOL=http
20+
#SELENIUM_PATH=/wd/hub
21+
22+
#*** Browser for running tests, default chrome. Uncomment and change if you want to run tests on another browser (ex. firefox).
23+
BROWSER=chrome
24+
25+
#*** Uncomment and set host & port if your dev environment needs different value other than MAGENTO_BASE_URL for Rest API Requests ***#
26+
#MAGENTO_RESTAPI_SERVER_HOST=
27+
#MAGENTO_RESTAPI_SERVER_PORT=
28+
29+
#*** Uncomment these properties to set up a dev environment with symlinked projects ***#
30+
#TESTS_BP=
31+
#FW_BP=
32+
#TESTS_MODULE_PATH=
33+
34+
#*** These properties impact the modules loaded into MFTF, you can point to your own full path, or a custom set of modules located with the core set
35+
MODULE_WHITELIST=Magento_Framework,Magento_ConfigurableProductWishlist,Magento_ConfigurableProductCatalogSearch
36+
#CUSTOM_MODULE_PATHS=
37+
38+
#*** Bool property which allows the user to toggle debug output during test execution
39+
#MFTF_DEBUG=
40+
#*** End of .env ***#

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ build/*
1111
clover.xml
1212
coverage/
1313
.vscode
14+
codeception.yml
15+
dev/tests/functional/MFTF.suite.yml
16+
dev/tests/functional/_output

RoboFile.php

+214
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
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+
}

bin/mftf

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env php
2+
3+
<?php
4+
/**
5+
* Copyright © Magento, Inc. All rights reserved.
6+
* See COPYING.txt for license details.
7+
*/
8+
9+
if (PHP_SAPI !== 'cli') {
10+
echo 'bin/mftf must be run as a CLI application';
11+
exit(1);
12+
}
13+
14+
try {
15+
require_once __DIR__ . '/../bootstrap.php';
16+
$application = new Symfony\Component\Console\Application();
17+
$application->setName('Magento Functional Testing Framework CLI');
18+
$application->setVersion('1.0.0');
19+
$application->add(new Magento\FunctionalTestingFramework\Console\SetupEnvCommand());
20+
$application->add(new Magento\FunctionalTestingFramework\Console\BuildProjectCommand());
21+
$application->run();
22+
} catch (\Exception $e) {
23+
while ($e) {
24+
echo $e->getMessage();
25+
echo $e->getTraceAsString();
26+
echo "\n\n";
27+
$e = $e->getPrevious();
28+
}
29+
exit(1);
30+
}

bootstrap.php

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
require_once 'vendor/autoload.php';
8+
define('BP', __DIR__);

codeception.dist.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright © Magento, Inc. All rights reserved.
2+
# See COPYING.txt for license details.
3+
actor: Tester
4+
paths:
5+
tests: dev/tests/functional
6+
log: dev/tests/functional/_output
7+
data: dev/tests/functional/_data
8+
support: src/Magento/FunctionalTestingFramework
9+
envs: etc/_envs
10+
settings:
11+
bootstrap: _bootstrap.php
12+
colors: true
13+
memory_limit: 1024M
14+
extensions:
15+
enabled:
16+
- Codeception\Extension\RunFailed
17+
- Yandex\Allure\Adapter\AllureAdapter
18+
config:
19+
Yandex\Allure\Adapter\AllureAdapter:
20+
deletePreviousResults: true
21+
outputDirectory: allure-results
22+
ignoredAnnotations:
23+
- env
24+
- zephyrId
25+
- useCaseId
26+
params:
27+
- .env

composer.json

+9-3
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@
1010
},
1111
"require": {
1212
"php": "7.0.2|7.0.4|~7.0.6|~7.1.0|~7.2.0",
13+
"allure-framework/allure-codeception": "~1.2.6",
1314
"codeception/codeception": "~2.3.4",
15+
"consolidation/robo": "^1.0.0",
1416
"epfremme/swagger-php": "^2.0",
1517
"flow/jsonpath": ">0.2",
1618
"fzaninotto/faker": "^1.6",
17-
"mustache/mustache": "~2.5"
19+
"mustache/mustache": "~2.5",
20+
"symfony/process": ">=2.7 <3.4",
21+
"vlucas/phpdotenv": "^2.4"
1822
},
1923
"require-dev": {
2024
"squizlabs/php_codesniffer": "1.5.3",
@@ -30,7 +34,8 @@
3034
},
3135
"autoload": {
3236
"psr-4": {
33-
"Magento\\FunctionalTestingFramework\\": "src/Magento/FunctionalTestingFramework"
37+
"Magento\\FunctionalTestingFramework\\": "src/Magento/FunctionalTestingFramework",
38+
"MFTF\\": "dev/tests/functional/MFTF"
3439
}
3540
},
3641
"autoload-dev": {
@@ -46,5 +51,6 @@
4651
"hooks": {
4752
"pre-push": "bin/all-checks"
4853
}
49-
}
54+
},
55+
"bin": ["bin/mftf"]
5056
}

0 commit comments

Comments
 (0)