Skip to content

Commit dd9f789

Browse files
authored
MQE-1083: Acceptance tester should be able to enter future/current dates in the date field
- added generateDate action, takes date and format and saves it to a variable
1 parent 95062cf commit dd9f789

File tree

6 files changed

+70
-2
lines changed

6 files changed

+70
-2
lines changed

dev/tests/verification/Resources/BasicFunctionalTest.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ class BasicFunctionalTestCest
9999
$executeJSKey1 = $I->executeJS("someJSFunction");
100100
$I->fillField(".functionalTestSelector", "someInput");
101101
$I->fillField(".functionalTestSelector", "0");
102+
$date = new \DateTime();
103+
$date->setTimestamp(strtotime("Now"));
104+
$date->setTimezone(new \DateTimeZone("America/Los_Angeles"));
105+
$generateDateKey = $date->format("H:i:s");
102106
$grabAttributeFromKey1 = $I->grabAttributeFrom(".functionalTestSelector", "someInput");
103107
$grabCookieKey1 = $I->grabCookie("grabCookieInput", ['domain' => 'www.google.com']);
104108
$grabFromCurrentUrlKey1 = $I->grabFromCurrentUrl("/grabCurrentUrl");

dev/tests/verification/TestModule/Test/BasicFunctionalTest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
<executeJS function="someJSFunction" stepKey="executeJSKey1"/>
6161
<fillField selector=".functionalTestSelector" userInput="someInput" stepKey="fillFieldKey1" />
6262
<fillField selector=".functionalTestSelector" userInput="0" stepKey="fillFieldKey2" />
63+
<generateDate date="Now" format="H:i:s" stepKey="generateDateKey"/>
6364
<grabAttributeFrom selector=".functionalTestSelector" userInput="someInput" stepKey="grabAttributeFromKey1" />
6465
<grabCookie userInput="grabCookieInput" parameterArray="['domain' => 'www.google.com']" stepKey="grabCookieKey1" />
6566
<grabFromCurrentUrl regex="/grabCurrentUrl" stepKey="grabFromCurrentUrlKey1" />

