Skip to content

Commit 4b3c37a

Browse files
committed
MQE-230: Update test schema and object model to reference data dependencies
1 parent c285653 commit 4b3c37a

File tree

5 files changed

+158
-20
lines changed

5 files changed

+158
-20
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
MAGENTO_ADMIN_USERNAME=admin
22
MAGENTO_ADMIN_PASSWORD=test123
3+
MAGENTO_BASE_URL=http://127.0.0.1:32769/
34
TESTS_BP=/Users/dev/somepath/magento2ce-acceptance-tests
45
FW_BP=/Users/dev/somepath/magento2-acceptance-test-framework

etc/di.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@
221221
<argument name="idAttributes" xsi:type="array">
222222
<item name="/config/cest" xsi:type="string">name</item>
223223
<item name="/config/cest/test" xsi:type="string">name</item>
224-
<item name="/config/cest/test/(acceptPopup|amOnPage|appendField|assertArraySubset|attachFile|cancelPopup|checkOption|click|clickWithLeftButton|clickWithRightButton|closeTab|dontSee|dontSeeCheckboxIsChecked|dontSeeCookie|dontSeeCurrentUrlEquals|dontSeeCurrentUrlMatches|dontSeeElement|dontSeeElementInDOM|dontSeeInCurrentUrl|dontSeeInField|dontSeeInPageSource|dontSeeInSource|dontSeeInTitle|dontSeeLink|dontSeeOptionIsSelected|doubleClick|dragAndDrop|executeJS|fillField|grabAttributeFrom|grabCookie|grabFromCurrentUrl|grabMultiple|grabPageSource|grabTextFrom|grabValueFrom|loadSessionSnapshot|makeScreenshot|maximizeWindow|moveBack|moveForward|moveMouseOver|openNewTab|pauseExecution|performOn|pressKey|reloadPage|resetCookie|resizeWindow|scrollTo|see|seeCheckboxIsChecked|seeCookie|seeCurrentUrlEquals|seeCurrentUrlMatches|seeElement|seeElementInDOM|seeInCurrentUrl|seeInField|seeInFormFields|seeInPageSource|seeInPopup|seeInSource|seeInTitle|seeLink|seeNumberOfElements|seeOptionIsSelected|selectOption|setCookie|switchToIFrame|switchToNextTab|switchToPreviousTab|switchToWindow|typeInPopup|uncheckOption|unselectOption|wait|waitForElement|waitForElementChange|waitForElementNotVisible|waitForElementVisible|waitForJS|waitForText)" xsi:type="string">mergeKey</item>
224+
<item name="/config/cest/test/(acceptPopup|amOnPage|appendField|assertArraySubset|attachFile|cancelPopup|checkOption|click|clickWithLeftButton|clickWithRightButton|closeTab|createData|deleteData|dontSee|dontSeeCheckboxIsChecked|dontSeeCookie|dontSeeCurrentUrlEquals|dontSeeCurrentUrlMatches|dontSeeElement|dontSeeElementInDOM|dontSeeInCurrentUrl|dontSeeInField|dontSeeInPageSource|dontSeeInSource|dontSeeInTitle|dontSeeLink|dontSeeOptionIsSelected|doubleClick|dragAndDrop|executeJS|fillField|grabAttributeFrom|grabCookie|grabFromCurrentUrl|grabMultiple|grabPageSource|grabTextFrom|grabValueFrom|loadSessionSnapshot|makeScreenshot|maximizeWindow|moveBack|moveForward|moveMouseOver|openNewTab|pauseExecution|performOn|pressKey|reloadPage|resetCookie|resizeWindow|scrollTo|see|seeCheckboxIsChecked|seeCookie|seeCurrentUrlEquals|seeCurrentUrlMatches|seeElement|seeElementInDOM|seeInCurrentUrl|seeInField|seeInFormFields|seeInPageSource|seeInPopup|seeInSource|seeInTitle|seeLink|seeNumberOfElements|seeOptionIsSelected|selectOption|setCookie|switchToIFrame|switchToNextTab|switchToPreviousTab|switchToWindow|typeInPopup|uncheckOption|unselectOption|wait|waitForElement|waitForElementChange|waitForElementNotVisible|waitForElementVisible|waitForJS|waitForText)" xsi:type="string">mergeKey</item>
225225
</argument>
226226
<argument name="fileName" xsi:type="string">*Cest.xml</argument>
227227
<argument name="defaultScope" xsi:type="string">Cest</argument>
@@ -231,7 +231,7 @@
231231
<virtualType name="Magento\AcceptanceTestFramework\Test\Config\Dom\ArrayNodeConfig" type="Magento\AcceptanceTestFramework\Config\Dom\ArrayNodeConfig">
232232
<arguments>
233233
<argument name="assocArrayAttributes" xsi:type="array">
234-
<item name="/config/cest/test/(acceptPopup|amOnPage|appendField|assertArraySubset|attachFile|cancelPopup|checkOption|click|clickWithLeftButton|clickWithRightButton|closeTab|dontSee|dontSeeCheckboxIsChecked|dontSeeCookie|dontSeeCurrentUrlEquals|dontSeeCurrentUrlMatches|dontSeeElement|dontSeeElementInDOM|dontSeeInCurrentUrl|dontSeeInField|dontSeeInPageSource|dontSeeInSource|dontSeeInTitle|dontSeeLink|dontSeeOptionIsSelected|doubleClick|dragAndDrop|executeJS|fillField|grabAttributeFrom|grabCookie|grabFromCurrentUrl|grabMultiple|grabPageSource|grabTextFrom|grabValueFrom|loadSessionSnapshot|makeScreenshot|maximizeWindow|moveBack|moveForward|moveMouseOver|openNewTab|pauseExecution|performOn|pressKey|reloadPage|resetCookie|resizeWindow|scrollTo|see|seeCheckboxIsChecked|seeCookie|seeCurrentUrlEquals|seeCurrentUrlMatches|seeElement|seeElementInDOM|seeInCurrentUrl|seeInField|seeInFormFields|seeInPageSource|seeInPopup|seeInSource|seeInTitle|seeLink|seeNumberOfElements|seeOptionIsSelected|selectOption|setCookie|switchToIFrame|switchToNextTab|switchToPreviousTab|switchToWindow|typeInPopup|uncheckOption|unselectOption|wait|waitForElement|waitForElementChange|waitForElementNotVisible|waitForElementVisible|waitForJS|waitForText)" xsi:type="string">mergeKey</item>
234+
<item name="/config/cest/test/(acceptPopup|amOnPage|appendField|assertArraySubset|attachFile|cancelPopup|checkOption|click|clickWithLeftButton|clickWithRightButton|closeTab|createData|deleteData|dontSee|dontSeeCheckboxIsChecked|dontSeeCookie|dontSeeCurrentUrlEquals|dontSeeCurrentUrlMatches|dontSeeElement|dontSeeElementInDOM|dontSeeInCurrentUrl|dontSeeInField|dontSeeInPageSource|dontSeeInSource|dontSeeInTitle|dontSeeLink|dontSeeOptionIsSelected|doubleClick|dragAndDrop|executeJS|fillField|grabAttributeFrom|grabCookie|grabFromCurrentUrl|grabMultiple|grabPageSource|grabTextFrom|grabValueFrom|loadSessionSnapshot|makeScreenshot|maximizeWindow|moveBack|moveForward|moveMouseOver|openNewTab|pauseExecution|performOn|pressKey|reloadPage|resetCookie|resizeWindow|scrollTo|see|seeCheckboxIsChecked|seeCookie|seeCurrentUrlEquals|seeCurrentUrlMatches|seeElement|seeElementInDOM|seeInCurrentUrl|seeInField|seeInFormFields|seeInPageSource|seeInPopup|seeInSource|seeInTitle|seeLink|seeNumberOfElements|seeOptionIsSelected|selectOption|setCookie|switchToIFrame|switchToNextTab|switchToPreviousTab|switchToWindow|typeInPopup|uncheckOption|unselectOption|wait|waitForElement|waitForElementChange|waitForElementNotVisible|waitForElementVisible|waitForJS|waitForText)" xsi:type="string">mergeKey</item>
235235
<item name="/config/cest/test" xsi:type="string">name</item>
236236
<item name="/config/cest" xsi:type="string">name</item>
237237
</argument>

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

