Skip to content

Commit 1df63f4

Browse files
author
Oleksii Korshenko
authored
Merge pull request #659 from magento-fearless-kiwis/MAGETWO-61889-upgrade-tests
Fixed Issues: - MAGETWO-61889 Add debug events preset to UI Upgrade tests - MAGETWO-61927 UI Upgrade from 2.0.x to 2.0.11 Test Failure with Sample Data
2 parents 10eff9c + f276c1d commit 1df63f4

File tree

4 files changed

+184
-0
lines changed

4 files changed

+184
-0
lines changed

dev/tests/functional/etc/events.xml

+22
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,26 @@
4343
<tag name="webapi_failed" />
4444
</observer>
4545
</preset>
46+
<preset name="debug" extends="base">
47+
<observer class="Magento\Mtf\System\Observer\Screenshot">
48+
<tag name="exception"/>
49+
<tag name="failure"/>
50+
<tag name="click_after"/>
51+
<tag name="accept_alert_after"/>
52+
<tag name="dismiss_alert_after"/>
53+
<tag name="open_after"/>
54+
<tag name="forward"/>
55+
<tag name="back"/>
56+
</observer>
57+
<observer class="Magento\Mtf\System\Observer\SourceCode">
58+
<tag name="exception"/>
59+
<tag name="failure"/>
60+
<tag name="click_after"/>
61+
<tag name="accept_alert_after"/>
62+
<tag name="dismiss_alert_after"/>
63+
<tag name="open_after"/>
64+
<tag name="forward"/>
65+
<tag name="back"/>
66+
</observer>
67+
</preset>
4668
</config>

dev/tests/functional/tests/app/Magento/Upgrade/Test/Block/SelectVersion.php

+159
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Mtf\Client\Element\SimpleElement;
1111
use Magento\Mtf\Client\Locator;
1212
use Magento\Mtf\Fixture\FixtureInterface;
13+
use Magento\Mtf\Client\ElementInterface;
1314

