Skip to content

Commit c285653

Browse files
authored
MQE-233 [Customizability] Update Object Model to handle special behaviors (#3)
* MQE-233 Cleanup Rebranching and re-publish. * MQE-233 Cleanup and Rebranching fixes
1 parent c20770f commit c285653

File tree

2 files changed

+76
-5
lines changed

2 files changed

+76
-5
lines changed

src/Magento/AcceptanceTestFramework/Test/Objects/ActionObject.php

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22

33
namespace Magento\AcceptanceTestFramework\Test\Objects;
44

5+
use Magento\AcceptanceTestFramework\PageObject\Page\Page;
6+
use Magento\AcceptanceTestFramework\PageObject\Section\Section;
7+
58
class ActionObject
69
{
710
private $mergeKey;
811
private $type;
912
private $actionAttributes = [];
1013
private $linkedAction;
1114
private $orderOffset = 0;
15+
private $resolvedCustomAttributes = [];
16+
private $timeout;
1217

1318
public function __construct($mergeKey, $type, $actionAttributes, $linkedAction = null, $order = 0)
1419
{
@@ -37,11 +42,13 @@ public function getType()
3742
* the tag <seeNumberOfElements selector="value1" expected="value2" mergeKey=""/> has 3 attributes,
3843
* only 2 of which are specific to the 'seeNumberOfElements' tag. As a result this function would
3944
* return the array would return [selector => value1, expected => value2]
45+
* The returned array is also the merged result of the resolved and normal actions, giving
46+
* priority to the resolved actions (resolved selector instead of section.element, etc).
4047
* @return array
4148
*/
4249
public function getCustomActionAttributes()
4350
{
44-
return $this->actionAttributes;
51+
return array_merge($this->actionAttributes, $this->resolvedCustomAttributes);
4552
}
4653

4754
public function getLinkedAction()
@@ -53,4 +60,46 @@ public function getOrderOffset()
5360
{
5461
return $this->orderOffset;
5562
}
56-
}
63+
64+
public function getTimeout()
65+
{
66+
return $this->timeout;
67+
}
68+
69+
/**
70+
* Resolves all references
71+
*/
72+
public function resolveReferences()
73+
{
74+
if(empty($this->resolvedCustomAttributes)){
75+
$this->resolveSelectorReference();
76+
$this->resolveUrlReference();
77+
}
78+
}
79+
80+
/**
81+
* Checks if selector is an attribute, and if the selector refers to a defined section.
82+
* If not, assume selector is CSS/xpath literal and leave it be.
83+
*/
84+
private function resolveSelectorReference()
85+
{
86+
if(array_key_exists('selector', $this->actionAttributes)
87+
and array_key_exists(strtok($this->actionAttributes['selector'], '.'), Section::getSection()) ) {
88+
list($section, $element) = explode('.', $this->actionAttributes['selector']);
89+
$this->resolvedCustomAttributes['selector'] = Section::getElementLocator($section, $element);
90+
$this->timeout = Section::getElementTimeOut($section, $element);
91+
}
92+
}
93+
94+
/**
95+
* Checks if url is an attribute, and if the url given is a defined page.
96+
* If not, assume url is literal and leave it be.
97+
*/
98+
private function resolveUrlReference()
99+
{
100+
if (array_key_exists('url', $this->actionAttributes)
101+
and array_key_exists($this->actionAttributes['url'], Page::getPage())) {
102+
$this->resolvedCustomAttributes['url'] = $_ENV['MAGENTO_BASE_URL'] . Page::getPageUrl($this->actionAttributes['url']);
103+
}
104+
}
105+
}

src/Magento/AcceptanceTestFramework/Test/Objects/TestObject.php

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public function getAnnotations()
3939
public function getOrderedActions()
4040
{
4141
$this->mergeActions();
42+
$this->insertWaits();
4243
return $this->orderedSteps;
4344
}
4445

@@ -50,6 +51,7 @@ public function getOrderedActions()
5051
private function sortActions()
5152
{
5253
foreach ($this->parsedSteps as $parsedStep) {
54+
$parsedStep->resolveReferences();
5355
if ($parsedStep->getLinkedAction()) {
5456
$this->stepsToMerge[$parsedStep->getMergeKey()] = $parsedStep;
5557
} else {
@@ -98,10 +100,30 @@ private function mergeAction($stepToMerge)
98100
$this->mergeAction($this->stepsToMerge[$linkedStep]);
99101
}
100102

101-
$position = array_search($linkedStep, array_keys($this->orderedSteps)) + $stepToMerge->getOrderOffset();
103+
$this->insertStep($stepToMerge);
104+
}
105+
106+
/**
107+
* Runs through the prepared orderedSteps and calls insertWait if a step requires a wait after it.
108+
* @return void
109+
*/
110+
private function insertWaits()
111+
{
112+
foreach ($this->orderedSteps as $step) {
113+
114+
if ($step->getTimeout()) {
115+
$waitStepAttributes = array('timeout' => $step->getTimeout());
116+
$waitStep = new ActionObject($step->getMergeKey() . 'WaitForPageLoad', 'waitForPageLoad', $waitStepAttributes, $step->getMergeKey(), 'after');
117+
$this->insertStep($waitStep);
118+
}
119+
}
120+
}
121+
122+
private function insertStep($stepToMerge)
123+
{
124+
$position = array_search($stepToMerge->getLinkedAction(), array_keys($this->orderedSteps)) + $stepToMerge->getOrderOffset();
102125
$previous_items = array_slice($this->orderedSteps, 0, $position, true);
103126
$next_items = array_slice($this->orderedSteps, $position, null, true);
104127
$this->orderedSteps = $previous_items + [$stepToMerge->getMergeKey() => $stepToMerge] + $next_items;
105128
}
106-
107-
}
129+
}

0 commit comments

Comments
 (0)