Skip to content

Commit f9dba75

Browse files
author
Stas Puga
committed
MAGETWO-94843: Automate with MFTF Auto generated coupon code for Cart Price Rules considers "Uses per Coupon" and "Uses per Customer" options
1 parent 8fd89cf commit f9dba75

File tree

4 files changed

+199
-12
lines changed

4 files changed

+199
-12
lines changed

app/code/Magento/Catalog/Test/Mftf/Section/StorefrontMessagesSection.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
1111
<section name="StorefrontMessagesSection">
1212
<element name="success" type="text" selector="div.message-success.success.message"/>
13+
<element name="error" type="text" selector="div.message-error.error.message"/>
1314
</section>
1415
</sections>

app/code/Magento/SalesRule/Test/Mftf/ActionGroup/ApplyCartRuleOnStorefrontActionGroup.xml

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,16 @@
99
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
1010
<actionGroup name="ApplyCartRuleOnStorefrontActionGroup">
1111
<arguments>
12-
<argument name="Product" defaultValue="_defaultProduct"/>
13-
<argument name="Coupon" defaultValue="SimpleSalesRuleCoupon"/>
12+
<argument name="product"/>
13+
<argument name="couponCode" type="string"/>
1414
</arguments>
15-
<amOnPage url="{{Product.name}}.html" stepKey="navigateToProductPage"/>
16-
<waitForPageLoad stepKey="waitForPageLoad1"/>
1715
<click selector="{{StorefrontProductActionSection.addToCart}}" stepKey="addToCart" />
18-
<waitForText userInput="You added {{Product.name}} to your shopping cart." stepKey="waitForAddedBtn"/>
19-
<amOnPage url="/checkout/cart/" stepKey="onPageShoppingCart"/>
20-
<waitForPageLoad stepKey="waitForPageLoad2"/>
21-
<click selector="{{DiscountSection.DiscountTab}}" stepKey="scrollToDiscountTab" />
22-
<fillField selector="{{DiscountSection.CouponInput}}" userInput="{{Coupon.code}}" stepKey="fillCouponCode" />
16+
<waitForText userInput="You added {{product.name}} to your shopping cart." stepKey="waitForText"/>
17+
<amOnPage url="{{CheckoutCartPage.url}}" stepKey="goToCheckoutPage"/>
18+
<waitForPageLoad stepKey="waitForPageLoad1"/>
19+
<click selector="{{DiscountSection.DiscountTab}}" stepKey="clickToDiscountTab" />
20+
<fillField selector="{{DiscountSection.CouponInput}}" userInput="{{couponCode}}" stepKey="fillCouponCode"/>
2321
<click selector="{{DiscountSection.ApplyCodeBtn}}" stepKey="applyCode"/>
24-
<waitForPageLoad stepKey="waitForPageLoad3"/>
25-
<waitForText userInput="You used coupon code" stepKey="waitForText"/>
26-
<see userInput="You used coupon code" stepKey="assertText"/>
22+
<waitForPageLoad stepKey="waitForPageLoad2"/>
2723
</actionGroup>
2824
</actionGroups>

