22
33import { expect , type Locator , type Page } from '@playwright/test' ;
44import { UIReference , inputValues , outcomeMarker } from '@config' ;
5+ import { requireEnv } from '@utils/env.utils' ;
56
67class MagentoAdminPage {
78 readonly page : Page ;
@@ -51,17 +52,26 @@ class MagentoAdminPage {
5152 const addCartPriceRuleButton = this . page . getByRole ( 'button' , { name : UIReference . cartPriceRulesPage . addCartPriceRuleButtonLabel } ) ;
5253 await addCartPriceRuleButton . waitFor ( ) ;
5354
54- const couponCellField = this . page . getByRole ( 'cell' , { name : magentoCouponCode } ) ;
55+ const couponSearchField = this . page . locator ( UIReference . magentoAdminPage . couponSearchFieldLocator ) ;
56+ await couponSearchField . fill ( magentoCouponCode ) ;
57+ await this . page . getByRole ( 'button' , { name : UIReference . general . searchButtonLabel } ) . click ( ) ;
58+
59+ await expect ( this . page . getByText ( UIReference . magentoAdminPage . searchResultsText ) ) . toBeVisible ( ) ;
60+
61+ const couponCellField = this . page . getByRole ( 'cell' , { name : outcomeMarker . magentoAdmin . noResultsFoundText } ) ;
62+
63+ // const couponCellField = this.page.getByRole('cell', {name: magentoCouponCode});
5564
56- if ( await couponCellField . isVisible ( ) ) {
57- const couponStatusField = this . page . locator ( 'tr' ) . filter ( { hasText :magentoCouponCode } ) ;
65+ if ( await couponCellField . isHidden ( ) ) {
66+ // if(await couponCellField.isVisible()){
67+ const couponStatusField = this . page . locator ( 'tr' ) . filter ( { hasText :magentoCouponCode } ) . first ( ) ;
5868 const couponStatus = await couponStatusField . innerText ( ) ;
5969 if ( couponStatus . includes ( UIReference . cartPriceRulesPage . couponCodeActiveStatusText ) ) {
6070 console . log ( 'Coupon already exists and is active' ) ;
6171 return 'Coupon already exists and is active.' ;
6272 } else {
6373 // coupon has been found, but is not active.
64- await couponCellField . click ( ) ;
74+ await couponStatusField . click ( ) ;
6575 const activeStatusSwitcher = this . page . locator ( UIReference . cartPriceRulesPage . activeStatusSwitcherLocator ) . first ( ) ;
6676 const activeStatusLabel = this . page . locator ( UIReference . cartPriceRulesPage . activeStatusLabelLocator ) . first ( ) ;
6777
@@ -71,7 +81,9 @@ class MagentoAdminPage {
7181 const saveCouponButton = this . page . getByRole ( 'button' , { name :UIReference . cartPriceRulesPage . saveRuleButtonLabel , exact :true } ) ;
7282 await saveCouponButton . click ( ) ;
7383
74- await expect ( this . page . locator ( UIReference . general . messageLocator ) ) . toBeVisible ( ) ;
84+ await expect ( this . page . locator (
85+ UIReference . general . messageLocator ) . filter ( { hasText : outcomeMarker . magentoAdmin . couponRuleSavedText }
86+ ) , "Message 'you saved the rule' is visible" ) . toBeVisible ( ) ;
7587 return `Coupon code ${ magentoCouponCode } has been activated.` ;
7688 }
7789 } else {
@@ -96,6 +108,7 @@ class MagentoAdminPage {
96108 select . dispatchEvent ( new Event ( 'change' ) ) ;
97109 } ) ;
98110
111+ await this . page . getByRole ( 'textbox' , { name : UIReference . cartPriceRulesPage . ruleNameFieldLabel } ) . fill ( magentoCouponCode ) ;
99112 await this . page . locator ( UIReference . cartPriceRulesPage . couponTypeSelectField ) . selectOption ( { label : inputValues . coupon . couponType } ) ;
100113 await this . page . getByLabel ( UIReference . cartPriceRulesPage . couponCodeFieldLabel ) . fill ( magentoCouponCode ) ;
101114
@@ -105,7 +118,9 @@ class MagentoAdminPage {
105118 const couponSaveButton = this . page . getByRole ( 'button' , { name : UIReference . cartPriceRulesPage . saveRuleButtonLabel , exact : true } ) ;
106119 await couponSaveButton . scrollIntoViewIfNeeded ( ) ;
107120 await couponSaveButton . click ( { force :true } ) ;
108- await expect ( this . page . locator ( UIReference . general . messageLocator ) ) . toBeVisible ( ) ;
121+ await expect ( this . page . locator (
122+ UIReference . general . messageLocator ) . filter ( { hasText : outcomeMarker . magentoAdmin . couponRuleSavedText }
123+ ) , "Message 'you saved the rule' is visible" ) . toBeVisible ( ) ;
109124 return `Coupon code ${ magentoCouponCode } has been set and activated.` ;
110125 }
111126 } ;
@@ -133,7 +148,7 @@ class MagentoAdminPage {
133148 await allCustomersLink . click ( ) ;
134149
135150 // Wait for URL. If loading symbol is visible, wait for it to go away
136- await this . page . waitForURL ( ' **/beheer /customer/index/**' ) ;
151+ await this . page . waitForURL ( ` **/${ requireEnv ( 'MAGENTO_ADMIN_SLUG' ) } /customer/index/**` ) ;
137152 if ( await this . page . locator ( UIReference . general . loadingSpinnerLocator ) . isVisible ( ) ) {
138153 await this . page . locator ( UIReference . general . loadingSpinnerLocator ) . waitFor ( { state : 'hidden' } ) ;
139154 }
@@ -186,7 +201,8 @@ class MagentoAdminPage {
186201 await customerConfigurationLink . waitFor ( ) ;
187202 await customerConfigurationLink . click ( ) ;
188203
189- const captchaSettingsBlock = this . page . getByRole ( 'link' , { name : UIReference . configurationPage . captchaSectionLabel } ) . filter ( { hasNotText : 'documentation' } ) ;
204+ const captchaSettingsBlock = this . page . getByRole ( 'link' , { name : UIReference . configurationPage . captchaSectionLabel } )
205+ . filter ( { hasNotText : 'documentation' } ) ;
190206 const captchaSettingsSystemValueCheckbox = this . page . locator ( UIReference . configurationPage . captchaSettingSystemCheckbox ) ;
191207
192208 await captchaSettingsBlock . waitFor ( ) ;
@@ -209,7 +225,7 @@ class MagentoAdminPage {
209225 const saveConfigButton = this . page . getByRole ( 'button' , { name : UIReference . configurationPage . saveConfigButtonLabel } ) ;
210226 await saveConfigButton . click ( ) ;
211227
212- await expect ( this . page . locator ( UIReference . general . messageLocator ) ) . toBeVisible ( ) ;
228+ await expect ( this . page . locator ( UIReference . general . messageLocator ) . filter ( { hasText : outcomeMarker . magentoAdmin . configurationSavedText } ) ) . toBeVisible ( ) ;
213229 }
214230 }
215231
@@ -269,7 +285,7 @@ class MagentoAdminPage {
269285 const saveConfigButton = this . page . getByRole ( 'button' , { name : UIReference . configurationPage . saveConfigButtonLabel } ) ;
270286 await saveConfigButton . click ( ) ;
271287
272- await expect ( this . page . locator ( UIReference . general . messageLocator ) ) . toBeVisible ( ) ;
288+ await expect ( this . page . locator ( UIReference . general . messageLocator ) . filter ( { hasText : outcomeMarker . magentoAdmin . configurationSavedText } ) ) . toBeVisible ( ) ;
273289 }
274290 }
275291
0 commit comments