Skip to content

Commit 933bb90

Browse files
authored
MQE-593: Return variables should not have their own attributes
- Edited schema to remove variable and returnVariable - Format for variable reference in test is now "{$variable}". - Actions that grab or return now always assign a variable with given stepkey for referencing.
1 parent d224769 commit 933bb90

File tree

9 files changed

+170
-158
lines changed

9 files changed

+170
-158
lines changed

dev/tests/verification/Resources/AssertCest.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class AssertCest
4343
$UniquePerson = DataObjectHandler::getInstance()->getObject("UniquePerson");
4444
$createData2 = new DataPersistenceHandler($UniquePerson);
4545
$createData2->createEntity();
46-
$text = $I->grabTextFrom(".copyright>span");
46+
$grabTextFrom1 = $I->grabTextFrom(".copyright>span");
4747
$I->comment("asserts without variable replacement");
4848
$I->assertArrayHasKey("apple", ['orange' => 2, 'apple' => 1], "pass");
4949
$I->assertArrayNotHasKey("kiwi", ['orange' => 2, 'apple' => 1], "pass");

dev/tests/verification/Resources/BasicFunctionalCest.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class BasicFunctionalCest
4646
*/
4747
public function BasicFunctionalTest(AcceptanceTester $I)
4848
{
49-
$someVar = $I->grabValueFrom();
49+
$someVarDefinition = $I->grabValueFrom();
5050
$I->acceptPopup();
5151
$I->amOnPage("/test/url");
5252
$I->appendField(".functionalTestSelector", $someVar);
@@ -77,12 +77,12 @@ class BasicFunctionalCest
7777
$I->executeJS("someJSFunction");
7878
$I->fillField(".functionalTestSelector", "someInput");
7979
$I->fillField(".functionalTestSelector", "0");
80-
$grabAttributeVar = $I->grabAttributeFrom(".functionalTestSelector", "someInput");
81-
$grabCookieVar = $I->grabCookie("grabCookieInput", ['domain' => 'www.google.com']);
82-
$grabUrlVar = $I->grabFromCurrentUrl("/grabCurrentUrl");
83-
$grabMultipleVar = $I->grabMultiple(".functionalTestSelector");
84-
$I->grabTextFrom(".functionalTestSelector");
85-
$grabValueVar = $I->grabValueFrom(".functionalTestSelector");
80+
$grabAttributeFromKey1 = $I->grabAttributeFrom(".functionalTestSelector", "someInput");
81+
$grabCookieKey1 = $I->grabCookie("grabCookieInput", ['domain' => 'www.google.com']);
82+
$grabFromCurrentUrlKey1 = $I->grabFromCurrentUrl("/grabCurrentUrl");
83+
$grabMultipleKey1 = $I->grabMultiple(".functionalTestSelector");
84+
$grabTextFromKey1 = $I->grabTextFrom(".functionalTestSelector");
85+
$grabValueFromKey1 = $I->grabValueFrom(".functionalTestSelector");
8686
$I->makeScreenshot("screenShotInput");
8787
$I->maximizeWindow();
8888
$I->moveBack();

dev/tests/verification/Resources/SectionReplacementCest.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,12 @@ class SectionReplacementCest
5353
$I->click("#" . $createdData->getCreatedDataByName('firstname') . " .stringLiteral2");
5454
$I->click("#" . $createdData->getCreatedDataByName('firstname') . "-stringLiteral2 .stringLiteral3");
5555
$I->click("#" . $createdData->getCreatedDataByName('firstname') . "-stringLiteral2 ." . $createdData->getCreatedDataByName('firstname') . " [stringLiteral3]");
56+
$I->click("#element .{$data}");
57+
$I->click("#{$data1} .{$data2}");
58+
$I->click("#{$data1}-{$data2} .{$data3}");
59+
$I->click("#John-Doe .John [Tiberius]");
5660
$I->click("#stringLiteral1-" . $createdData->getCreatedDataByName('firstname') . " .John");
61+
$I->click("#stringLiteral1-" . $createdData->getCreatedDataByName('firstname') . " .{$data}");
5762
$I->click("#stringLiteral1-" . $createdData->getCreatedDataByName('firstname') . " .".msq("uniqueData")."John");
5863
$I->click("#stringLiteral1-" . $createdData->getCreatedDataByName('firstname') . " .Doe".msq("uniqueData"));
5964
}

