Skip to content

Commit 80500e0

Browse files
authored
Merge branch 'develop' into MQE-1600
2 parents 6313da3 + fa56508 commit 80500e0

File tree

9 files changed

+139
-28
lines changed

9 files changed

+139
-28
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@ dev/tests/functional/MFTF.suite.yml
1616
dev/tests/functional/_output
1717
dev/mftf.log
1818
dev/tests/mftf.log
19-
dev/tests/docs/*
19+
dev/tests/docs/*
20+
dev/tests/_output
21+
dev/tests/functional.suite.yml

docs/selectors.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
## Selectors
2+
3+
These guidelines should help you to write high quality selectors.
4+
5+
### Selectors SHOULD be written in CSS instead of XPath whenever possible
6+
7+
CSS is generally easier to read than XPath. For example, `//*[@id="foo"]` in XPath can be expressed as simply as `#foo` in CSS.
8+
See this [XPath Cheatsheet](https://devhints.io/xpath) for more examples.
9+
10+
### XPath selectors SHOULD NOT use `@attribute="foo"`.
11+
12+
This would fail if the attribute was `attribute="foo bar"`.
13+
Instead you SHOULD use `contains(@attribute, "foo")` where `@attribute` is any valid attribute such as `@text` or `@class`.
14+
15+
### CSS and XPath selectors SHOULD be implemented in their most simple form
16+
17+
* <span class="color:green">GOOD:</span> `#foo`
18+
* <span class="color:red">BAD:</span> `button[contains(@id, "foo")]`
19+
20+
### CSS and XPath selectors SHOULD avoid making use of hardcoded indices
21+
22+
Instead you SHOULD parameterize the selector.
23+
24+
* <span class="color:green">GOOD:</span> `.foo:nth-of-type({{index}})`
25+
* <span class="color:red">BAD:</span> `.foo:nth-of-type(1)`
26+
27+
* <span class="color:green">GOOD:</span> `button[contains(@id, "foo")][{{index}}]`
28+
* <span class="color:red">BAD:</span> `button[contains(@id, "foo")][1]`
29+
30+
* <span class="color:green">GOOD:</span> `#actions__{{index}}__aggregator`
31+
* <span class="color:red">BAD:</span> `#actions__1__aggregator`
32+
33+
### CSS and XPath selectors MUST NOT reference the `@data-bind` attribute
34+
35+
The `@data-bind` attribute is used by KnockoutJS, a framework Magento uses to create dynamic Javascript pages. Since this `@data-bind` attribute is tied to a specific framework, it should not be used for selectors. If Magento decides to use a different framework then these `@data-bind` selectors would break.

docs/troubleshooting.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Chrome v62 is in the process of being rolled out, and it causes an error with Ch
4141

4242
#### Solution
4343

44-
Use [ChromeDriver v2.33+][]{:target="\_blank"} and [Selenium Server Standalone v3.6.0+][]{:target="\_blank"} in order to execute tests in Google Chrome v62+.
44+
Use [ChromeDriver 74.0.3729.6+][]{:target="\_blank"} and [Selenium Server Standalone v3.9+][]{:target="\_blank"} in order to execute tests in Google Chrome v62+.
4545

4646
### Firefox
4747

@@ -57,5 +57,5 @@ None yet. Solving this problem is dependent on a GeckoDriver fix.
5757

5858
<!-- Link Definitions -->
5959
[Headless Chrome]: https://developers.google.com/web/updates/2017/04/headless-chrome
60-
[ChromeDriver v2.33+]: https://chromedriver.storage.googleapis.com/index.html?path=2.33/
61-
[Selenium Server Standalone v3.6.0+]: http://www.seleniumhq.org/download/
60+
[ChromeDriver 74.0.3729.6+]: https://chromedriver.storage.googleapis.com/index.html?path=2.33/
61+
[Selenium Server Standalone v3.9+]: http://www.seleniumhq.org/download/

src/Magento/FunctionalTestingFramework/Codeception/Subscriber/Console.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,20 @@ class Console extends \Codeception\Subscriber\Console
3131
*/
3232
private $actionGroupStepKey = null;
3333