etc/di.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<!-- Entity value gets replaced in Dom.php before reading $xml -->
1010
<!DOCTYPE config [
11-
<!ENTITY commonTestActions "acceptPopup|actionGroup|amOnPage|amOnUrl|amOnSubdomain|appendField|assertArrayIsSorted|assertArraySubset|assertElementContainsAttribute|attachFile|cancelPopup|checkOption|clearField|click|clickWithLeftButton|clickWithRightButton|closeAdminNotification|closeTab|comment|conditionalClick|createData|deleteData|updateData|getData|dontSee|dontSeeJsError|dontSeeCheckboxIsChecked|dontSeeCookie|dontSeeCurrentUrlEquals|dontSeeCurrentUrlMatches|dontSeeElement|dontSeeElementInDOM|dontSeeInCurrentUrl|dontSeeInField|dontSeeInFormFields|dontSeeInPageSource|dontSeeInSource|dontSeeInTitle|dontSeeLink|dontSeeOptionIsSelected|doubleClick|dragAndDrop|entity|executeJS|executeInSelenium|fillField|formatMoney|grabAttributeFrom|grabCookie|grabFromCurrentUrl|grabMultiple|grabPageSource|grabTextFrom|grabValueFrom|loadSessionSnapshot|loginAsAdmin|magentoCLI|makeScreenshot|maximizeWindow|moveBack|moveForward|moveMouseOver|mSetLocale|mResetLocale|openNewTab|pauseExecution|parseFloat|performOn|pressKey|reloadPage|resetCookie|submitForm|resizeWindow|saveSessionSnapshot|scrollTo|scrollToTopOfPage|searchAndMultiSelectOption|see|seeCheckboxIsChecked|seeCookie|seeCurrentUrlEquals|seeCurrentUrlMatches|seeElement|seeElementInDOM|seeInCurrentUrl|seeInField|seeInFormFields|seeInPageSource|seeInPopup|seeInSource|seeInTitle|seeLink|seeNumberOfElements|seeOptionIsSelected|selectOption|setCookie|submitForm|switchToIFrame|switchToNextTab|switchToPreviousTab|switchToWindow|typeInPopup|uncheckOption|unselectOption|wait|waitForAjaxLoad|waitForElement|waitForElementChange|waitForElementNotVisible|waitForElementVisible|waitForJS|waitForLoadingMaskToDisappear|waitForPageLoad|waitForText|assertArrayHasKey|assertArrayNotHasKey|assertArraySubset|assertContains|assertCount|assertEmpty|assertEquals|assertFalse|assertFileExists|assertFileNotExists|assertGreaterOrEquals|assertGreaterThan|assertGreaterThanOrEqual|assertInstanceOf|assertInternalType|assertIsEmpty|assertLessOrEquals|assertLessThan|assertLessThanOrEqual|assertNotContains|assertNotEmpty|assertNotEquals|assertNotInstanceOf|assertNotNull|assertNotRegExp|assertNotSame|assertNull|assertRegExp|assertSame|assertStringStartsNotWith|assertStringStartsWith|assertTrue|expectException|fail|dontSeeFullUrlEquals|dontSee|dontSeeFullUrlMatches|dontSeeInFullUrl|seeFullUrlEquals|seeFullUrlMatches|seeInFullUrl|grabFromFullUrl">
11+
<!ENTITY commonTestActions "acceptPopup|actionGroup|amOnPage|amOnUrl|amOnSubdomain|appendField|assertArrayIsSorted|assertArraySubset|assertElementContainsAttribute|attachFile|cancelPopup|checkOption|clearField|click|clickWithLeftButton|clickWithRightButton|closeAdminNotification|closeTab|comment|conditionalClick|createData|deleteData|updateData|getData|dontSee|dontSeeJsError|dontSeeCheckboxIsChecked|dontSeeCookie|dontSeeCurrentUrlEquals|dontSeeCurrentUrlMatches|dontSeeElement|dontSeeElementInDOM|dontSeeInCurrentUrl|dontSeeInField|dontSeeInFormFields|dontSeeInPageSource|dontSeeInSource|dontSeeInTitle|dontSeeLink|dontSeeOptionIsSelected|doubleClick|dragAndDrop|entity|executeJS|executeInSelenium|fillField|formatMoney|generateDate|grabAttributeFrom|grabCookie|grabFromCurrentUrl|grabMultiple|grabPageSource|grabTextFrom|grabValueFrom|loadSessionSnapshot|loginAsAdmin|magentoCLI|makeScreenshot|maximizeWindow|moveBack|moveForward|moveMouseOver|mSetLocale|mResetLocale|openNewTab|pauseExecution|parseFloat|performOn|pressKey|reloadPage|resetCookie|submitForm|resizeWindow|saveSessionSnapshot|scrollTo|scrollToTopOfPage|searchAndMultiSelectOption|see|seeCheckboxIsChecked|seeCookie|seeCurrentUrlEquals|seeCurrentUrlMatches|seeElement|seeElementInDOM|seeInCurrentUrl|seeInField|seeInFormFields|seeInPageSource|seeInPopup|seeInSource|seeInTitle|seeLink|seeNumberOfElements|seeOptionIsSelected|selectOption|setCookie|submitForm|switchToIFrame|switchToNextTab|switchToPreviousTab|switchToWindow|typeInPopup|uncheckOption|unselectOption|wait|waitForAjaxLoad|waitForElement|waitForElementChange|waitForElementNotVisible|waitForElementVisible|waitForJS|waitForLoadingMaskToDisappear|waitForPageLoad|waitForText|assertArrayHasKey|assertArrayNotHasKey|assertArraySubset|assertContains|assertCount|assertEmpty|assertEquals|assertFalse|assertFileExists|assertFileNotExists|assertGreaterOrEquals|assertGreaterThan|assertGreaterThanOrEqual|assertInstanceOf|assertInternalType|assertIsEmpty|assertLessOrEquals|assertLessThan|assertLessThanOrEqual|assertNotContains|assertNotEmpty|assertNotEquals|assertNotInstanceOf|assertNotNull|assertNotRegExp|assertNotSame|assertNull|assertRegExp|assertSame|assertStringStartsNotWith|assertStringStartsWith|assertTrue|expectException|fail|dontSeeFullUrlEquals|dontSee|dontSeeFullUrlMatches|dontSeeInFullUrl|seeFullUrlEquals|seeFullUrlMatches|seeInFullUrl|grabFromFullUrl">
1212
]>
1313