dev/tests/verification/TestModule/Cest/AssertCest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
</before>
1515
<test name="AssertTest">
1616
<createData entity="UniquePerson" stepKey="createData2"/>
17-
<grabTextFrom returnVariable="text" selector=".copyright>span" stepKey="grabTextFrom1"/>
17+
<grabTextFrom selector=".copyright>span" stepKey="grabTextFrom1"/>
1818
<!-- asserts without variable replacement -->
1919
<comment stepKey="c1" userInput="asserts without variable replacement"/>
2020
<assertArrayHasKey stepKey="assertArrayHasKey" expected="apple" expectedType="string" actual="['orange' => 2, 'apple' => 1]" actualType="const" message="pass"/>

dev/tests/verification/TestModule/Cest/BasicFunctionalCest.xml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@
3030
<features value="Hardcoded Functional Test"/>
3131
<stories value="MQE-425"/>
3232
</annotations>
33-
<grabValueFrom returnVariable="someVar" stepKey="someVarDefinition"/>
33+
<grabValueFrom stepKey="someVarDefinition"/>
3434
<acceptPopup stepKey="acceptPopupKey1"/>
3535
<amOnPage stepKey="amOnPageKey1" url="/test/url"/>
36-
<appendField variable="someVar" selector=".functionalTestSelector" stepKey="appendFieldKey1" />
36+
<appendField userInput="{$someVar}" selector=".functionalTestSelector" stepKey="appendFieldKey1" />
3737
<attachFile userInput="testFileAttachment" selector=".functionalTestSelector" stepKey="attachFileKey1" />
3838
<cancelPopup stepKey="cancelPopupKey1"/>
3939
<checkOption selector=".functionalTestSelector" stepKey="checkOptionKey1"/>
@@ -50,7 +50,7 @@
5050
<dontSeeElement selector=".functionalTestSelector" stepKey="dontSeeElementKey1"/>
5151
<dontSeeElementInDOM selector=".functionalTestSelector" stepKey="dontSeeElementInDOMKey1"/>
5252
<dontSeeInCurrentUrl url="/functionalUrl" stepKey="dontSeeInCurrentUrlKey1"/>
53-
<dontSeeInField variable="someVar" selector=".functionalTestSelector" stepKey="dontSeeInFieldKey1" />
53+
<dontSeeInField userInput="{$someVar}" selector=".functionalTestSelector" stepKey="dontSeeInFieldKey1" />
5454
<dontSeeInPageSource userInput="someInput" stepKey="dontSeeInPageSourceKey1"/>
5555
<dontSeeInSource html="&quot;&lt;myHtmlHere&gt;&quot;" stepKey="dontSeeInSourceKey1"/>
5656
<dontSeeInTitle userInput="someInput" stepKey="dontSeeInTitleKey1"/>
@@ -61,12 +61,12 @@
6161
<executeJS function="someJSFunction" stepKey="executeJSKey1"/>
6262
<fillField selector=".functionalTestSelector" userInput="someInput" stepKey="fillFieldKey1" />
6363
<fillField selector=".functionalTestSelector" userInput="0" stepKey="fillFieldKey2" />
64-
<grabAttributeFrom returnVariable="grabAttributeVar" selector=".functionalTestSelector" userInput="someInput" stepKey="grabAttributeFromKey1" />
65-
<grabCookie returnVariable="grabCookieVar" userInput="grabCookieInput" parameterArray="['domain' => 'www.google.com']" stepKey="grabCookieKey1" />
66-
<grabFromCurrentUrl returnVariable="grabUrlVar" url="/grabCurrentUrl" stepKey="grabFromCurrentUrlKey1" />
67-
<grabMultiple selector=".functionalTestSelector" returnVariable="grabMultipleVar" stepKey="grabMultipleKey1" />
68-
<grabTextFrom returnVariable="" selector=".functionalTestSelector" stepKey="grabTextFromKey1" />
69-
<grabValueFrom selector=".functionalTestSelector" returnVariable="grabValueVar" stepKey="grabValueFromKey1" />
64+
<grabAttributeFrom selector=".functionalTestSelector" userInput="someInput" stepKey="grabAttributeFromKey1" />
65+
<grabCookie userInput="grabCookieInput" parameterArray="['domain' => 'www.google.com']" stepKey="grabCookieKey1" />
66+
<grabFromCurrentUrl url="/grabCurrentUrl" stepKey="grabFromCurrentUrlKey1" />
67+
<grabMultiple selector=".functionalTestSelector" stepKey="grabMultipleKey1" />
68+
<grabTextFrom selector=".functionalTestSelector" stepKey="grabTextFromKey1" />
69+
<grabValueFrom selector=".functionalTestSelector" stepKey="grabValueFromKey1" />
7070
<makeScreenshot userInput="screenShotInput" stepKey="makeScreenshotKey1"/>
7171
<maximizeWindow stepKey="maximizeWindowKey1"/>
7272
<moveBack stepKey="moveBackKey1"/>
@@ -96,7 +96,7 @@
9696
<seeInSource html="&quot;&lt;myHtmlHere&gt;&quot;" stepKey="seeInSourceKey1"/>
9797
<seeInTitle userInput="someInput" stepKey="seeInTitleKey1"/>
9898
<seeLink userInput="someInput" url="/functionalUrl" stepKey="seeLinkKey1" />
99-
<seeNumberOfElements variable="someVar" selector=".functionalTestSelector" stepKey="seeNumberOfElementsKey1"/>
99+
<seeNumberOfElements userInput="{$someVar}" selector=".functionalTestSelector" stepKey="seeNumberOfElementsKey1"/>
100100
<seeOptionIsSelected selector=".functionalTestSelector" userInput="someInput" stepKey="seeOptionIsSelectedKey1" />
101101
<selectOption selector=".functionalTestSelector" stepKey="selectOptionKey1"/>
102102
<setCookie value="someCookieValue" userInput="someInput" stepKey="setCookieKey1" />