Lines changed: 130 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Magento\AcceptanceTestFramework\PageObject\Page\Page;
66
use Magento\AcceptanceTestFramework\PageObject\Section\Section;
7+
use Magento\AcceptanceTestFramework\DataGenerator\Managers\DataManager;
78

89
class ActionObject
910
{
@@ -67,39 +68,151 @@ public function getTimeout()
6768
}
6869

6970
/**
70-
* Resolves all references
71+
* Populate the resolved custom attributes array with lookup values for the following attributes:
72+
*
73+
* selector
74+
* url
75+
* userInput
76+
*
77+
* @return void
7178
*/
7279
public function resolveReferences()
7380
{
74-
if(empty($this->resolvedCustomAttributes)){
75-
$this->resolveSelectorReference();
81+
if (empty($this->resolvedCustomAttributes)) {
82+
$this->resolveSelectorReferenceAndTimeout();
7683
$this->resolveUrlReference();
84+
$this->resolveUserInputReference();
7785
}
7886
}
7987

8088
/**
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.
89+
* Look up the selector for SomeSectionName.ElementName and set it as the selector attribute in the
90+
* resolved custom attributes. Also set the timeout value.
91+
*
92+
* e.g. {{SomeSectionName.ElementName}} becomes #login-button
93+
*
94+
* @return void
8395
*/
84-
private function resolveSelectorReference()
96+
private function resolveSelectorReferenceAndTimeout()
8597
{
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);
98+
if (!array_key_exists('selector', $this->actionAttributes)) {
99+
return;
91100
}
101+
$selector = $this->actionAttributes['selector'];
102+
103+
$reference = $this->findReference($selector);
104+
if ($reference == null) {
105+
// Nothing to replace
106+
return;
107+
}
108+
109+
list($sectionName, $elementName) = $this->stripAndSplitReference($reference);
110+
$section = Section::getSection($sectionName);
111+
if ($section == null) {
112+
// Bad section reference
113+
return;
114+
}
115+
$replacement = Section::getElementLocator($sectionName, $elementName);
116+
117+
$this->resolvedCustomAttributes['selector'] = str_replace($reference, $replacement, $selector);
118+
$this->timeout = Section::getElementTimeOut($sectionName, $elementName);
92119
}
93120