1414
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../src/Magento/FunctionalTestingFramework/ObjectManager/etc/config.xsd">

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ class ActionObject
3939
"expectedResult",
4040
"actualResult",
4141
"command",
42-
"regex"
42+
"regex",
43+
"date",
44+
"format"
4345
];
4446
const SELECTOR_ENABLED_ATTRIBUTES = [
4547
'selector',

src/Magento/FunctionalTestingFramework/Test/etc/Actions/customActions.xsd

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<xs:element type="scrollToTopOfPageType" name="scrollToTopOfPage" minOccurs="0" maxOccurs="unbounded"/>
2323
<xs:element type="clearFieldType" name="clearField" minOccurs="0" maxOccurs="unbounded"/>
2424
<xs:element type="assertArrayIsSortedType" name="assertArrayIsSorted" minOccurs="0" maxOccurs="unbounded"/>
25+
<xs:element type="generateDateType" name="generateDate" minOccurs="0" maxOccurs="unbounded"/>
2526
</xs:choice>
2627
</xs:group>
2728

@@ -219,6 +220,41 @@
219220
<xs:attributeGroup ref="commonActionAttributes"/>
220221
</xs:complexType>
221222

223+
<xs:complexType name="generateDateType">
224+
<xs:annotation>
225+
<xs:documentation>
226+
Generates a date according to input and format.
227+
</xs:documentation>
228+
</xs:annotation>
229+
<xs:simpleContent>
230+
<xs:extension base="xs:string">
231+
<xs:attribute name="date" use="required" type="xs:string">
232+
<xs:annotation>
233+
<xs:documentation>
234+
Date input to parse, uses same functionality as php strtotime() function.
235+
</xs:documentation>
236+
</xs:annotation>
237+
</xs:attribute>
238+
<xs:attribute name="format" use="required" type="xs:string">
239+
<xs:annotation>
240+
<xs:documentation>
241+
Format to save given date in, uses same functionality as php date() function.
242+
</xs:documentation>
243+
</xs:annotation>
244+
</xs:attribute>
245+
<xs:attribute name="timezone" use="optional" type="xs:string">
246+
<xs:annotation>
247+
<xs:documentation>
248+
Timezone to generate date in, defaults to "America/Los_Angeles".
249+
</xs:documentation>
250+
</xs:annotation>
251+
</xs:attribute>
252+
<xs:attributeGroup ref="commonActionAttributes"/>
253+
</xs:extension>
254+
</xs:simpleContent>
255+
</xs:complexType>
256+
257+
222258
<xs:complexType name="arrayType">
223259
<xs:simpleContent>
224260
<xs:extension base="xs:string">

src/Magento/FunctionalTestingFramework/Util/TestGenerator.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = "
491491
$arguments = null;
492492
$sortOrder = null;
493493
$storeCode = null;
494+
$format = null;
494495

495496
$assertExpected = null;
496497
$assertActual = null;
@@ -531,6 +532,17 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = "
531532
$input = $this->addUniquenessFunctionCall($customActionAttributes['regex']);
532533
}
533534

535+
if (isset($customActionAttributes['date']) && isset($customActionAttributes['format'])) {
536+
$input = $this->addUniquenessFunctionCall($customActionAttributes['date']);
537+
if ($input === "") {
538+
$input = "\"Now\"";
539+
}
540+
$format = $this->addUniquenessFunctionCall($customActionAttributes['format']);
541+
if ($format === "") {
542+
$format = "\"r\"";
543+
}
544+
}
545+
534546
if (isset($customActionAttributes['expected'])) {
535547
$assertExpected = $this->resolveValueByType(
536548
$customActionAttributes['expected'],
@@ -1238,6 +1250,19 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = "
12381250
$argRef .= str_replace(ucfirst($fieldKey), "", $stepKey) . "Fields['{$fieldKey}'] = ${input};\n";
12391251
$testSteps .= $argRef;
12401252
break;
1253+
case "generateDate":
1254+
$timezone = "America/Los_Angeles";
1255+
if (isset($customActionAttributes['timezone'])) {
1256+
$timezone = $customActionAttributes['timezone'];
1257+
}
1258+
1259+
$dateGenerateCode = "\t\t\$date = new \DateTime();\n";
1260+
$dateGenerateCode .= "\t\t\$date->setTimestamp(strtotime({$input}));\n";
1261+
$dateGenerateCode .= "\t\t\$date->setTimezone(new \DateTimeZone(\"{$timezone}\"));\n";
1262+
$dateGenerateCode .= "\t\t\${$stepKey} = \$date->format({$format});\n";
1263+
1264+
$testSteps .= $dateGenerateCode;
1265+
break;
12411266
default:
12421267
$testSteps .= $this->wrapFunctionCall($actor, $actionObject, $selector, $input, $parameter);
12431268
}

0 commit comments

Comments
 (0)