Skip to content

Commit 62ec0aa

Browse files
author
Myron van Velsen
committed
Merge branch '275-magentoadmin-page-ts-splitsen' into 'main'
Resolve "magentoAdmin.page.ts splitsen" See merge request elgentos/magento2-playwright!51
2 parents dd83fea + 35389d2 commit 62ec0aa

File tree

8 files changed

+603
-378
lines changed

8 files changed

+603
-378
lines changed

tests/config/element-identifiers.json

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,44 @@
1818
"address" : {
1919
"addressBookTitle" : "Address Book"
2020
},
21+
"adminGeneral": {
22+
"tableSearchFieldLabel": "Search by keyword",
23+
"loadingSpinnerLocator": "#container .spinner",
24+
"searchButtonLabel": "Search"
25+
},
26+
"adminCustomers": {
27+
"createNewCustomerButtonLabel": "Add New Customer",
28+
"edit": {
29+
"passwordFieldLabel": "Enter Password"
30+
},
31+
"registration": {
32+
"debtorNumberFieldLabel": "Debtor number",
33+
"allowBulkPurchaseFieldLabel": "Allow bulk purchase",
34+
"createAccountSaveButtonLabel": "Save Customer",
35+
"createAccountSaveAndContinueButtonLabel": "Save and Continue Edit"
36+
}
37+
},
38+
"adminPage": {
39+
"captchaIncorrectText" : "Incorrect CAPTCHA.",
40+
"couponSearchFieldLocator" : "#promo_quote_grid_filter_coupon_code",
41+
"dashboardHeadingText": "Dashboard",
42+
"loginButtonLabel": "Sign In",
43+
"navigation": {
44+
"customersButtonLabel": "Customers",
45+
"marketingButtonLabel": "Marketing",
46+
"storesButtonLabel": "Stores",
47+
"salesButtonLabel": "Sales"
48+
},
49+
"passwordFieldLabel": "Password",
50+
"searchResultsText" : "records found",
51+
"subNavigation": {
52+
"allCustomersButtonLabel": "All Customers",
53+
"cartPriceRulesButtonLabel": "Cart Price Rules",
54+
"configurationButtonLabel": "Configuration",
55+
"ordersButtonLabel": "Orders"
56+
},
57+
"usernameFieldLabel": "Username"
58+
},
2159
"newAddress": {
2260
"addNewAddressTitle": "Add New Address",
2361
"cityNameLabel": "City",
@@ -190,25 +228,6 @@
190228
"homePage": {
191229
"homePageTitleText": "Hyvä Themes"
192230
},
193-
"magentoAdminPage": {
194-
"captchaIncorrectText" : "Incorrect CAPTCHA.",
195-
"couponSearchFieldLocator" : "#promo_quote_grid_filter_coupon_code",
196-
"dashboardHeadingText": "Dashboard",
197-
"loginButtonLabel": "Sign In",
198-
"navigation": {
199-
"customersButtonLabel": "Customers",
200-
"marketingButtonLabel": "Marketing",
201-
"storesButtonLabel": "Stores"
202-
},
203-
"passwordFieldLabel": "Password",
204-
"searchResultsText" : "records found",
205-
"subNavigation": {
206-
"allCustomersButtonLabel": "All Customers",
207-
"cartPriceRulesButtonLabel": "Cart Price Rules",
208-
"configurationButtonLabel": "Configuration"
209-
},
210-
"usernameFieldLabel": "Username"
211-
},
212231
"mainMenu": {
213232
"addressBookButtonLabel" : "Address Book",
214233
"createAccountButtonLabel" : "Create an Account",

tests/config/outcome-markers.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
"addressDeletedNotification": "You deleted the address.",
1515
"newAddressAddedNotifcation": "You saved the address."
1616
},
17+
"adminGeneral": {
18+
"searchResultsFoundText": "records found"
19+
},
1720
"cart": {
1821
"discountAppliedNotification": "You used coupon code",
1922
"discountRemovedNotification": "You canceled the coupon code.",
@@ -30,7 +33,7 @@
3033
"couponRemovedNotification": "Your coupon was successfully removed",
3134
"incorrectDiscountNotification": "The coupon code isn't valid. Verify the code and try again.",
3235
"orderPlacedNotification": "Thank you for your purchase!",
33-
"orderPlacedNumberText": "Your order number is"
36+
"orderPlacedNumberText": "Your order number is:"
3437
},
3538
"comparePage": {
3639
"productRemovedNotificationTextOne": "You removed product",
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
// @ts-check
2+
3+
import { expect, type Locator, type Page } from '@playwright/test';
4+
import { UIReference, inputValues, outcomeMarker } from '@config';
5+
import { requireEnv } from "@utils/env.utils";
6+
7+
class AdminCustomers {
8+
readonly page: Page;
9+
10+
constructor(page: Page) {
11+
this.page = page;
12+
}
13+
14+
/**
15+
* @feature Customer Management
16+
* @scenario Check if a customer exists by email address
17+
* @given the admin is on the Magento dashboard
18+
* @when the admin navigates to Customers > All Customers
19+
* @and the customer table is fully loaded
20+
* @and the admin searches for a specific email address
21+
* @then the system returns whether a customer with that email exists in the customer list
22+
*/
23+
async checkIfCustomerExists(email: string){
24+
const mainMenuCustomersButton = this.page.getByRole('link', {name: UIReference.adminPage.navigation.customersButtonLabel}).first();
25+
const allCustomersLink = this.page.getByRole('link', {name: UIReference.adminPage.subNavigation.allCustomersButtonLabel});
26+
const customersSearchField = this.page.getByRole('textbox', {name: UIReference.customerOverviewPage.tableSearchFieldLabel});
27+
28+
// loop clicking the 'Customers' button until clicking it show the subnavigation
29+
await expect(async() =>{
30+
await mainMenuCustomersButton.press('Enter');
31+
await expect(allCustomersLink, `Link to "All Customers" is visible`).toBeVisible({timeout: 5000});
32+
}).toPass();
33+
34+
await allCustomersLink.click();
35+
36+
// Wait for URL. If loading symbol is visible, wait for it to go away
37+
await this.page.waitForURL(`**/${requireEnv('MAGENTO_ADMIN_SLUG')}/customer/index/**`);
38+
if (await this.page.locator(UIReference.general.loadingSpinnerLocator).isVisible()) {
39+
await this.page.locator(UIReference.general.loadingSpinnerLocator).waitFor({state: 'hidden'});
40+
}
41+
42+
await customersSearchField.waitFor();
43+
await customersSearchField.fill(email);
44+
await this.page.getByRole('button', {name: UIReference.general.searchButtonLabel}).click();
45+
46+
47+
if (await this.page.locator(UIReference.general.loadingSpinnerLocator).isVisible()) {
48+
await this.page.locator(UIReference.general.loadingSpinnerLocator).waitFor({state: 'hidden'});
49+
}
50+
51+
// Loop to ensure the 'results found' text is visible
52+
await expect(async() =>{
53+
await this.page.getByText(outcomeMarker.customerOverviewPage.searchResultsFoundText).first();
54+
}).toPass();
55+
56+
// Return true (email found) or false (email not found)
57+
return await this.page.getByRole('cell', {name:email}).locator('div').isVisible();
58+
}
59+
60+
/**
61+
* @feature Customer Management
62+
* @scenario Create a new customer account
63+
* @given the admin is on the Magento dashboard
64+
* @when the admin navigates to Customers > All Customers
65+
* @and clicks the 'Create New Customer' button
66+
* @then the admin fills in the mandatory fields and optional fields for a new customer account
67+
* @and the system saves the customer account and navigates to the account edit page
68+
* @and displays a confirmation message that the customer was saved
69+
*/
70+
async createNewCustomerAccount(
71+
firstName: string,
72+
lastName: string,
73+
email: string
74+
) {
75+
const createNewCustomersLink = this.page.getByRole('button', {name: UIReference.adminCustomers.createNewCustomerButtonLabel});
76+
await createNewCustomersLink.click();
77+
78+
// Wait for URL. If loading symbol is visible, wait for it to go away
79+
await this.page.waitForURL(`**/${requireEnv('MAGENTO_ADMIN_SLUG')}/customer/index/new/**`);
80+
if (await this.page.locator(UIReference.adminGeneral.loadingSpinnerLocator).isVisible()) {
81+
await this.page.locator(UIReference.adminGeneral.loadingSpinnerLocator).waitFor({state: 'hidden'});
82+
}
83+
84+
const accountCreationFirstNameField = this.page.getByLabel(UIReference.personalInformation.firstNameLabel);
85+
const accountCreationLastNameField = this.page.getByLabel(UIReference.personalInformation.lastNameLabel);
86+
const accountCreationEmailField = this.page.getByLabel(UIReference.credentials.emailFieldLabel, { exact: true});
87+
const accountCreationConfirmButton = this.page.getByRole('button', {name: UIReference.adminCustomers.registration.createAccountSaveAndContinueButtonLabel});
88+
const customersSearchField = this.page.getByRole('textbox', {name: UIReference.adminGeneral.tableSearchFieldLabel});
89+
90+
// Optional fields:
91+
const allowBulkPurchaseSwitcher = this.page.locator(UIReference.cartPriceRulesPage.activeStatusSwitcherLocator).first();
92+
93+
await accountCreationFirstNameField.fill(firstName);
94+
await accountCreationLastNameField.fill(lastName);
95+
await accountCreationEmailField.fill(email);
96+
await allowBulkPurchaseSwitcher.click();
97+
await accountCreationConfirmButton.click();
98+
99+
await this.page.waitForURL(`**/${requireEnv('MAGENTO_ADMIN_SLUG')}/customer/index/edit/**`);
100+
if (await this.page.locator(UIReference.adminGeneral.loadingSpinnerLocator).isVisible()) {
101+
await this.page.locator(UIReference.adminGeneral.loadingSpinnerLocator).waitFor({state: 'hidden'});
102+
103+
await expect(
104+
this.page.locator(UIReference.general.messageLocator).filter({hasText: 'You saved the customer.'})
105+
).toBeVisible();
106+
}
107+
108+
await this.approveAccount(email);
109+
}
110+
111+
/**
112+
* @feature Customer Management
113+
* @scenario Approve a customer account
114+
* @given the admin is on the Magento dashboard
115+
* @when the admin navigates to Customers > All Customers
116+
* @and searches for a specific email address
117+
* @then the admin clicks on the 'Edit' link for the corresponding customer
118+
* @and approves the customer account
119+
* @and the system displays a confirmation message that the customer account has been approved
120+
*/
121+
async approveAccount(email: string) {
122+
123+
const customersSearchField = this.page.getByRole('textbox', {name: UIReference.adminGeneral.tableSearchFieldLabel});
124+
const editAccountButton = this.page.getByRole('link', {name: 'Edit'}).first()
125+
const approvalButtonAccountEdit = this.page.getByRole('button', {name: 'Approve'})
126+
127+
await customersSearchField.waitFor();
128+
await customersSearchField.fill(email);
129+
await this.page.getByRole('button', {name: UIReference.adminGeneral.searchButtonLabel}).click();
130+
131+
if (await this.page.locator(UIReference.adminGeneral.loadingSpinnerLocator).isVisible()) {
132+
await this.page.locator(UIReference.adminGeneral.loadingSpinnerLocator).waitFor({state: 'hidden'});
133+
}
134+
135+
// Loop to ensure the 'results found' text is visible
136+
await expect(async() =>{
137+
await this.page.getByText(outcomeMarker.customerOverviewPage.searchResultsFoundText).first();
138+
}).toPass();
139+
140+
// Return true (email found) or false (email not found)
141+
await this.page.getByRole('cell', {name:email}).locator('div').isVisible();
142+
143+
await expect(async() => {
144+
editAccountButton.click();
145+
}).toPass();
146+
147+
await this.page.waitForURL(`**/${requireEnv('MAGENTO_ADMIN_SLUG')}/customer/index/edit/**`);
148+
if (await this.page.locator(UIReference.general.loadingSpinnerLocator).isVisible()) {
149+
console.log('Spinner is visible');
150+
await this.page.locator(UIReference.general.loadingSpinnerLocator).waitFor({state: 'hidden'});
151+
}
152+
153+
// Press approval button when approval button is visible
154+
if (await approvalButtonAccountEdit.isVisible()) {
155+
await approvalButtonAccountEdit.click();
156+
157+
await this.page.waitForURL(`**/${requireEnv('MAGENTO_ADMIN_SLUG')}/customer/index/edit/**`);
158+
if (await this.page.locator(UIReference.general.loadingSpinnerLocator).isVisible()) {
159+
console.log('Spinner is visible');
160+
await this.page.locator(UIReference.general.loadingSpinnerLocator).waitFor({state: 'hidden'});
161+
}
162+
await expect(
163+
this.page
164+
.locator(UIReference.general.messageLocator)
165+
.filter({ hasText: 'Customer account has been approved!' })
166+
).toBeVisible();
167+
}
168+
}
169+
}
170+
171+
export default AdminCustomers;

0 commit comments

Comments
 (0)