34+
/**
35+
* Console constructor. Parent constructor requires codeception CLI options, and does not have its own configs.
36+
* Constructor is only different than parent due to the way Codeception instantiates Extensions.
37+
*
38+
* @param array $extensionOptions
39+
* @param array $options
40+
*
41+
* @SuppressWarnings(PHPMD)
42+
*/
43+
public function __construct($extensionOptions = [], $options = [])
44+
{
45+
parent::__construct($options);
46+
}
47+
3448
/**
3549
* Printing stepKey in before step action.
3650
*

src/Magento/FunctionalTestingFramework/Console/StaticChecksCommand.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,19 @@
99
namespace Magento\FunctionalTestingFramework\Console;
1010

1111
use Magento\FunctionalTestingFramework\StaticCheck\StaticChecksList;
12+
use Magento\FunctionalTestingFramework\StaticCheck\StaticCheckListInterface;
1213
use Magento\FunctionalTestingFramework\Util\Logger\LoggingUtil;
1314
use Symfony\Component\Console\Command\Command;
1415
use Symfony\Component\Console\Input\InputInterface;
15-
use Symfony\Component\Console\Input\InputArgument;
1616
use Symfony\Component\Console\Output\OutputInterface;
17+
use Exception;
1718

1819
class StaticChecksCommand extends Command
1920
{
2021
/**
2122
* Pool of static check scripts to run
2223
*
23-
* @var \Magento\FunctionalTestingFramework\StaticCheck\StaticCheckListInterface
24+
* @var StaticCheckListInterface
2425
*/
2526
private $staticChecksList;
2627

@@ -41,16 +42,28 @@ protected function configure()
4142
*
4243
* @param InputInterface $input
4344
* @param OutputInterface $output
44-
* @return int|null|void
45-
* @throws \Exception
45+
* @return int
46+
* @throws Exception
4647
*/
4748
protected function execute(InputInterface $input, OutputInterface $output)
4849
{
4950
$staticCheckObjects = $this->staticChecksList->getStaticChecks();
51+
52+
$errors = [];
53+
5054
foreach ($staticCheckObjects as $staticCheck) {
51-
$staticOutput = $staticCheck->execute($input);
55+
$staticCheck->execute($input);
56+
57+
$staticOutput = $staticCheck->getOutput();
5258
LoggingUtil::getInstance()->getLogger(get_class($staticCheck))->info($staticOutput);
5359
$output->writeln($staticOutput);
60+
$errors += $staticCheck->getErrors();
61+
}
62+
63+
if (empty($errors)) {
64+
return 0;
65+
} else {
66+
return 1;
5467
}
5568
}
5669
}

src/Magento/FunctionalTestingFramework/StaticCheck/StaticCheckInterface.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,19 @@ interface StaticCheckInterface
1616
/**
1717
* Executes static check script, returns output.
1818
* @param InputInterface $input
19-
* @return string
19+
* @return void
2020
*/
2121
public function execute(InputInterface $input);
22+
23+
/**
24+
* Return array containing all errors found after running the execute() function.
25+
* @return array
26+
*/
27+
public function getErrors();
28+
29+
/**
30+
* Return string of a short human readable result of the check. For example: "No Dependency errors found."
31+
* @return string
32+
*/
33+
public function getOutput();
2234
}

src/Magento/FunctionalTestingFramework/StaticCheck/StaticCheckListInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ interface StaticCheckListInterface
1414
/**
1515
* Gets list of static check script instances
1616
*
17-
* @return \Magento\FunctionalTestingFramework\StaticCheck\StaticCheckListInterface[]
17+
* @return StaticCheckInterface[]
1818
*/
1919
public function getStaticChecks();
2020
}

src/Magento/FunctionalTestingFramework/StaticCheck/StaticChecksList.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ class StaticChecksList implements StaticCheckListInterface
1616
/**
1717
* Property contains all static check scripts.
1818
*
19-
* @var \Magento\FunctionalTestingFramework\StaticCheck\StaticCheckListInterface[]
19+
* @var StaticCheckInterface[]
2020
*/
2121
private $checks;
2222

