@@ -31,6 +31,7 @@ class MagentoAdminPage {
3131 * @then the system displays a success message confirming the rule was saved
3232 */
3333 async addCartPriceRule ( magentoCouponCode : string ) {
34+ let resultMessage = "" ;
3435
3536 // Force specific viewport size to deal with webkit issues
3637 await this . page . setViewportSize ( {
@@ -52,6 +53,7 @@ class MagentoAdminPage {
5253 const addCartPriceRuleButton = this . page . getByRole ( 'button' , { name : UIReference . cartPriceRulesPage . addCartPriceRuleButtonLabel } ) ;
5354 await addCartPriceRuleButton . waitFor ( ) ;
5455
56+ // Use search field to check for coupon codes.
5557 const couponSearchField = this . page . locator ( UIReference . magentoAdminPage . couponSearchFieldLocator ) ;
5658 await couponSearchField . fill ( magentoCouponCode ) ;
5759 await this . page . getByRole ( 'button' , { name : UIReference . general . searchButtonLabel } ) . click ( ) ;
@@ -60,15 +62,11 @@ class MagentoAdminPage {
6062
6163 const couponCellField = this . page . getByRole ( 'cell' , { name : outcomeMarker . magentoAdmin . noResultsFoundText } ) ;
6264
63- // const couponCellField = this.page.getByRole('cell', {name: magentoCouponCode});
64-
6565 if ( await couponCellField . isHidden ( ) ) {
66- // if(await couponCellField.isVisible()){
6766 const couponStatusField = this . page . locator ( 'tr' ) . filter ( { hasText :magentoCouponCode } ) . first ( ) ;
6867 const couponStatus = await couponStatusField . innerText ( ) ;
6968 if ( couponStatus . includes ( UIReference . cartPriceRulesPage . couponCodeActiveStatusText ) ) {
70- console . log ( 'Coupon already exists and is active' ) ;
71- return 'Coupon already exists and is active.' ;
69+ resultMessage = 'Coupon already exists and is active.' ;
7270 } else {
7371 // coupon has been found, but is not active.
7472 await couponStatusField . click ( ) ;
@@ -84,7 +82,7 @@ class MagentoAdminPage {
8482 await expect ( this . page . locator (
8583 UIReference . general . messageLocator ) . filter ( { hasText : outcomeMarker . magentoAdmin . couponRuleSavedText }
8684 ) , "Message 'you saved the rule' is visible" ) . toBeVisible ( ) ;
87- return `Coupon code ${ magentoCouponCode } has been activated.` ;
85+ resultMessage = `Coupon code ${ magentoCouponCode } has been activated.` ;
8886 }
8987 } else {
9088 // coupon is not set
@@ -121,8 +119,16 @@ class MagentoAdminPage {
121119 await expect ( this . page . locator (
122120 UIReference . general . messageLocator ) . filter ( { hasText : outcomeMarker . magentoAdmin . couponRuleSavedText }
123121 ) , "Message 'you saved the rule' is visible" ) . toBeVisible ( ) ;
124- return `Coupon code ${ magentoCouponCode } has been set and activated.` ;
122+ resultMessage = `Coupon code ${ magentoCouponCode } has been set and activated.` ;
125123 }
124+
125+ // Clear the search field
126+ await couponSearchField . waitFor ( ) ;
127+ const clearSearchButton = this . page . getByRole ( 'button' , { name : UIReference . cartPriceRulesPage . clearSearchButtonLabel } ) ;
128+ await clearSearchButton . click ( ) ;
129+ await expect ( couponSearchField , `Coupon Code search field is empty` ) . toBeEmpty ( ) ;
130+
131+ return resultMessage ;
126132 } ;
127133
128134 /**
0 commit comments