Skip to content

Commit 13e1e46

Browse files
author
Shay
committed
Merge branch '130-new-test-spec-footer-spec-ts' into 'main'
Resolve "New test.spec: footer.spec.ts" See merge request elgentos/magento2-playwright!4
2 parents 3d6a5d2 + 72e0b7c commit 13e1e46

File tree

8 files changed

+139
-16
lines changed

8 files changed

+139
-16
lines changed

tests/cart.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import CartPage from '@poms/frontend/cart.page';
77
import LoginPage from '@poms/frontend/login.page';
88
import ProductPage from '@poms/frontend/product.page';
99
import { requireEnv } from '@utils/env.utils';
10-
import NotificationValidator from '@utils/notification.validator';
10+
import NotificationValidatorUtils from '@utils/notificationValidator.utils';
1111

1212
test.describe('Cart functionalities (guest)', () => {
1313
/**
@@ -26,8 +26,8 @@ test.describe('Cart functionalities (guest)', () => {
2626
await productPage.addSimpleProductToCart(UIReference.productPage.simpleProductTitle, slugs.productpage.simpleProductSlug);
2727

2828
const productAddedNotification = `${outcomeMarker.productPage.simpleProductAddedNotification} ${UIReference.productPage.simpleProductTitle}`;
29-
const notificationValidator = new NotificationValidator(page, testInfo);
30-
await notificationValidator.validate(productAddedNotification);
29+
const notificationValidator = new NotificationValidatorUtils(page, testInfo);
30+
await notificationValidator.validate('beforeEach add product to cart', productAddedNotification);
3131

3232
// await mainMenu.openMiniCart();
3333
// await expect(page.getByText(outcomeMarker.miniCart.simpleProductInCartTitle)).toBeVisible();

tests/config/element-identifiers.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,15 @@
149149
"customerOverviewPage": {
150150
"tableSearchFieldLabel": "Search by keyword"
151151
},
152+
"footerPage": {
153+
"footerLocator": ".page-footer",
154+
"currencyIdentifier": "#currency-heading",
155+
"currencyLabel": "Currency",
156+
"currencyDollar": "USD - US Dollar",
157+
"currencyEuro": "EUR - Euro",
158+
"newsletterInputElementLabel": "Email Address",
159+
"newsletterSubscribeButtonLabel": "Subscribe"
160+
},
152161
"general": {
153162
"addToCartLabel": "Add to Cart",
154163
"closeMessageLabel": "Close message",

tests/config/outcome-markers.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@
3939
"customerOverviewPage": {
4040
"searchResultsFoundText": "records found"
4141
},
42+
"footerPage": {
43+
"newsletterSubscription": "Thank you for your subscription.",
44+
"newsletterAlreadySubscribed": "This email address is already subscribed."
45+
},
4246
"homePage": {
4347
"firstProductName": "Aim Analog Watch"
4448
},

tests/footer.spec.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// @ts-check
2+
3+
import { test } from '@playwright/test';
4+
import { outcomeMarker } from '@config';
5+
import NotificationValidatorUtils from "@utils/notificationValidator.utils";
6+
7+
import NewsletterPage from "@poms/frontend/newsletter.page";
8+
import Footer from '@poms/frontend/footer.page';
9+
10+
test.describe('Footer', () => {
11+
12+
test(
13+
'Footer_is_available',
14+
{tag: ['@footer', '@cold']},
15+
async ({page}) => {
16+
const footer = new Footer(page);
17+
18+
await page.goto('');
19+
await footer.goToFooterElement();
20+
}
21+
)
22+
23+
test(
24+
'Footer_switch_currency',
25+
{tag: ['@footer', '@cold']},
26+
async ({page}) => {
27+
const footer = new Footer(page);
28+
29+
await page.goto('');
30+
await footer.switchCurrency();
31+
}
32+
)
33+
34+
test(
35+
'Footer_newsletter_subscription',
36+
{tag: ['@footer', '@cold']},
37+
async ({page}, testInfo) => {
38+
const newsletterPage = new NewsletterPage(page);
39+
40+
await page.goto('');
41+
await newsletterPage.footerSubscribeToNewsletter();
42+
43+
const subscriptionOutput = outcomeMarker.footerPage.newsletterSubscription;
44+
const notificationType = 'Newsletter subscription notification';
45+
46+
const notificationValidator = new NotificationValidatorUtils(page, testInfo);
47+
await notificationValidator.validate(notificationType, subscriptionOutput);
48+
}
49+
)
50+
})

tests/poms/frontend/footer.page.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// @ts-check
2+
3+
import { expect, Locator, type Page } from '@playwright/test';
4+
import { UIReference } from '@config';
5+
6+
class Footer {
7+
readonly page: Page
8+
readonly footerElement: Locator
9+
10+
11+
constructor(page: Page) {
12+
this.page = page
13+
this.footerElement = this.page.locator(UIReference.footerPage.footerLocator);
14+
}
15+
16+
async goToFooterElement () {
17+
await this.page.getByText(UIReference.footerPage.currencyLabel).scrollIntoViewIfNeeded();
18+
await expect(
19+
this.footerElement,
20+
'Footer is visible'
21+
).toBeVisible();
22+
}
23+
24+
async switchCurrency () {
25+
await this.goToFooterElement();
26+
27+
const isUsdActive = await this.page.getByRole('button', {
28+
name: UIReference.footerPage.currencyDollar
29+
}).isVisible();
30+
31+
const currencyToOpen = isUsdActive ? UIReference.footerPage.currencyDollar : UIReference.footerPage.currencyEuro;
32+
const currencyToSelect = isUsdActive ? UIReference.footerPage.currencyEuro : UIReference.footerPage.currencyDollar;
33+
34+
await this.page.getByRole('button', { name: currencyToOpen }).click();
35+
36+
await expect(
37+
this.page.getByRole('navigation', { name: UIReference.footerPage.currencyLabel }),
38+
'Footer navigation is visible'
39+
).toBeVisible();
40+
41+
await this.page.getByRole('link', { name: currencyToSelect }).click();
42+
43+
await this.goToFooterElement();
44+
45+
await expect(
46+
this.page.getByRole('button', { name: currencyToSelect }),
47+
'Currency selector is visible'
48+
).toBeVisible();
49+
}
50+
}
51+
52+
export default Footer;

tests/poms/frontend/newsletter.page.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// @ts-check
22

33
import { expect, type Locator, type Page } from '@playwright/test';
4-
import { UIReference, outcomeMarker } from '@config';
4+
import { UIReference, outcomeMarker, inputValues } from '@config';
5+
import { faker } from '@faker-js/faker'
56

67
class NewsletterSubscriptionPage {
78
readonly page: Page;
@@ -15,16 +16,15 @@ class NewsletterSubscriptionPage {
1516
}
1617

1718
async updateNewsletterSubscription(){
18-
19-
if(await this.newsletterCheckElement.isChecked()) {
20-
// user is already subscribed, test runs unsubscribe
21-
var subscriptionUpdatedNotification = outcomeMarker.account.newsletterRemovedNotification;
2219

20+
let subscriptionUpdatedNotification = outcomeMarker.account.newsletterRemovedNotification;
21+
let subscribed = false;
22+
23+
if(await this.newsletterCheckElement.isChecked()) {
24+
// user is already subscribed, test runs unsubscribe
2325
await this.newsletterCheckElement.uncheck();
2426
await this.saveSubscriptionsButton.click();
2527

26-
var subscribed = false;
27-
2828
} else {
2929
// user is not yet subscribed, test runs subscribe
3030
subscriptionUpdatedNotification = outcomeMarker.account.newsletterSavedNotification;
@@ -38,6 +38,12 @@ class NewsletterSubscriptionPage {
3838
await expect(this.page.getByText(subscriptionUpdatedNotification)).toBeVisible();
3939
return subscribed;
4040
}
41+
42+
async footerSubscribeToNewsletter() {
43+
await expect(this.page.getByRole('textbox', {name: UIReference.footerPage.newsletterInputElementLabel})).toBeVisible();
44+
await this.page.getByRole('textbox', {name: UIReference.footerPage.newsletterInputElementLabel}).fill(faker.internet.email());
45+
await this.page.getByRole('button', {name: UIReference.footerPage.newsletterSubscribeButtonLabel}).click();
46+
}
4147
}
4248

4349
export default NewsletterSubscriptionPage;

tests/poms/frontend/product.page.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import { expect, type Locator, type Page } from '@playwright/test';
44
import { UIReference, outcomeMarker, slugs } from '@config';
5-
import NotificationValidator from '@utils/notification.validator';
65

76
class ProductPage {
87
readonly page: Page;

tests/utils/notification.validator.ts renamed to tests/utils/notificationValidator.utils.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { expect, Page, TestInfo } from "@playwright/test";
44
import { UIReference } from '@config';
55

6-
class NotificationValidator {
6+
class NotificationValidatorUtils {
77

88
private page : Page;
99
private testInfo: TestInfo;
@@ -14,10 +14,11 @@ class NotificationValidator {
1414
}
1515

1616
/**
17-
* @param value (expected text on page)
17+
* @param notificationType
18+
* @param value
1819
* @return json object
1920
*/
20-
async validate(value: string) {
21+
async validate(notificationType: string, value: string) {
2122
await this.page.locator(UIReference.general.messageLocator).waitFor({ state: 'visible' });
2223
const notificationText = await this.page.locator(UIReference.general.messageLocator).textContent();
2324
let message = { success: true, message: 'Action was successful, but notification text could not be extracted.'};
@@ -34,8 +35,10 @@ class NotificationValidator {
3435
message = { success: false, message: `Notification text not found: ${value}. Found notification text: ${notificationText}` };
3536
}
3637

37-
this.testInfo.annotations.push({ type: 'Notification message on page', description: message.message });
38+
this.testInfo.annotations.push({ type: `Notification: ${notificationType}`, description: message.message });
39+
40+
return message;
3841
}
3942
}
4043

41-
export default NotificationValidator;
44+
export default NotificationValidatorUtils;

0 commit comments

Comments
 (0)