2323
/**
2424
* Constructor
2525
*
26-
* @param array $scripts
26+
* @param array $checks
2727
*/
2828
public function __construct(array $checks = [])
2929
{

src/Magento/FunctionalTestingFramework/StaticCheck/TestDependencyCheck.php

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@
66

77
namespace Magento\FunctionalTestingFramework\StaticCheck;
88

9-
use Magento\FunctionalTestingFramework\Config\Data;
109
use Magento\FunctionalTestingFramework\Config\MftfApplicationConfig;
1110
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\DataObjectHandler;
11+
use Magento\FunctionalTestingFramework\Exceptions\TestReferenceException;
12+
use Magento\FunctionalTestingFramework\Exceptions\XmlException;
1213
use Magento\FunctionalTestingFramework\Page\Handlers\PageObjectHandler;
1314
use Magento\FunctionalTestingFramework\Page\Handlers\SectionObjectHandler;
14-
use Magento\FunctionalTestingFramework\Page\Objects\SectionObject;
1515
use Magento\FunctionalTestingFramework\Test\Handlers\ActionGroupObjectHandler;
1616
use Magento\FunctionalTestingFramework\Test\Handlers\TestObjectHandler;
1717
use Magento\FunctionalTestingFramework\Test\Objects\ActionObject;
1818
use Magento\FunctionalTestingFramework\Util\ModuleResolver;
1919
use Magento\FunctionalTestingFramework\Util\TestGenerator;
2020
use Symfony\Component\Console\Input\InputInterface;
21-
use Symfony\Component\Filesystem\Filesystem;
2221
use Symfony\Component\Finder\Finder;
22+
use Exception;
2323

2424
/**
2525
* Class TestDependencyCheck
@@ -62,11 +62,24 @@ class TestDependencyCheck implements StaticCheckInterface
6262
*/
6363
private $alreadyExtractedDependencies;
6464

65+
/**
66+
* Array containing all errors found after running the execute() function.
67+
* @var array
68+
*/
69+
private $errors;
70+
71+
/**
72+
* String representing the output summary found after running the execute() function.
73+
* @var string
74+
*/
75+
private $output;
76+
6577
/**
6678
* Checks test dependencies, determined by references in tests versus the dependencies listed in the Magento module
6779
*
6880
* @param InputInterface $input
6981
* @return string
82+
* @throws Exception;
7083
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
7184
*/
7285
public function execute(InputInterface $input)
@@ -98,21 +111,39 @@ public function execute(InputInterface $input)
98111
$actionGroupXmlFiles = $this->buildFileList($allModules, $filePaths[1]);
99112
$dataXmlFiles= $this->buildFileList($allModules, $filePaths[2]);
100113

101-
$testErrors = [];
102-
$testErrors += $this->findErrorsInFileSet($testXmlFiles);
103-
$testErrors += $this->findErrorsInFileSet($actionGroupXmlFiles);
104-
$testErrors += $this->findErrorsInFileSet($dataXmlFiles);
114+
$this->errors = [];
115+
$this->errors += $this->findErrorsInFileSet($testXmlFiles);
116+
$this->errors += $this->findErrorsInFileSet($actionGroupXmlFiles);
117+
$this->errors += $this->findErrorsInFileSet($dataXmlFiles);
105118

106-
//print all errors to file
107-
return $this->printErrorsToFile($testErrors);
119+
// hold on to the output and print any errors to a file
120+
$this->output = $this->printErrorsToFile();
121+
}
122+
123+
/**
124+
* Return array containing all errors found after running the execute() function.
125+
* @return array
126+
*/
127+
public function getErrors()
128+
{
129+
return $this->errors;
130+
}
131+
132+
/**
133+
* Return string of a short human readable result of the check. For example: "No Dependency errors found."
134+
* @return string
135+
*/
136+
public function getOutput()
137+
{
138+
return $this->output;
108139
}
109140

110141
/**
111142
* Finds all reference errors in given set of files
112143
* @param Finder $files
113144
* @return array
114-
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException
115-
* @throws \Magento\FunctionalTestingFramework\Exceptions\XmlException
145+
* @throws TestReferenceException
146+
* @throws XmlException
116147
*/
117148
private function findErrorsInFileSet($files)
118149
{
@@ -333,8 +364,7 @@ private function buildFileList($modulePaths, $path)
333364
* Attempts to find any MFTF entity by its name. Returns null if none are found.
334365
* @param string $name
335366
* @return mixed
336-
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException
337-
* @throws \Magento\FunctionalTestingFramework\Exceptions\XmlException
367+
* @throws XmlException
338368
*/
339369
private function findEntity($name)
340370
{
@@ -363,24 +393,29 @@ private function findEntity($name)
363393

364394
/**
365395
* Prints out given errors to file, and returns summary result string
366-
* @param array $errors
367396
* @return string
368397
*/
369-
private function printErrorsToFile($errors)
398+
private function printErrorsToFile()
370399
{
400+
$errors = $this->getErrors();
401+
371402
if (empty($errors)) {
372403
return "No Dependency errors found.";
373404
}
405+
374406
$outputPath = getcwd() . DIRECTORY_SEPARATOR . "mftf-dependency-checks.txt";
375407
$fileResource = fopen($outputPath, 'w');
376408
$header = "MFTF File Dependency Check:\n";
377409
fwrite($fileResource, $header);
410+
378411
foreach ($errors as $test => $error) {
379412
fwrite($fileResource, $error[0] . PHP_EOL);
380413
}
414+
381415
fclose($fileResource);
382416
$errorCount = count($errors);
383417
$output = "Dependency errors found across {$errorCount} file(s). Error details output to {$outputPath}";
418+
384419
return $output;
385420
}
386421
}

0 commit comments

Comments
 (0)