94121
/**
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.
122+
* Look up the url for SomePageName and set it, with MAGENTO_BASE_URL prepended, as the url attribute in the
123+
* resolved custom attributes.
124+
*
125+
* e.g. {{SomePageName}} becomes http://localhost:76543/some/url
126+
*
127+
* @return void
97128
*/
98129
private function resolveUrlReference()
99130
{
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']);
131+
if (!array_key_exists('url', $this->actionAttributes)) {
132+
return;
133+
}
134+
$url = $this->actionAttributes['url'];
135+
136+
$reference = $this->findReference($url);
137+
if ($reference == null) {
138+
// Nothing to replace
139+
return;
140+
}
141+
142+
list($pageName) = $this->stripAndSplitReference($reference);
143+
$page = Page::getPage($pageName);
144+
if ($page == null) {
145+
// Bad page reference
146+
return;
147+
}
148+
$replacement = $_ENV['MAGENTO_BASE_URL'] . Page::getPageUrl($pageName);
149+
150+
$this->resolvedCustomAttributes['url'] = str_replace($reference, $replacement, $url);
151+
}
152+
153+
154+
/**
155+
* Look up the value for EntityDataObjectName.Key and set it as the userInput attribute in the resolved custom
156+
* attributes.
157+
*
158+
* e.g. {{CustomerEntityFoo.FirstName}} becomes Jerry
159+
*
160+
* @return void
161+
*/
162+
private function resolveUserInputReference()
163+
{
164+
if (!array_key_exists('userInput', $this->actionAttributes)) {
165+
return;
166+
}
167+
$userInput = $this->actionAttributes['userInput'];
168+
169+
$reference = $this->findReference($userInput);
170+
if ($reference == null) {
171+
// Nothing to replace
172+
return;
173+
}
174+
175+
list($entityName, $entityKey) = $this->stripAndSplitReference($userInput);
176+
$entityObj = DataManager::getInstance()->getEntity($entityName);
177+
if ($entityObj == null) {
178+
// Bad entity reference
179+
return;
180+
}
181+
182+
$replacement = $entityObj->getDataByName($entityKey);
183+
if ($replacement == null) {
184+
// Bad entity.key reference
185+
return;
186+
}
187+
188+
$this->resolvedCustomAttributes['userInput'] = str_replace($reference, $replacement, $userInput);
189+
}
190+
191+
/**
192+
* Return an array containing the name (before the period) and key (after the period) in a {{reference.foo}}.
193+
*
194+
* @param string $reference
195+
* @return string[] The name and key that is referenced.
196+
*/
197+
private function stripAndSplitReference($reference)
198+
{
199+
$strippedReference = str_replace('}}', '', str_replace('{{', '', $reference));
200+
return explode('.', $strippedReference);
201+
}
202+
203+
/**
204+
* Return a {{reference.foo}} if it exists in the string.
205+
*
206+
* @param string $str
207+
* @return string|null
208+
*/
209+
private function findReference($str)
210+
{
211+
preg_match('/{{[\w.]+}}/', $str, $matches);
212+
if (empty($matches)) {
213+
return null;
214+
} else {
215+
return $matches[0];
103216
}
104217
}
105-
}
218+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,4 @@ private function insertStep($stepToMerge)
126126
$next_items = array_slice($this->orderedSteps, $position, null, true);
127127
$this->orderedSteps = $previous_items + [$stepToMerge->getMergeKey() => $stepToMerge] + $next_items;
128128
}
129-
}
129+
}