dev/tests/verification/TestModule/Cest/SectionReplacementCest.xml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
<click stepKey="selectorReplaceThreeParam" selector="{{SampleSection.threeParamElement('stringLiteral1', 'stringLiteral2', 'stringLiteral3')}}"/>
1919
<click stepKey="selectorReplaceThreeParamOneDupe" selector="{{SampleSection.threeOneDuplicateParamElement('stringLiteral1', 'stringLiteral2', 'stringLiteral3')}}"/>
2020

21-
2221
<click stepKey="selectorReplaceOneParamDataRef" selector="{{SampleSection.oneParamElement(simpleData.firstname)}}"/>
2322
<click stepKey="selectorReplaceTwoParamDataRef" selector="{{SampleSection.twoParamElement(simpleData.firstname, simpleData.lastname)}}"/>
2423
<click stepKey="selectorReplaceThreeParamDataRef" selector="{{SampleSection.threeParamElement(simpleData.firstname, simpleData.lastname, simpleData.middlename)}}"/>
@@ -40,7 +39,14 @@
4039
<click stepKey="selectorReplaceThreeParamPersisted" selector="{{SampleSection.threeParamElement($createdData.firstname$, 'stringLiteral2', 'stringLiteral3')}}"/>
4140
<click stepKey="selectorReplaceThreeParamOneDupePersisted" selector="{{SampleSection.threeOneDuplicateParamElement($createdData.firstname$, 'stringLiteral2', 'stringLiteral3')}}"/>
4241