app/code/Magento/SalesRule/Test/Mftf/Data/SalesRuleData.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,32 @@
6060
<data key="apply">Percent of product price discount</data>
6161
<data key="discountAmount">50</data>
6262
</entity>
63+
<entity name="SalesRuleSpecificCoupon" type="SalesRule">
64+
<data key="name" unique="suffix">SimpleSalesRule</data>
65+
<data key="description">Sales Rule Descritpion</data>
66+
<array key="website_ids">
67+
<item>1</item>
68+
</array>
69+
<array key="customer_group_ids">
70+
<item>0</item>
71+
<item>1</item>
72+
<item>3</item>
73+
</array>
74+
<data key="uses_per_customer">1</data>
75+
<data key="is_active">true</data>
76+
<data key="stop_rules_processing">false</data>
77+
<data key="is_advanced">true</data>
78+
<data key="sort_order">2</data>
79+
<data key="simple_action">by_percent</data>
80+
<data key="discount_amount">10</data>
81+
<data key="discount_qty">1</data>
82+
<data key="discount_step">0</data>
83+
<data key="apply_to_shipping">false</data>
84+
<data key="times_used">1</data>
85+
<data key="is_rss">false</data>
86+
<data key="coupon_type">SPECIFIC_COUPON</data>
87+
<data key="use_auto_generation">true</data>
88+
<data key="uses_per_coupon">2</data>
89+
<data key="simple_free_shipping">1</data>
90+
</entity>
6391
</entities>
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="StorefrontAutoGeneratedCouponCodeTest">
12+
<annotations>
13+
<features value="SalesRule"/>
14+
<stories value="Create cart price rule"/>
15+
<title value="[Cart Price Rule] Auto generated coupon code considers 'Uses per Coupon' and 'Uses per Customer' options"/>
16+
<description
17+
value="[Cart Price Rule] Auto generated coupon code considers 'Uses per Coupon' and 'Uses per Customer' options"/>
18+
<severity value="AVERAGE"/>
19+
<testCaseId value="MAGETWO-59323"/>
20+
<group value="test"/>
21+
<!--<group value="salesRule"/>-->
22+
</annotations>
23+
24+
<before>
25+
<!-- Create customer -->
26+
<createData entity="Simple_US_Customer" stepKey="createCustomer"/>
27+
<!-- Create simple product-->
28+
<createData entity="SimpleProduct2" stepKey="createSimpleProduct"/>
29+
<!-- Create a cart price rule -->
30+
<createData entity="SalesRuleSpecificCoupon" stepKey="createSalesRule"/>
31+
</before>
32+
33+
<after>
34+
<!-- Delete the cart price rule we made during the test -->
35+
<deleteData createDataKey="createSalesRule" stepKey="deleteSalesRule"/>
36+
<deleteData createDataKey="createCustomer" stepKey="deleteCustomer"/>
37+
<deleteData createDataKey="createSimpleProduct" stepKey="deleteSimpleProduct"/>
38+
<actionGroup ref="logout" stepKey="logout"/>
39+
</after>
40+
<!-- Login as Admin -->
41+
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
42+
43+
<!-- Search Cart Price Rule and go to edit Cart Price Rule -->
44+
<amOnPage url="{{AdminCartPriceRulesPage.url}}" stepKey="amOnCartPriceList"/>
45+
<waitForPageLoad stepKey="waitForPageLoad"/>
46+
<fillField selector="{{AdminCartPriceRulesSection.filterByNameInput}}" userInput="$$createSalesRule.name$$"
47+
stepKey="fillFieldFilterByName"/>
48+
<click selector="{{AdminCartPriceRulesSection.searchButton}}" stepKey="clickSearchButton"/>
49+
<see selector="{{AdminCartPriceRulesSection.nameColumns}}" userInput="$$createSalesRule.name$$"
50+
stepKey="seeRuleName"/>
51+
<click selector="{{AdminCartPriceRulesSection.rowContainingText($$createSalesRule.name$$)}}"
52+
stepKey="goToEditRule"/>
53+
54+
<!-- Step 3-4. Navigate to Manage Coupon Codes section to generate 1 coupon code -->
55+
<conditionalClick selector="{{AdminCartPriceRulesFormSection.manageCouponCodesHeader}}"
56+
dependentSelector="{{AdminCartPriceRulesFormSection.manageCouponCodesHeader}}" visible="true"
57+
stepKey="clickManageCouponCodes"/>
58+
<fillField selector="{{AdminCartPriceRulesFormSection.couponQty}}" userInput="1" stepKey="fillFieldCouponQty"/>
59+
<click selector="{{AdminCartPriceRulesFormSection.generateCouponsButton}}" stepKey="clickGenerateCoupon"/>
60+
<see selector="{{AdminCartPriceRulesFormSection.successMessage}}" userInput="1 coupon(s) have been generated."
61+
stepKey="seeSuccessMessage"/>
62+
<grabTextFrom selector="{{AdminCartPriceRulesFormSection.generatedCouponByIndex('1')}}"
63+
stepKey="couponCode"/>
64+
65+
<!-- Step: 5. Login to storefront as previously created customer -->
66+
<actionGroup ref="LoginToStorefrontActionGroup" stepKey="loginAsCustomer">
67+
<argument name="Customer" value="$$createCustomer$$"/>
68+
</actionGroup>
69+
70+
<!-- Step: 6-7. Open the Product Page, add the product to Cart, go to Shopping Cart and Apply the same coupon code -->
71+
<amOnPage url="{{StorefrontProductPage.url($$createSimpleProduct.name$$)}}" stepKey="openProductPage"/>
72+
<waitForPageLoad stepKey="waitForPageLoad2"/>
73+
<actionGroup ref="ApplyCartRuleOnStorefrontActionGroup" stepKey="applyCartPriceRule">
74+
<argument name="product" value="$$createSimpleProduct$$"/>
75+
<argument name="couponCode" value="{$couponCode}"/>
76+
</actionGroup>
77+
<waitForText userInput='You used coupon code "{$couponCode}"' stepKey="waitForText"/>
78+
<see selector="{{StorefrontMessagesSection.success}}" userInput='You used coupon code "{$couponCode}"'
79+
stepKey="seeSuccessMessage1"/>
80+
<waitForElementVisible selector="{{CheckoutCartSummarySection.discountAmount}}" time="30"
81+
stepKey="waitForElementDiscountVisible"/>
82+
83+
<!-- Step 8. Go to Checkout and Click Place Order button -->
84+
<click selector="{{CheckoutCartSummarySection.proceedToCheckout}}" stepKey="clickProceedToCheckout"/>
85+
<click selector="{{CheckoutShippingMethodsSection.checkShippingMethodByName('Flat Rate')}}"
86+
stepKey="selectFlatShippingMethod"/>
87+
<waitForLoadingMaskToDisappear stepKey="waitForLoadingMask"/>
88+
<waitForElement selector="{{CheckoutShippingMethodsSection.next}}" time="30" stepKey="waitForNextButton"/>
89+
<click selector="{{CheckoutShippingMethodsSection.next}}" stepKey="clickNext"/>
90+
<waitForElement selector="{{CheckoutPaymentSection.paymentSectionTitle}}" time="30"
91+
stepKey="waitForPaymentSectionLoaded"/>
92+
<click selector="{{CheckoutPaymentSection.placeOrder}}" stepKey="clickPlaceOrder"/>
93+
<waitForElement selector="{{CheckoutSuccessMainSection.success}}" time="30" stepKey="waitForLoadSuccessPage"/>
94+
95+
<!-- Step: 9-10. Open the Product Page, add the product to Cart, go to Shopping Cart and Apply the same coupon code -->
96+
<amOnPage url="{{StorefrontProductPage.url($$createSimpleProduct.name$$)}}" stepKey="openProductPage1"/>
97+
<waitForPageLoad stepKey="waitForPageLoad3"/>
98+
<actionGroup ref="ApplyCartRuleOnStorefrontActionGroup" stepKey="applyCartPriceRule1">
99+
<argument name="product" value="$$createSimpleProduct$$"/>
100+
<argument name="couponCode" value="{$couponCode}"/>
101+
</actionGroup>
102+
<waitForText userInput='The coupon code "{$couponCode}" is not valid.' stepKey="waitForText1"/>
103+
<see selector="{{StorefrontMessagesSection.error}}" userInput='The coupon code "{$couponCode}" is not valid.'
104+
stepKey="seeErrorMessages"/>
105+
<waitForElementNotVisible selector="{{CheckoutCartSummarySection.discountAmount}}" time="30"
106+
stepKey="waitForElementNotDiscountVisible"/>
107+
108+
<!-- Step 11. Log out from storefront -->
109+
<actionGroup ref="StorefrontSignOutActionGroup" stepKey="storefrontSignOut"/>
110+
111+
<!-- Step: 12-13. Open the Product Page, add the product to Cart, go to Shopping Cart and Apply the same coupon code -->
112+
<amOnPage url="{{StorefrontProductPage.url($$createSimpleProduct.name$$)}}" stepKey="openProductPage2"/>
113+
<waitForPageLoad stepKey="waitForPageLoad4"/>
114+
<actionGroup ref="ApplyCartRuleOnStorefrontActionGroup" stepKey="applyCartPriceRule2">
115+
<argument name="product" value="$$createSimpleProduct$$"/>
116+
<argument name="couponCode" value="{$couponCode}"/>
117+
</actionGroup>
118+
<waitForText userInput='You used coupon code "{$couponCode}"' stepKey="waitForText2"/>
119+
<see selector="{{StorefrontMessagesSection.success}}" userInput='You used coupon code "{$couponCode}"'
120+
stepKey="seeSuccessMessage2"/>
121+
<waitForElementVisible selector="{{CheckoutCartSummarySection.discountAmount}}" time="30"
122+
stepKey="waitForElementDiscountVisible1"/>
123+
124+
<!-- Step 14. Go to Checkout and Click Place Order button -->
125+
<click selector="{{CheckoutCartSummarySection.proceedToCheckout}}" stepKey="clickProceedToCheckout1"/>
126+
<actionGroup ref="GuestCheckoutFillingShippingSectionActionGroup" stepKey="guestCheckoutFillingShippingSection">
127+
<argument name="customerVar" value="CustomerEntityOne"/>
128+
<argument name="customerAddressVar" value="CustomerAddressSimple"/>
129+
</actionGroup>
130+
<click selector="{{CheckoutPaymentSection.placeOrder}}" stepKey="clickPlaceOrder1"/>
131+
<waitForElement selector="{{CheckoutSuccessMainSection.success}}" time="30" stepKey="waitForLoadSuccessPage1"/>
132+
133+
<!-- Step; 15-16. Open the Product Page, add the product to Cart, go to Shopping Cart and Apply the same coupon code -->
134+
<amOnPage url="{{StorefrontProductPage.url($$createSimpleProduct.name$$)}}" stepKey="openProductPage3"/>
135+
<waitForPageLoad stepKey="waitForPageLoad5"/>
136+
<actionGroup ref="ApplyCartRuleOnStorefrontActionGroup" stepKey="applyCartPriceRule3">
137+
<argument name="product" value="$$createSimpleProduct$$"/>
138+
<argument name="couponCode" value="{$couponCode}"/>
139+
</actionGroup>
140+
<waitForText userInput='The coupon code "{$couponCode}" is not valid.' stepKey="waitForText3"/>
141+
<see selector="{{StorefrontMessagesSection.error}}" userInput='The coupon code "{$couponCode}" is not valid.'
142+
stepKey="seeErrorMessages1"/>
143+
<waitForElementNotVisible selector="{{CheckoutCartSummarySection.discountAmount}}" time="30"
144+
stepKey="waitForElementNotDiscountVisible1"/>
145+
146+
<!-- Step: 17. Open another browser Reset Cookie -->
147+
<resetCookie userInput="PHPSESSID" stepKey="resetCookie"/>
148+
149+
<!-- Step: 18-19. Open the Product Page, add the product to Cart, go to Shopping Cart and Apply the same coupon code -->
150+
<amOnPage url="{{StorefrontProductPage.url($$createSimpleProduct.name$$)}}" stepKey="openProductPage4"/>
151+
<waitForPageLoad stepKey="waitForPageLoad6"/>
152+
<actionGroup ref="ApplyCartRuleOnStorefrontActionGroup" stepKey="applyCartPriceRule4">
153+
<argument name="product" value="$$createSimpleProduct$$"/>
154+
<argument name="couponCode" value="{$couponCode}"/>
155+
</actionGroup>
156+
<waitForText userInput='The coupon code "{$couponCode}" is not valid.' stepKey="waitForText4"/>
157+
<see selector="{{StorefrontMessagesSection.error}}" userInput='The coupon code "{$couponCode}" is not valid.'
158+
stepKey="seeErrorMessages2"/>
159+
<waitForElementNotVisible selector="{{CheckoutCartSummarySection.discountAmount}}" time="30"
160+
stepKey="waitForElementNotDiscountVisible2"/>
161+
</test>
162+
</tests>

0 commit comments

Comments
 (0)