|
| 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}; |
0 commit comments