43-
<click stepKey="selectorReplaceThreeParamMixed" selector="{{SampleSection.threeParamElement('stringLiteral1', $createdData.firstname$, simpleData.firstname)}}"/>
42+
<click stepKey="selectorReplaceOneParamVariable" selector="{{SampleSection.oneParamElement({$data})}}"/>
43+
<click stepKey="selectorReplaceTwoParamVariable" selector="{{SampleSection.twoParamElement({$data1}, {$data2})}}"/>
44+
<click stepKey="selectorReplaceThreeParamVariable" selector="{{SampleSection.threeParamElement({$data1}, {$data2}, {$data3})}}"/>
45+
<click stepKey="selectorReplaceThreeParamVariableOneDupe" selector="{{SampleSection.threeOneDuplicateParamElement(simpleData.firstname, simpleData.lastname, simpleData.middlename)}}"/>
46+
47+
48+
<click stepKey="selectorReplaceThreeParamMixed1" selector="{{SampleSection.threeParamElement('stringLiteral1', $createdData.firstname$, simpleData.firstname)}}"/>
49+
<click stepKey="selectorReplaceThreeParamMixed2" selector="{{SampleSection.threeParamElement('stringLiteral1', $createdData.firstname$, {$data})}}"/>
4450
<click stepKey="selectorReplaceThreeParamMixedMSQPrefix" selector="{{SampleSection.threeParamElement('stringLiteral1', $createdData.firstname$, uniqueData.firstname)}}"/>
4551
<click stepKey="selectorReplaceThreeParamMixedMSQSuffix" selector="{{SampleSection.threeParamElement('stringLiteral1', $createdData.firstname$, uniqueData.lastname)}}"/>
4652
</test>

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

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class ActionObject
2727
const ACTION_ATTRIBUTE_SELECTOR = 'selector';
2828
const ACTION_ATTRIBUTE_VARIABLE_REGEX_PARAMETER = '/\(.+\)/';
2929
const ACTION_ATTRIBUTE_VARIABLE_REGEX_PATTERN = '/{{[\w.\[\]()\',$ ]+}}/';
30+
const ACTION_ATTRIBUTE_VARIABLE_REGEX_PATTERN_WITH_PARAMS= '/{{[\w]+\.[\w]+\([\w ,.\'{$}]+\)}}/';
3031

3132
/**
3233
* The unique identifier for the action
@@ -314,7 +315,10 @@ private function stripAndReturnParameters($reference)
314315
*/
315316
private function findAndReplaceReferences($objectHandler, $inputString)
316317
{
317-
preg_match_all(ActionObject::ACTION_ATTRIBUTE_VARIABLE_REGEX_PATTERN, $inputString, $matches);
318+
//look for parameter area, if so use different regex
319+
$regex = $this->resolveRegexPatternForReference($inputString);
320+
321+
preg_match_all($regex, $inputString, $matches);
318322

319323
$outputString = $inputString;
320324

@@ -357,6 +361,20 @@ private function findAndReplaceReferences($objectHandler, $inputString)
357361
return $outputString;
358362
}
359363

364+
/**
365+
* Determines whether the given $inputString has (params), and returns the appropriate regex for use in matching.
366+
* @param string $inputString
367+
* @return string
368+
*/
369+
private function resolveRegexPatternForReference($inputString)
370+
{
371+
if (preg_match(ActionObject::ACTION_ATTRIBUTE_VARIABLE_REGEX_PARAMETER, $inputString) === 1) {
372+
return ActionObject::ACTION_ATTRIBUTE_VARIABLE_REGEX_PATTERN_WITH_PARAMS;
373+
} else {
374+
return ActionObject::ACTION_ATTRIBUTE_VARIABLE_REGEX_PATTERN;
375+
}
376+
}
377+
360378
/**
361379
* Gets the object's dataByName with given $match, differentiating behavior between <array> and <data> nodes.
362380
* @param string $obj
@@ -430,13 +448,17 @@ private function matchParameterReferences($reference, $parameters)
430448

431449
//Attempt to Resolve {{data}} references to actual output. Trim parameter for whitespace before processing it.
432450
//If regex matched it means that it's either a 'StringLiteral' or $key.data$/$$key.data$$ reference.
451+
//Elseif regex match for {$data}
433452
//Else assume it's a normal {{data.key}} reference and recurse through findAndReplace
434453
$resolvedParameters = [];
435454
foreach ($parameters as $parameter) {
436455
$parameter = trim($parameter);
437-
preg_match_all("/[$'][\w\D]+[$']/", $parameter, $match);
438-
if (!empty($match[0])) {
456+
preg_match_all("/[$'][\w\D]+[$']/", $parameter, $stringOrPersistedMatch);
457+
preg_match_all('/{\$[a-z][a-zA-Z\d]+}/', $parameter, $variableMatch);
458+
if (!empty($stringOrPersistedMatch[0])) {
439459
$resolvedParameters[] = ltrim(rtrim($parameter, "'"), "'");
460+
} elseif (!empty($variableMatch[0])) {
461+
$resolvedParameters[] = $parameter;
440462
} else {
441463
$resolvedParameters[] = $this->findAndReplaceReferences(
442464
DataObjectHandler::getInstance(),

0 commit comments

Comments
 (0)