1415
/**
1516
* Select version block.
@@ -63,4 +64,162 @@ public function chooseUpgradeOtherComponents()
6364
$this->_rootElement->find("[for=yesUpdateComponents]", Locator::SELECTOR_CSS)->click();
6465
$this->waitForElementVisible("[ng-show='componentsProcessed']");
6566
}
67+
68+
/**
69+
* Set maximum compatible sample data for each row
70+
* Iterates through each page of the grid and sets the compatible version from fixture
71+
*
72+
* @param string $sampleDataVersion
73+
* @return void
74+
*/
75+
public function chooseVersionUpgradeOtherComponents($sampleDataVersion)
76+
{
77+
do {
78+
$this->iterateAndSetComponentsRows($this->convertVersionFixtureToRegexp($sampleDataVersion));
79+
if ($this->canClickOnNextPage()) {
80+
$this->clickOnNextPage();
81+
}
82+
} while ($this->canClickOnNextPage());
83+
}
84+
85+
/**
86+
* Gets components rows as ElementInterface
87+
*
88+
* @return ElementInterface[]
89+
*/
90+
private function getComponentsTableRows()
91+
{
92+
return $this->_rootElement->getElements("table.data-grid tbody tr");
93+
}
94+
95+
/**
96+
* Iterate through components in table and set compatible version for selected magento version
97+
*
98+
* @param $sampleDataVersion
99+
* @return void
100+
*/
101+
private function iterateAndSetComponentsRows($sampleDataVersion)
102+
{
103+
$rows = $this->getComponentsTableRows();
104+
for ($rowIndex = 1; $rowIndex <= count($rows); $rowIndex++) {
105+
$textElement = $this->getRowComponentTitle($rowIndex);
106+
if ($this->titleContainsSampleData($textElement)) {
107+
$this->setSampleDataVersionToRowSelect($rowIndex, $sampleDataVersion);
108+
}
109+
}
110+
}
111+
112+
/**
113+
* Clicks on Next Page of the grid
114+
*
115+
* @return void
116+
*/
117+
private function clickOnNextPage()
118+
{
119+
$this->_rootElement->find(".admin__data-grid-pager .action-next", Locator::SELECTOR_CSS)->click();
120+
}
121+
122+
/**
123+
* Can click on next page
124+
*
125+
* @return bool
126+
*/
127+
private function canClickOnNextPage()
128+
{
129+
$element = $this->_rootElement->find(".admin__data-grid-pager .action-next");
130+
if ($element->isVisible()) {
131+
return !$element->isDisabled();
132+
}
133+
return false;
134+
}
135+
136+
/**
137+
* Gets rows component title
138+
*
139+
* @param int $rowIndex
140+
* @return ElementInterface
141+
*/
142+
private function getRowComponentTitle($rowIndex)
143+
{
144+
return $this->_rootElement->find(
145+
"//table//tbody//tr[" . $rowIndex . "]//td//*[contains(text(),'sample')]",
146+
Locator::SELECTOR_XPATH
147+
);
148+
}
149+
150+
/**
151+
* Gets the select element from row
152+
*
153+
* @param int $rowIndex
154+
* @return ElementInterface
155+
*/
156+
private function getSelectFromRow($rowIndex)
157+
{
158+
return $this->_rootElement->find(
159+
'//table//tbody//tr[' . $rowIndex . ']//td//select',
160+
Locator::SELECTOR_XPATH,
161+
'select'
162+
);
163+
}
164+
165+
/**
166+
* Convert sample data version fixture to regexp format
167+
* Example 100.1.* to 100\.1\.[0-9]+
168+
*
169+
* @param string $sampleDataVersion
170+
* @return string
171+
* @throws \Exception
172+
*/
173+
private function convertVersionFixtureToRegexp($sampleDataVersion)
174+
{
175+
if (!preg_match('/\d+(?:\.*\d*)*/', $sampleDataVersion)) {
176+
throw new \Exception('Wrong format for sample data version fixture. Example: 100.1.* needed.');
177+
}
178+
return str_replace('*', '[0-9]+', $sampleDataVersion);
179+
}
180+
181+
/**
182+
* Asserts if element's text contains sample data
183+
*
184+
* @param ElementInterface $element
185+
* @return bool
186+
*/
187+
private function titleContainsSampleData($element)
188+
{
189+
return preg_match('/magento\/.*sample-data/', $element->getText());
190+
}
191+
192+
/**
193+
* Sets sample data version matching the maximum compatible version from fixture
194+
*
195+
* @param int $rowIndex
196+
* @param string $sampleDataVersionForRegex
197+
* @return void
198+
*/
199+
private function setSampleDataVersionToRowSelect($rowIndex, $sampleDataVersionForRegex)
200+
{
201+
$selectElement = $this->getSelectFromRow($rowIndex);
202+
$optionTextArray = [];
203+
foreach ($selectElement->getElements('option') as $option) {
204+
$optionText = $option->getText();
205+
if (preg_match('/' . $sampleDataVersionForRegex . '/', $optionText)) {
206+
preg_match('/([0-9\.\-a-zA-Z]+)/', $optionText, $match);
207+
$optionTextArray[$optionText] = current($match);
208+
}
209+
}
210+
211+
if (!empty($optionTextArray)) {
212+
uasort(
213+
$optionTextArray,
214+
function ($versionOne, $versionTwo) {
215+
return version_compare($versionOne, $versionTwo) * -1;
216+
}
217+
);
218+
219+
$toSelectVersion = key($optionTextArray);
220+
if ($toSelectVersion !== $selectElement->getText()) {
221+
$selectElement->setValue($toSelectVersion);
222+
}
223+
}
224+
}
66225
}

dev/tests/functional/tests/app/Magento/Upgrade/Test/TestCase/UpgradeSystemTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public function test(
7272
['data' => $createBackupConfig]
7373
);
7474
$version = $upgrade['upgradeVersion'];
75+
$sampleDataVersion = $upgrade['sampledataVersion'];
7576

7677
$suffix = "( (CE|EE))$";
7778
$normalVersion = '(0|[1-9]\d*)';
@@ -109,6 +110,7 @@ public function test(
109110
$this->setupWizard->getSelectVersion()->fill($upgradeFixture);
110111
if ($upgrade['otherComponents'] === 'Yes') {
111112
$this->setupWizard->getSelectVersion()->chooseUpgradeOtherComponents();
113+
$this->setupWizard->getSelectVersion()->chooseVersionUpgradeOtherComponents($sampleDataVersion);
112114
}
113115
$this->setupWizard->getSelectVersion()->clickNext();
114116

dev/tests/functional/tests/app/Magento/Upgrade/Test/TestCase/UpgradeSystemTest.xml

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<data name="upgrade/optionsMedia" xsi:type="string">No</data>
1919
<data name="upgrade/optionsDb" xsi:type="string">No</data>
2020
<data name="upgrade/otherComponents" xsi:type="string">{otherComponents}</data>
21+
<data name="upgrade/sampledataVersion" xsi:type="string">{sampledataVersion}</data>
2122
</variation>
2223
</testCase>
2324
</config>

0 commit comments

Comments
 (0)