Skip to content

Commit b2cacaf

Browse files
author
Shay
committed
Merge branch '236-setup-kan-falen-door-gebruik-van-generieke-selector-div-message-in-magento-admin' into 'main'
Resolve "Setup kan falen door gebruik van generieke selector 'div.message' in Magento admin" See merge request elgentos/magento2-playwright!40
2 parents e3defdc + 3b6eb39 commit b2cacaf

File tree

4 files changed

+57
-37
lines changed

4 files changed

+57
-37
lines changed

tests/config/element-identifiers.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@
183183
"homePageTitleText": "Hyvä Themes"
184184
},
185185
"magentoAdminPage": {
186+
"couponSearchFieldLocator" : "#promo_quote_grid_filter_coupon_code",
186187
"dashboardHeadingText": "Dashboard",
187188
"loginButtonLabel": "Sign In",
188189
"navigation": {
@@ -191,6 +192,7 @@
191192
"storesButtonLabel": "Stores"
192193
},
193194
"passwordFieldLabel": "Password",
195+
"searchResultsText" : "records found",
194196
"subNavigation": {
195197
"allCustomersButtonLabel": "All Customers",
196198
"cartPriceRulesButtonLabel": "Cart Price Rules",

tests/config/outcome-markers.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@
4949
"logout": {
5050
"logoutConfirmationText": "You have signed out"
5151
},
52+
"magentoAdmin" : {
53+
"configurationSavedText" : "You saved the configuration.",
54+
"couponRuleSavedText" : "You saved the rule.",
55+
"noResultsFoundText" : "We couldn't find any records."
56+
},
5257
"miniCart": {
5358
"configurableProductMinicartTitle": "x Inez Full Zip Jacket",
5459
"miniCartTitle": "My Cart",

tests/poms/adminhtml/magentoAdmin.page.ts

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { expect, type Locator, type Page } from '@playwright/test';
44
import { UIReference, inputValues, outcomeMarker } from '@config';
5+
import { requireEnv } from '@utils/env.utils';
56

67
class 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

tests/setup.spec.ts

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,51 +19,48 @@ base.beforeEach(async ({ page }, testInfo) => {
1919
});
2020

2121
base.describe('Setting up the testing environment', () => {
22+
// Set tests to serial mode to ensure the order is followed.
23+
base.describe.configure({mode:'serial'});
24+
2225
/**
23-
* @feature Magento Admin Configuration (Enable multiple admin logins)
24-
* @scenario Enable multiple admin logins only in Chromium browser
25-
* @given the
26-
* @scenario Enable multiple admin logins only in Chromium browser
26+
* @feature Magento Admin Configuration (disable login CAPTCHA)
27+
* @scenario Disable login CAPTCHA in admin settings via Chromium browser
2728
* @given the test is running in a Chromium-based browser
2829
* @when the admin logs in to the Magento dashboard
29-
* @and the admin navigates to the configuration page
30-
* @and the "Allow Multiple Admin Account Login" setting is updated to "Yes"
30+
* @and the admin navigates to the security configuration section
31+
* @and the "Enable CAPTCHA on Admin Login" setting is updated to "No"
3132
* @then the configuration is saved successfully
3233
* @but if the browser is not Chromium
3334
* @then the test is skipped with an appropriate message
3435
*/
35-
base('Enable_multiple_admin_logins', { tag: '@setup' }, async ({ page, browserName }, testInfo) => {
36-
const browserEngine = browserName?.toUpperCase() || "UNKNOWN";
36+
base('Disable_login_captcha', { tag: '@setup' }, async ({ page, browserName }, testInfo) => {
37+
base.skip(browserName !== 'chromium', `Disabling login captcha through Chromium. This is ${browserName}, therefore test is skipped.`);
3738

38-
if (browserEngine !== "CHROMIUM") {
39-
testInfo.skip(true, `Enabling multiple admin logins through Chromium. This is ${browserEngine}, therefore test is skipped.`);
40-
} else {
41-
const magentoAdminPage = new MagentoAdminPage(page);
42-
await magentoAdminPage.enableMultipleAdminLogins();
43-
}
39+
const magentoAdminPage = new MagentoAdminPage(page);
40+
await magentoAdminPage.disableLoginCaptcha();
4441
});
4542

43+
4644
/**
47-
* @feature Magento Admin Configuration (disable login CAPTCHA)
48-
* @scenario Disable login CAPTCHA in admin settings via Chromium browser
45+
* @feature Magento Admin Configuration (Enable multiple admin logins)
46+
* @scenario Enable multiple admin logins only in Chromium browser
47+
* @given the
48+
* @scenario Enable multiple admin logins only in Chromium browser
4949
* @given the test is running in a Chromium-based browser
5050
* @when the admin logs in to the Magento dashboard
51-
* @and the admin navigates to the security configuration section
52-
* @and the "Enable CAPTCHA on Admin Login" setting is updated to "No"
51+
* @and the admin navigates to the configuration page
52+
* @and the "Allow Multiple Admin Account Login" setting is updated to "Yes"
5353
* @then the configuration is saved successfully
5454
* @but if the browser is not Chromium
5555
* @then the test is skipped with an appropriate message
5656
*/
57-
base('Disable_login_captcha', { tag: '@setup' }, async ({ page, browserName }, testInfo) => {
58-
const browserEngine = browserName?.toUpperCase() || "UNKNOWN";
57+
base('Enable_multiple_admin_logins', { tag: '@setup' }, async ({ page, browserName }, testInfo) => {
58+
base.skip(browserName !== 'chromium', `Disabling login captcha through Chromium. This is ${browserName}, therefore test is skipped.`);
5959

60-
if (browserEngine !== "CHROMIUM") {
61-
testInfo.skip(true, `Disabling login captcha through Chromium. This is ${browserEngine}, therefore test is skipped.`);
62-
} else {
63-
const magentoAdminPage = new MagentoAdminPage(page);
64-
await magentoAdminPage.disableLoginCaptcha();
65-
}
60+
const magentoAdminPage = new MagentoAdminPage(page);
61+
await magentoAdminPage.enableMultipleAdminLogins();
6662
});
63+
6764

6865
/**
6966
* @feature Cart Price Rules Configuration
@@ -112,4 +109,4 @@ base.describe('Setting up the testing environment', () => {
112109
true
113110
);
114111
});
115-
});
112+
});

0 commit comments

Comments
 (0)