Skip to content

Commit 77e9783

Browse files
authored
Merge pull request #173 from Progi1984/foContactUsPage
Migrate `@pages/FO/{classic|hummingbird}/contactUs` from Core
2 parents 0007aa0 + 9b258b1 commit 77e9783

File tree

6 files changed

+221
-0
lines changed

6 files changed

+221
-0
lines changed

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ export {default as foClassicCartPage} from '@pages/FO/classic/cart';
263263
export {default as foClassicCategoryPage} from '@pages/FO/classic/category';
264264
export {default as foClassicCheckoutPage} from '@pages/FO/classic/checkout';
265265
export {default as foClassicCheckoutOrderConfirmationPage} from '@pages/FO/classic/checkout/orderConfirmation';
266+
export {default as foClassicContactUsPage} from '@pages/FO/classic/contactUs';
266267
export {default as foClassicEmailSubscriptionPage} from '@pages/FO/classic/emailSubscription';
267268
export {default as foClassicHomePage} from '@pages/FO/classic/home';
268269
export {default as foClassicLoginPage} from '@pages/FO/classic/login';
@@ -281,6 +282,7 @@ export {default as foHummingbirdCartPage} from '@pages/FO/hummingbird/cart';
281282
export {default as foHummingbirdCategoryPage} from '@pages/FO/hummingbird/category';
282283
export {default as foHummingbirdCheckoutPage} from '@pages/FO/hummingbird/checkout';
283284
export {default as foHummingbirdCheckoutOrderConfirmationPage} from '@pages/FO/hummingbird/checkout/orderConfirmation';
285+
export {default as foHummingbirdContactUsPage} from '@pages/FO/hummingbird/contactUs';
284286
export {default as foHummingbirdHomePage} from '@pages/FO/hummingbird/home';
285287
export {default as foHummingbirdLoginPage} from '@pages/FO/hummingbird/login';
286288
export {default as foHummingbirdModalQuickViewPage} from '@pages/FO/hummingbird/modal/quickView';
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import type FakerContactMessage from '@data/faker/contactMessage';
2+
import {FOBasePagePageInterface} from '@interfaces/FO';
3+
import {type Page} from '@playwright/test';
4+
5+
export interface FoContactUsPageInterface extends FOBasePagePageInterface {
6+
readonly badFileExtensionErrorMessage: string;
7+
readonly invalidContent: string;
8+
readonly invalidEmail: string;
9+
readonly pageTitle: string;
10+
readonly validationMessage: string;
11+
12+
getAlertError(page: Page): Promise<string>;
13+
getAlertSuccess(page: Page): Promise<string>;
14+
getEmailFieldValue(page: Page): Promise<string>;
15+
getEmailUsLink(page: Page): Promise<string>;
16+
getGDPRLabel(page: Page): Promise<string>;
17+
hasGDPRLabel(page: Page): Promise<boolean>;
18+
isAttachmentInputVisible(page: Page): Promise<boolean>;
19+
sendMessage(page: Page, contactUsData: FakerContactMessage, file?: string|null): Promise<void>;
20+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type {FoContactUsPageInterface} from '@interfaces/FO/contactUs';
2+
3+
/* eslint-disable global-require, @typescript-eslint/no-var-requires */
4+
function requirePage(): FoContactUsPageInterface {
5+
return require('@versions/develop/pages/FO/classic/contactUs').foContactUsPage;
6+
}
7+
/* eslint-enable global-require, @typescript-eslint/no-var-requires */
8+
9+
export default requirePage();
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type {FoContactUsPageInterface} from '@interfaces/FO/contactUs';
2+
3+
/* eslint-disable global-require, @typescript-eslint/no-var-requires */
4+
function requirePage(): FoContactUsPageInterface {
5+
return require('@versions/develop/pages/FO/hummingbird/contactUs');
6+
}
7+
/* eslint-enable global-require, @typescript-eslint/no-var-requires */
8+
9+
export default requirePage();
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
import type FakerContactMessage from '@data/faker/contactMessage';
2+
import {type FoContactUsPageInterface} from '@interfaces/FO/contactUs';
3+
import FOBasePage from '@pages/FO/FOBasePage';
4+
import type {Page} from '@playwright/test';
5+
6+
/**
7+
* Contact us page, contains functions that can be used on the page
8+
* @class
9+
* @extends FOBasePage
10+
*/
11+
class FoContactUsPage extends FOBasePage implements FoContactUsPageInterface {
12+
public readonly pageTitle: string;
13+
14+
public readonly validationMessage: string;
15+
16+
public readonly invalidEmail: string;
17+
18+
public readonly invalidContent: string;
19+
20+
public readonly badFileExtensionErrorMessage: string;
21+
22+
private readonly emailUsLink: string;
23+
24+
private readonly subjectSelect: string;
25+
26+
private readonly emailAddressInput: string;
27+
28+
protected attachmentLabel: string;
29+
30+
private readonly orderReferenceSelect: string;
31+
32+
private readonly messageTextarea: string;
33+
34+
private readonly gdprLabel: string;
35+
36+
private readonly sendButton: string;
37+
38+
private readonly alertSuccessDiv: string;
39+
40+
private readonly alertDangerTextBlock: string;
41+
42+
/**
43+
* @constructs
44+
* Setting up texts and selectors to use on contact us page
45+
*/
46+
constructor(theme: string = 'classic') {
47+
super(theme);
48+
49+
this.pageTitle = 'Contact us';
50+
this.validationMessage = 'Your message has been successfully sent to our team.';
51+
this.invalidEmail = 'Invalid email address.';
52+
this.invalidContent = 'The message cannot be blank.';
53+
this.badFileExtensionErrorMessage = 'Bad file extension';
54+
55+
// Left column selectors
56+
this.emailUsLink = '#left-column a';
57+
58+
// Form selectors
59+
this.subjectSelect = '#content select[name=\'id_contact\']';
60+
this.emailAddressInput = '#content input[name=\'from\']';
61+
this.attachmentLabel = '#file-upload'; // input[name="fileUpload"]
62+
this.orderReferenceSelect = 'select[name=id_order]';
63+
this.messageTextarea = '#content textarea[name=\'message\']';
64+
this.gdprLabel = '#content .gdpr_consent label.psgdpr_consent_message span:nth-of-type(2)';
65+
this.sendButton = '#content input[name=\'submitMessage\']';
66+
this.alertSuccessDiv = '#content div.alert-success';
67+
this.alertDangerTextBlock = '#content div.alert-danger';
68+
}
69+
70+
/*
71+
Methods
72+
*/
73+
/**
74+
* Get email us link href
75+
* @param page {Page} Browser tab
76+
* @returns {Promise<string>}
77+
*/
78+
async getEmailUsLink(page: Page): Promise<string> {
79+
return this.getAttributeContent(page, this.emailUsLink, 'href');
80+
}
81+
82+
/**
83+
* Send message
84+
* @param page {Page} Browser tab
85+
* @param contactUsData {FakerContactMessage} The data for fill the form
86+
* @param file {string|null} The path of the file to upload
87+
* @returns {Promise<void>}
88+
*/
89+
async sendMessage(page: Page, contactUsData: FakerContactMessage, file: string|null = null): Promise<void> {
90+
await this.selectByVisibleText(page, this.subjectSelect, contactUsData.subject);
91+
await this.setValue(page, this.emailAddressInput, contactUsData.emailAddress);
92+
93+
if (file) {
94+
await this.uploadFile(page, this.attachmentLabel, file);
95+
}
96+
97+
if (contactUsData.reference) {
98+
await this.selectByVisibleText(page, this.orderReferenceSelect, contactUsData.reference);
99+
}
100+
101+
await this.setValue(page, this.messageTextarea, contactUsData.message);
102+
await page.locator(this.sendButton).click();
103+
}
104+
105+
/**
106+
* Get login error
107+
* @param page {Page} Browser tab
108+
* @return {Promise<string>}
109+
*/
110+
async getAlertSuccess(page: Page): Promise<string> {
111+
return this.getTextContent(page, this.alertSuccessDiv);
112+
}
113+
114+
/**
115+
* Get login error
116+
* @param page {Page} Browser tab
117+
* @return {Promise<string>}
118+
*/
119+
async getAlertError(page: Page): Promise<string> {
120+
return this.getTextContent(page, this.alertDangerTextBlock);
121+
}
122+
123+
/**
124+
* Get and return the content of the email input
125+
* @param page {Page} Browser tab
126+
* @returns {Promise<string>}
127+
*/
128+
async getEmailFieldValue(page: Page): Promise<string> {
129+
return this.getAttributeContent(page, this.emailAddressInput, 'value');
130+
}
131+
132+
/**
133+
* Check if attachment input is visible
134+
* @param page {Page} Browser tab
135+
* @returns {Promise<boolean>}
136+
*/
137+
async isAttachmentInputVisible(page: Page): Promise<boolean> {
138+
return this.elementVisible(page, this.attachmentLabel, 1000);
139+
}
140+
141+
/**
142+
* Return if the GDPR field is present
143+
* @param page {Page} Browser tab
144+
* @returns {Promise<boolean>}
145+
*/
146+
async hasGDPRLabel(page: Page): Promise<boolean> {
147+
return await page.locator(this.gdprLabel).count() !== 0;
148+
}
149+
150+
/**
151+
* Return the label for the GDPR field
152+
* @param page {Page} Browser tab
153+
* @returns {Promise<string>}
154+
*/
155+
async getGDPRLabel(page: Page): Promise<string> {
156+
return this.getTextContent(page, this.gdprLabel);
157+
}
158+
}
159+
160+
const foContactUsPage = new FoContactUsPage();
161+
export {foContactUsPage, FoContactUsPage};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import {type FoContactUsPageInterface} from '@interfaces/FO/contactUs';
2+
import {FoContactUsPage as FoContactUsPageVersion} from '@versions/develop/pages/FO/classic/contactUs';
3+
4+
/**
5+
* Contact Us page, contains functions that can be used on the page
6+
* @class
7+
* @extends FOBasePage
8+
*/
9+
class FoContactUsPage extends FoContactUsPageVersion implements FoContactUsPageInterface {
10+
/**
11+
* @constructs
12+
*/
13+
constructor() {
14+
super('hummingbird');
15+
16+
this.attachmentLabel = 'input[name="fileUpload"]';
17+
}
18+
}
19+
20+
module.exports = new FoContactUsPage();

0 commit comments

Comments
 (0)