src/Magento/AcceptanceTestFramework/Test/etc/testSchema.xsd

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
<xs:element type="clickWithLeftButtonType" name="clickWithLeftButton" minOccurs="0" maxOccurs="unbounded"/>
5454
<xs:element type="clickWithRightButtonType" name="clickWithRightButton" minOccurs="0" maxOccurs="unbounded"/>
5555
<xs:element type="closeTabType" name="closeTab" minOccurs="0" maxOccurs="unbounded"/>
56+
<xs:element type="createDataType" name="createData" minOccurs="0" maxOccurs="unbounded"/>
57+
<xs:element type="deleteDataType" name="deleteData" minOccurs="0" maxOccurs="unbounded"/>
5658
<xs:element type="dontSeeType" name="dontSee" minOccurs="0" maxOccurs="unbounded"/>
5759
<xs:element type="dontSeeCheckboxIsCheckedType" name="dontSeeCheckboxIsChecked" minOccurs="0" maxOccurs="unbounded"/>
5860
<xs:element type="dontSeeCookieType" name="dontSeeCookie" minOccurs="0" maxOccurs="unbounded"/>
@@ -276,6 +278,28 @@
276278
</xs:extension>
277279
</xs:simpleContent>
278280
</xs:complexType>
281+
<xs:complexType name="createDataType">
282+
<xs:simpleContent>
283+
<xs:extension base="xs:string">
284+
<xs:attribute type="xs:string" name="entity" use="required"/>
285+
<xs:attribute type="xs:string" name="mergeKey" use="required"/>
286+
<xs:attribute type="xs:boolean" name="remove" default="false"/>
287+
<xs:attribute type="xs:string" name="before"/>
288+
<xs:attribute type="xs:string" name="after"/>
289+
</xs:extension>
290+
</xs:simpleContent>
291+
</xs:complexType>
292+
<xs:complexType name="deleteDataType">
293+
<xs:simpleContent>
294+
<xs:extension base="xs:string">
295+
<xs:attribute type="xs:string" name="createDataKey" use="required"/>
296+
<xs:attribute type="xs:string" name="mergeKey" use="required"/>
297+
<xs:attribute type="xs:boolean" name="remove" default="false"/>
298+
<xs:attribute type="xs:string" name="before"/>
299+
<xs:attribute type="xs:string" name="after"/>
300+
</xs:extension>
301+
</xs:simpleContent>
302+
</xs:complexType>
279303
<xs:complexType name="dontSeeType">
280304
<xs:simpleContent>
281305
<xs:extension base="xs:string">

0 commit comments

Comments
 (0)