Skip to content

Commit 8321d7d

Browse files
Mohit.k.SharmaMohit.k.Sharma
Mohit.k.Sharma
authored and
Mohit.k.Sharma
committed
MQE-2953 | Get Cookie Expiry in mftf
1 parent 75b1e08 commit 8321d7d

File tree

7 files changed

+84
-2
lines changed

7 files changed

+84
-2
lines changed

dev/.credentials

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
magento/MAGENTO_ADMIN_PASSWORD=Admin@123456

docs/test/actions.md

+29
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ The following test actions return a variable:
144144

145145
* [grabAttributeFrom](#grabattributefrom)
146146
* [grabCookie](#grabcookie)
147+
* [grabCookieAttributes](#grabCookieAttributes)
147148
* [grabFromCurrentUrl](#grabfromcurrenturl)
148149
* [grabMultiple](#grabmultiple)
149150
* [grabPageSource](#grabpagesource)
@@ -1158,6 +1159,34 @@ To access this value, use `{$grabCookieExampleDomain}` in later actions. -->
11581159
<grabCookie userInput="cookie1" parameterArray="['domainName' => '.example.com']" stepKey="grabCookieExampleDomain"/>
11591160
```
11601161

1162+
### grabCookieAttributes
1163+
1164+
See [grabCookieAttributes docs on codeception.com](http://codeception.com/docs/modules/WebDriver#grabCookieAttributes).
1165+
1166+
Attribute|Type|Use|Description
1167+
---|---|---|---
1168+
`userInput`|string|optional| Name of the cookie to grab.
1169+
`parameterArray`|string|optional| Array of cookie parameters to grab.
1170+
`stepKey`|string|required| A unique identifier of the action.
1171+
`before`|string|optional| `stepKey` of action that must be executed next.
1172+
`after`|string|optional| `stepKey` of preceding action.
1173+
1174+
#### Examples
1175+
1176+
```xml
1177+
<!-- Grab the cookie attributes with the given name `cookie1`.
1178+
To access these values, use `{$grabCookie1}` in later actions. -->
1179+
<grabCookieAttributes userInput="cookie1" stepKey="grabCookie1"/>
1180+
```
1181+
1182+
```xml
1183+
<!-- Grab the cookie attributes with the given name `cookie1` from the domain `www.example.com`.
1184+
To access these values, use `{$grabCookieExampleDomain}` in later actions.
1185+
To access expiry date, use `{$grabCookieExampleDomain.expiry}` in later actions.
1186+
-->
1187+
<grabCookieAttributes userInput="cookie1" parameterArray="['domainName' => '.example.com']" stepKey="grabCookieExampleDomain"/>
1188+
```
1189+
11611190
### grabFromCurrentUrl
11621191

11631192
See [grabFromCurrentUrl docs on codeception.com](http://codeception.com/docs/modules/WebDriver#grabFromCurrentUrl)..

etc/di.xml

+1-1
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|assertArrayIsSortasserted|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|fillField|formatCurrency|generateDate|getOTP|grabAttributeFrom|grabCookie|grabFromCurrentUrl|grabMultiple|grabPageSource|grabTextFrom|grabValueFrom|return|loadSessionSnapshot|loginAsAdmin|magentoCLI|magentoCron|makeScreenshot|maximizeWindow|moveBack|moveForward|moveMouseOver|mSetLocale|mResetLocale|openNewTab|pause|parseFloat|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|waitForPwaElementNotVisible|waitForPwaElementVisible|waitForJS|waitForLoadingMaskToDisappear|waitForPageLoad|waitForText|assertArrayHasKey|assertArrayNotHasKey|assertContains|assertStringContainsString|assertStringContainsStringIgnoringCase|assertCount|assertEmpty|assertEquals|assertFalse|assertFileExists|assertFileNotExists|assertGreaterOrEquals|assertGreaterThan|assertGreaterThanOrEqual|assertInstanceOf|assertIsEmpty|assertLessOrEquals|assertLessThan|assertLessThanOrEqual|assertNotContains|assertStringNotContainsString|assertStringNotContainsStringIgnoringCase|assertNotEmpty|assertNotEquals|assertNotInstanceOf|assertNotNull|assertNotRegExp|assertNotSame|assertNull|assertRegExp|assertSame|assertStringStartsNotWith|assertStringStartsWith|assertTrue|expectException|fail|dontSeeFullUrlEquals|dontSee|dontSeeFullUrlMatches|dontSeeInFullUrl|seeFullUrlEquals|seeFullUrlMatches|seeInFullUrl|grabFromFullUrl|helper|assertEqualsWithDelta|assertEqualsCanonicalizing|assertEqualsIgnoringCase|assertNotEqualsWithDelta|assertNotEqualsCanonicalizing|assertNotEqualsIgnoringCase">
11+
<!ENTITY commonTestActions "acceptPopup|actionGroup|amOnPage|amOnUrl|amOnSubdomain|appendField|assertArrayIsSortasserted|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|fillField|formatCurrency|generateDate|getOTP|grabAttributeFrom|grabCookie|grabCookieAttributes|grabFromCurrentUrl|grabMultiple|grabPageSource|grabTextFrom|grabValueFrom|return|loadSessionSnapshot|loginAsAdmin|magentoCLI|magentoCron|makeScreenshot|maximizeWindow|moveBack|moveForward|moveMouseOver|mSetLocale|mResetLocale|openNewTab|pause|parseFloat|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|waitForPwaElementNotVisible|waitForPwaElementVisible|waitForJS|waitForLoadingMaskToDisappear|waitForPageLoad|waitForText|assertArrayHasKey|assertArrayNotHasKey|assertContains|assertStringContainsString|assertStringContainsStringIgnoringCase|assertCount|assertEmpty|assertEquals|assertFalse|assertFileExists|assertFileNotExists|assertGreaterOrEquals|assertGreaterThan|assertGreaterThanOrEqual|assertInstanceOf|assertIsEmpty|assertLessOrEquals|assertLessThan|assertLessThanOrEqual|assertNotContains|assertStringNotContainsString|assertStringNotContainsStringIgnoringCase|assertNotEmpty|assertNotEquals|assertNotInstanceOf|assertNotNull|assertNotRegExp|assertNotSame|assertNull|assertRegExp|assertSame|assertStringStartsNotWith|assertStringStartsWith|assertTrue|expectException|fail|dontSeeFullUrlEquals|dontSee|dontSeeFullUrlMatches|dontSeeInFullUrl|seeFullUrlEquals|seeFullUrlMatches|seeInFullUrl|grabFromFullUrl|helper|assertEqualsWithDelta|assertEqualsCanonicalizing|assertEqualsIgnoringCase|assertNotEqualsWithDelta|assertNotEqualsCanonicalizing|assertNotEqualsIgnoringCase">
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/Module/MagentoWebDriver.php

+33
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,39 @@ public function rapidClick($selector, $count)
808808
}
809809
}
810810

811+
/**
812+
* Grabs a cookie attributes value.
813+
* You can set additional cookie params like `domain`, `path` in array passed as last argument.
814+
* If the cookie is set by an ajax request (XMLHttpRequest),
815+
* there might be some delay caused by the browser, so try `$I->wait(0.1)`.
816+
* @param string $cookie
817+
* @param array $params
818+
* @return mixed
819+
*/
820+
public function grabCookieAttributes(string $cookie, array $params = []): array
821+
{
822+
$params['name'] = $cookie;
823+
$cookieArrays = $this->filterCookies($this->webDriver->manage()->getCookies(), $params);
824+
if (is_array($cookieArrays)) { // Microsoft Edge returns null if there are no cookies...
825+
$cookieAttributes = [];
826+
foreach ($cookieArrays as $cookieArray) {
827+
if ($cookieArray->getName() === $cookie) {
828+
$cookieAttributes['name'] = $cookieArray->getValue();
829+
$cookieAttributes['path'] = $cookieArray->getPath();
830+
$cookieAttributes['domain'] = $cookieArray->getDomain();
831+
$cookieAttributes['secure'] = $cookieArray->isSecure();
832+
$cookieAttributes['httpOnly'] = $cookieArray->isHttpOnly();
833+
$cookieAttributes['sameSite'] = $cookieArray->getSameSite();
834+
$cookieAttributes['expiry'] = date('d/m/Y', $cookieArray->getExpiry());
835+
836+
return $cookieAttributes;
837+
}
838+
}
839+
}
840+
841+
return [];
842+
}
843+
811844
/**
812845
* Function used to fill sensitive credentials with user data, data is decrypted immediately prior to fill to avoid
813846
* exposure in console or log.

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

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class ActionGroupObject
3131
"createData",
3232
"grabAttributeFrom",
3333
"grabCookie",
34+
"grabCookieAttributes",
3435
"grabFromCurrentUrl",
3536
"grabMultiple",
3637
"grabPageSource",

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

+17-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<xs:choice>
1414
<xs:element type="grabAttributeFromType" name="grabAttributeFrom" minOccurs="0" maxOccurs="unbounded"/>
1515
<xs:element type="grabCookieType" name="grabCookie" minOccurs="0" maxOccurs="unbounded"/>
16+
<xs:element type="grabCookieAttributesType" name="grabCookieAttributes" minOccurs="0" maxOccurs="unbounded"/>
1617
<xs:element type="grabFromCurrentUrlType" name="grabFromCurrentUrl" minOccurs="0" maxOccurs="unbounded"/>
1718
<xs:element type="grabMultipleType" name="grabMultiple" minOccurs="0" maxOccurs="unbounded"/>
1819
<xs:element type="grabPageSourceType" name="grabPageSource" minOccurs="0" maxOccurs="unbounded"/>
@@ -53,6 +54,21 @@
5354
</xs:simpleContent>
5455
</xs:complexType>
5556

57+
<xs:complexType name="grabCookieAttributesType">
58+
<xs:annotation>
59+
<xs:documentation>
60+
Grabs a cookie attributes value.
61+
</xs:documentation>
62+
</xs:annotation>
63+
<xs:simpleContent>
64+
<xs:extension base="xs:string">
65+
<xs:attribute ref="userInput"/>
66+
<xs:attribute ref="parameterArray"/>
67+
<xs:attributeGroup ref="commonActionAttributes"/>
68+
</xs:extension>
69+
</xs:simpleContent>
70+
</xs:complexType>
71+
5672
<xs:complexType name="grabFromCurrentUrlType">
5773
<xs:annotation>
5874
<xs:documentation>
@@ -129,4 +145,4 @@
129145
</xs:extension>
130146
</xs:simpleContent>
131147
</xs:complexType>
132-
</xs:schema>
148+
</xs:schema>

src/Magento/FunctionalTestingFramework/Util/TestGenerator.php

+2
Original file line numberDiff line numberDiff line change
@@ -1100,6 +1100,7 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato
11001100
$parameterArray
11011101
);
11021102
break;
1103+
case "grabCookieAttributes":
11031104
case "grabCookie":
11041105
$testSteps .= $this->wrapFunctionCallWithReturnValue(
11051106
$stepKey,
@@ -2371,6 +2372,7 @@ private function validateXmlAttributesMutuallyExclusive($key, $tagName, $attribu
23712372
'excludes' => [
23722373
'dontSeeCookie',
23732374
'grabCookie',
2375+
'grabCookieAttributes',
23742376
'resetCookie',
23752377
'seeCookie',
23762378
'setCookie',

0 commit comments

Comments
 (0)