Skip to content

Commit

Permalink
Merge pull request #659 from magento-fearless-kiwis/MAGETWO-61889-upg…
Browse files Browse the repository at this point in the history
…rade-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
  • Loading branch information
Oleksii Korshenko authored Dec 9, 2016
2 parents 10eff9c + f276c1d commit 1df63f4
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 0 deletions.
22 changes: 22 additions & 0 deletions dev/tests/functional/etc/events.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,26 @@
<tag name="webapi_failed" />
</observer>
</preset>
<preset name="debug" extends="base">
<observer class="Magento\Mtf\System\Observer\Screenshot">
<tag name="exception"/>
<tag name="failure"/>
<tag name="click_after"/>
<tag name="accept_alert_after"/>
<tag name="dismiss_alert_after"/>
<tag name="open_after"/>
<tag name="forward"/>
<tag name="back"/>
</observer>
<observer class="Magento\Mtf\System\Observer\SourceCode">
<tag name="exception"/>
<tag name="failure"/>
<tag name="click_after"/>
<tag name="accept_alert_after"/>
<tag name="dismiss_alert_after"/>
<tag name="open_after"/>
<tag name="forward"/>
<tag name="back"/>
</observer>
</preset>
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Magento\Mtf\Client\Element\SimpleElement;
use Magento\Mtf\Client\Locator;
use Magento\Mtf\Fixture\FixtureInterface;
use Magento\Mtf\Client\ElementInterface;

/**
* Select version block.
Expand Down Expand Up @@ -63,4 +64,162 @@ public function chooseUpgradeOtherComponents()
$this->_rootElement->find("[for=yesUpdateComponents]", Locator::SELECTOR_CSS)->click();
$this->waitForElementVisible("[ng-show='componentsProcessed']");
}

/**
* Set maximum compatible sample data for each row
* Iterates through each page of the grid and sets the compatible version from fixture
*
* @param string $sampleDataVersion
* @return void
*/
public function chooseVersionUpgradeOtherComponents($sampleDataVersion)
{
do {
$this->iterateAndSetComponentsRows($this->convertVersionFixtureToRegexp($sampleDataVersion));
if ($this->canClickOnNextPage()) {
$this->clickOnNextPage();
}
} while ($this->canClickOnNextPage());
}

/**
* Gets components rows as ElementInterface
*
* @return ElementInterface[]
*/
private function getComponentsTableRows()
{
return $this->_rootElement->getElements("table.data-grid tbody tr");
}

/**
* Iterate through components in table and set compatible version for selected magento version
*
* @param $sampleDataVersion
* @return void
*/
private function iterateAndSetComponentsRows($sampleDataVersion)
{
$rows = $this->getComponentsTableRows();
for ($rowIndex = 1; $rowIndex <= count($rows); $rowIndex++) {
$textElement = $this->getRowComponentTitle($rowIndex);
if ($this->titleContainsSampleData($textElement)) {
$this->setSampleDataVersionToRowSelect($rowIndex, $sampleDataVersion);
}
}
}

/**
* Clicks on Next Page of the grid
*
* @return void
*/
private function clickOnNextPage()
{
$this->_rootElement->find(".admin__data-grid-pager .action-next", Locator::SELECTOR_CSS)->click();
}

/**
* Can click on next page
*
* @return bool
*/
private function canClickOnNextPage()
{
$element = $this->_rootElement->find(".admin__data-grid-pager .action-next");
if ($element->isVisible()) {
return !$element->isDisabled();
}
return false;
}

/**
* Gets rows component title
*
* @param int $rowIndex
* @return ElementInterface
*/
private function getRowComponentTitle($rowIndex)
{
return $this->_rootElement->find(
"//table//tbody//tr[" . $rowIndex . "]//td//*[contains(text(),'sample')]",
Locator::SELECTOR_XPATH
);
}

/**
* Gets the select element from row
*
* @param int $rowIndex
* @return ElementInterface
*/
private function getSelectFromRow($rowIndex)
{
return $this->_rootElement->find(
'//table//tbody//tr[' . $rowIndex . ']//td//select',
Locator::SELECTOR_XPATH,
'select'
);
}

/**
* Convert sample data version fixture to regexp format
* Example 100.1.* to 100\.1\.[0-9]+
*
* @param string $sampleDataVersion
* @return string
* @throws \Exception
*/
private function convertVersionFixtureToRegexp($sampleDataVersion)
{
if (!preg_match('/\d+(?:\.*\d*)*/', $sampleDataVersion)) {
throw new \Exception('Wrong format for sample data version fixture. Example: 100.1.* needed.');
}
return str_replace('*', '[0-9]+', $sampleDataVersion);
}

/**
* Asserts if element's text contains sample data
*
* @param ElementInterface $element
* @return bool
*/
private function titleContainsSampleData($element)
{
return preg_match('/magento\/.*sample-data/', $element->getText());
}

/**
* Sets sample data version matching the maximum compatible version from fixture
*
* @param int $rowIndex
* @param string $sampleDataVersionForRegex
* @return void
*/
private function setSampleDataVersionToRowSelect($rowIndex, $sampleDataVersionForRegex)
{
$selectElement = $this->getSelectFromRow($rowIndex);
$optionTextArray = [];
foreach ($selectElement->getElements('option') as $option) {
$optionText = $option->getText();
if (preg_match('/' . $sampleDataVersionForRegex . '/', $optionText)) {
preg_match('/([0-9\.\-a-zA-Z]+)/', $optionText, $match);
$optionTextArray[$optionText] = current($match);
}
}

if (!empty($optionTextArray)) {
uasort(
$optionTextArray,
function ($versionOne, $versionTwo) {
return version_compare($versionOne, $versionTwo) * -1;
}
);

$toSelectVersion = key($optionTextArray);
if ($toSelectVersion !== $selectElement->getText()) {
$selectElement->setValue($toSelectVersion);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public function test(
['data' => $createBackupConfig]
);
$version = $upgrade['upgradeVersion'];
$sampleDataVersion = $upgrade['sampledataVersion'];

$suffix = "( (CE|EE))$";
$normalVersion = '(0|[1-9]\d*)';
Expand Down Expand Up @@ -109,6 +110,7 @@ public function test(
$this->setupWizard->getSelectVersion()->fill($upgradeFixture);
if ($upgrade['otherComponents'] === 'Yes') {
$this->setupWizard->getSelectVersion()->chooseUpgradeOtherComponents();
$this->setupWizard->getSelectVersion()->chooseVersionUpgradeOtherComponents($sampleDataVersion);
}
$this->setupWizard->getSelectVersion()->clickNext();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<data name="upgrade/optionsMedia" xsi:type="string">No</data>
<data name="upgrade/optionsDb" xsi:type="string">No</data>
<data name="upgrade/otherComponents" xsi:type="string">{otherComponents}</data>
<data name="upgrade/sampledataVersion" xsi:type="string">{sampledataVersion}</data>
</variation>
</testCase>
</config>

0 comments on commit 1df63f4

Please sign in to comment.