From 6a88e86ab156b971aa8fe6ac07738567fd4de8cd Mon Sep 17 00:00:00 2001 From: Dzanan91 Date: Fri, 15 Nov 2024 10:54:50 +0100 Subject: [PATCH] test: added tests for contact us page-GRS task --- package.json | 2 +- pages/contactUsPage.ts | 38 +++ pages/homePage.ts | 12 + playwright.config.ts | 10 +- support/BaseTest.ts | 5 + support/commonActions.ts | 59 +++- support/utils/randomUtils.ts | 8 + tests-examples/demo-todo-app.spec.ts | 437 --------------------------- tests/home.spec.ts | 36 ++- 9 files changed, 150 insertions(+), 457 deletions(-) create mode 100644 pages/contactUsPage.ts delete mode 100644 tests-examples/demo-todo-app.spec.ts diff --git a/package.json b/package.json index 5429452..63f9e17 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "1.0.0", "main": "index.js", "scripts": { - "test:headed": "npx playwright test --headed", + "test:headed": "npx playwright test --headed --project=Chromium", "test:headless": "npx playwright test" }, "keywords": [], diff --git a/pages/contactUsPage.ts b/pages/contactUsPage.ts new file mode 100644 index 0000000..ef02467 --- /dev/null +++ b/pages/contactUsPage.ts @@ -0,0 +1,38 @@ +import { Page,BrowserContext, Locator, FrameLocator, } from "@playwright/test"; + +export class ContactUsPage { + readonly page:Page + readonly context: BrowserContext; + + readonly firstNameInput: Locator + readonly lastNameInput: Locator + readonly emailInput: Locator + readonly commentSection: Locator + readonly submitBtn: Locator + readonly nameErrorMessage: Locator + readonly emailErrorMessage: Locator + readonly commentErrorMessage: Locator + readonly widgetElement: Locator + readonly youTubeElement: Locator + readonly iframe: FrameLocator; + + + constructor(page:Page, context: BrowserContext) { + this.page = page + this.context = context + + this.iframe = page.frameLocator('iframe[src="https://forms.zohopublic.com/giantrocketship/form/ContactUs/formperma/2GK_UjFMD9mHGNOwqNGNR4-lMvKrCQeBVRGu4FTSuY4?zf_rszfm=1&gclid=undefined"]'); + + this.firstNameInput = this.iframe.locator('input[elname="First"]'); + this.lastNameInput = this.iframe.locator('input[elname="Last"]'); + this.emailInput = this.iframe.locator('input[name="Email"]'); + this.commentSection = this.iframe.locator('textarea[id="MultiLine-arialabel"]'); + this.submitBtn = this.iframe.locator('button[elname="submit"]') + this.nameErrorMessage = this.iframe.locator('#error-Name') + this.emailErrorMessage = this.iframe.locator('#error-Email') + this.commentErrorMessage = this.iframe.locator('#error-MultiLine') + this.widgetElement = this.page.locator('div[data-widget_type="text-editor.default"] p') + this.youTubeElement = this.page.locator('div[data-settings*="youtube_url"]') + } + +} \ No newline at end of file diff --git a/pages/homePage.ts b/pages/homePage.ts index aee9911..38e94de 100644 --- a/pages/homePage.ts +++ b/pages/homePage.ts @@ -5,16 +5,28 @@ export class HomePage { readonly context: BrowserContext; readonly getStartedBtn: Locator + readonly GRSLogo: Locator + readonly navbar: { [key: string]: Locator }; constructor(page:Page, context: BrowserContext) { this.page = page this.context = context this.getStartedBtn = page.getByRole('link', {name: 'Get started'}) + this.GRSLogo = page.locator('a[href="https://giantrocketship.com"]') + this.navbar = { + Home: this.page.getByRole('link', { name: 'Home', exact: true }), + Pricing: this.page.getByRole('link', { name: 'Pricing', exact: true }), + Resources: this.page.getByRole('link', { name: 'Resources', exact: true }), + Contact: this.page.locator('a[aria-haspopup="true"]:has-text("Contact")'), + ScheduleDemo: this.page.getByRole('link', { name: 'Schedule Demo', exact: true }), + ContactUs: this.page.getByRole('link', {name: 'Contact Us', exact: true}) + }; } async goToHomePage(): Promise { await this.page.goto('/') } + } \ No newline at end of file diff --git a/playwright.config.ts b/playwright.config.ts index a70d7f2..733b216 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -38,9 +38,9 @@ export default defineConfig({ name: 'chromium', use: { browserName: 'chromium', - baseURL: 'https://playwright.dev', + baseURL: 'https://giantrocketship.com', headless: true, - viewport: { width: 1920, height: 1080 }, + viewport: { width: 2560, height: 1440 }, ignoreHTTPSErrors: true, acceptDownloads: true, screenshot: 'only-on-failure', @@ -56,7 +56,7 @@ export default defineConfig({ name: 'firefox', use: { browserName: 'firefox', - baseURL: 'https://playwright.dev', + baseURL: 'https://giantrocketship.com', headless: true, viewport: { width: 1920, height: 1080 }, ignoreHTTPSErrors: true, @@ -70,7 +70,7 @@ export default defineConfig({ name: 'webkit', use: { browserName: 'webkit', - baseURL: 'https://playwright.dev', + baseURL: 'https://giantrocketship.com', headless: true, viewport: { width: 1920, height: 1080 }, ignoreHTTPSErrors: true, @@ -85,7 +85,7 @@ export default defineConfig({ use: { browserName: 'chromium', channel: 'msedge', - baseURL: 'https://playwright.dev', + baseURL: 'https://giantrocketship.com', headless: true, viewport: { width: 1920, height: 1080 }, ignoreHTTPSErrors: true, diff --git a/support/BaseTest.ts b/support/BaseTest.ts index c9f8278..e77be68 100644 --- a/support/BaseTest.ts +++ b/support/BaseTest.ts @@ -1,14 +1,19 @@ import { test as baseTest } from '@playwright/test'; import { HomePage } from '../pages/homePage'; import { CommonActions } from './commonActions'; +import { ContactUsPage } from '../pages/contactUsPage'; const test = baseTest.extend<{ homePage: HomePage; webActions: CommonActions; + contactUsPage: ContactUsPage }>({ homePage: async ({ page,context }, use) => { await use(new HomePage(page, context)); }, + contactUsPage: async ({ page,context }, use) => { + await use(new ContactUsPage(page, context)); + }, webActions: async ({ page }, use) => { await use(new CommonActions(page)); }, diff --git a/support/commonActions.ts b/support/commonActions.ts index 85c5b6d..a315711 100644 --- a/support/commonActions.ts +++ b/support/commonActions.ts @@ -1,4 +1,4 @@ -import { Page, Locator } from '@playwright/test'; +import { Page, Locator, expect } from '@playwright/test'; export class CommonActions { private page: Page; @@ -7,18 +7,20 @@ export class CommonActions { this.page = page; } - async clickButton(locator: Locator) { - await locator.scrollIntoViewIfNeeded(); - await locator.click(); + async clickButton(locator: Locator, index: number = 0): Promise { + const element = locator.nth(index); + await element.scrollIntoViewIfNeeded(); + await element.click(); } + + async inputText(element: Locator, text: string): Promise { + await element.fill(text); + } - async inputText(selector: string, text: string) { - await this.page.locator(selector).fill(text); - } - - async isVisible(selector: string): Promise { - return await this.page.locator(selector).isVisible(); - } + async isVisible(element: Locator): Promise { + await expect(element).toBeVisible(); + return await element.isVisible(); + } async getText(selector: string): Promise { return await this.page.locator(selector).innerText(); @@ -27,4 +29,39 @@ export class CommonActions { async waitForElement(selector: string, timeout: number = 5000) { await this.page.locator(selector).waitFor({ timeout }); } + + async hoverOverElement(element: Locator): Promise { + await element.hover(); + } + + async isTextVisible(locator: Locator, expectedText: string, index: number = 0, timeout: number = 5000): Promise { + const element = locator.nth(index); + await element.waitFor({ state: 'visible', timeout }); + const actualText = await element.innerText(); + expect(actualText.trim()).toBe(expectedText.trim()); + } + + /** + * Validates the current URL. + * @param expectedUrl The expected URL or a part of the URL. + * @param matchType The type of match: 'exact' or 'contains' + */ + + async validateUrl(expectedUrl: string, matchType: 'exact' | 'contains' ) { + const currentUrl = this.page.url(); + + switch (matchType) { + case 'exact': + expect(currentUrl).toBe(expectedUrl); + break; + + case 'contains': + expect(currentUrl).toContain(expectedUrl); + break; + + default: + throw new Error(`Invalid match type: ${matchType}`); + } + } + } diff --git a/support/utils/randomUtils.ts b/support/utils/randomUtils.ts index e69de29..717efcb 100644 --- a/support/utils/randomUtils.ts +++ b/support/utils/randomUtils.ts @@ -0,0 +1,8 @@ +export function generateRandomString(length: number): string { + const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; + let result = ''; + for (let i = 0; i < length; i++) { + result += characters.charAt(Math.floor(Math.random() * characters.length)); + } + return result; +} diff --git a/tests-examples/demo-todo-app.spec.ts b/tests-examples/demo-todo-app.spec.ts deleted file mode 100644 index 8641cb5..0000000 --- a/tests-examples/demo-todo-app.spec.ts +++ /dev/null @@ -1,437 +0,0 @@ -import { test, expect, type Page } from '@playwright/test'; - -test.beforeEach(async ({ page }) => { - await page.goto('https://demo.playwright.dev/todomvc'); -}); - -const TODO_ITEMS = [ - 'buy some cheese', - 'feed the cat', - 'book a doctors appointment' -] as const; - -test.describe('New Todo', () => { - test('should allow me to add todo items', async ({ page }) => { - // create a new todo locator - const newTodo = page.getByPlaceholder('What needs to be done?'); - - // Create 1st todo. - await newTodo.fill(TODO_ITEMS[0]); - await newTodo.press('Enter'); - - // Make sure the list only has one todo item. - await expect(page.getByTestId('todo-title')).toHaveText([ - TODO_ITEMS[0] - ]); - - // Create 2nd todo. - await newTodo.fill(TODO_ITEMS[1]); - await newTodo.press('Enter'); - - // Make sure the list now has two todo items. - await expect(page.getByTestId('todo-title')).toHaveText([ - TODO_ITEMS[0], - TODO_ITEMS[1] - ]); - - await checkNumberOfTodosInLocalStorage(page, 2); - }); - - test('should clear text input field when an item is added', async ({ page }) => { - // create a new todo locator - const newTodo = page.getByPlaceholder('What needs to be done?'); - - // Create one todo item. - await newTodo.fill(TODO_ITEMS[0]); - await newTodo.press('Enter'); - - // Check that input is empty. - await expect(newTodo).toBeEmpty(); - await checkNumberOfTodosInLocalStorage(page, 1); - }); - - test('should append new items to the bottom of the list', async ({ page }) => { - // Create 3 items. - await createDefaultTodos(page); - - // create a todo count locator - const todoCount = page.getByTestId('todo-count') - - // Check test using different methods. - await expect(page.getByText('3 items left')).toBeVisible(); - await expect(todoCount).toHaveText('3 items left'); - await expect(todoCount).toContainText('3'); - await expect(todoCount).toHaveText(/3/); - - // Check all items in one call. - await expect(page.getByTestId('todo-title')).toHaveText(TODO_ITEMS); - await checkNumberOfTodosInLocalStorage(page, 3); - }); -}); - -test.describe('Mark all as completed', () => { - test.beforeEach(async ({ page }) => { - await createDefaultTodos(page); - await checkNumberOfTodosInLocalStorage(page, 3); - }); - - test.afterEach(async ({ page }) => { - await checkNumberOfTodosInLocalStorage(page, 3); - }); - - test('should allow me to mark all items as completed', async ({ page }) => { - // Complete all todos. - await page.getByLabel('Mark all as complete').check(); - - // Ensure all todos have 'completed' class. - await expect(page.getByTestId('todo-item')).toHaveClass(['completed', 'completed', 'completed']); - await checkNumberOfCompletedTodosInLocalStorage(page, 3); - }); - - test('should allow me to clear the complete state of all items', async ({ page }) => { - const toggleAll = page.getByLabel('Mark all as complete'); - // Check and then immediately uncheck. - await toggleAll.check(); - await toggleAll.uncheck(); - - // Should be no completed classes. - await expect(page.getByTestId('todo-item')).toHaveClass(['', '', '']); - }); - - test('complete all checkbox should update state when items are completed / cleared', async ({ page }) => { - const toggleAll = page.getByLabel('Mark all as complete'); - await toggleAll.check(); - await expect(toggleAll).toBeChecked(); - await checkNumberOfCompletedTodosInLocalStorage(page, 3); - - // Uncheck first todo. - const firstTodo = page.getByTestId('todo-item').nth(0); - await firstTodo.getByRole('checkbox').uncheck(); - - // Reuse toggleAll locator and make sure its not checked. - await expect(toggleAll).not.toBeChecked(); - - await firstTodo.getByRole('checkbox').check(); - await checkNumberOfCompletedTodosInLocalStorage(page, 3); - - // Assert the toggle all is checked again. - await expect(toggleAll).toBeChecked(); - }); -}); - -test.describe('Item', () => { - - test('should allow me to mark items as complete', async ({ page }) => { - // create a new todo locator - const newTodo = page.getByPlaceholder('What needs to be done?'); - - // Create two items. - for (const item of TODO_ITEMS.slice(0, 2)) { - await newTodo.fill(item); - await newTodo.press('Enter'); - } - - // Check first item. - const firstTodo = page.getByTestId('todo-item').nth(0); - await firstTodo.getByRole('checkbox').check(); - await expect(firstTodo).toHaveClass('completed'); - - // Check second item. - const secondTodo = page.getByTestId('todo-item').nth(1); - await expect(secondTodo).not.toHaveClass('completed'); - await secondTodo.getByRole('checkbox').check(); - - // Assert completed class. - await expect(firstTodo).toHaveClass('completed'); - await expect(secondTodo).toHaveClass('completed'); - }); - - test('should allow me to un-mark items as complete', async ({ page }) => { - // create a new todo locator - const newTodo = page.getByPlaceholder('What needs to be done?'); - - // Create two items. - for (const item of TODO_ITEMS.slice(0, 2)) { - await newTodo.fill(item); - await newTodo.press('Enter'); - } - - const firstTodo = page.getByTestId('todo-item').nth(0); - const secondTodo = page.getByTestId('todo-item').nth(1); - const firstTodoCheckbox = firstTodo.getByRole('checkbox'); - - await firstTodoCheckbox.check(); - await expect(firstTodo).toHaveClass('completed'); - await expect(secondTodo).not.toHaveClass('completed'); - await checkNumberOfCompletedTodosInLocalStorage(page, 1); - - await firstTodoCheckbox.uncheck(); - await expect(firstTodo).not.toHaveClass('completed'); - await expect(secondTodo).not.toHaveClass('completed'); - await checkNumberOfCompletedTodosInLocalStorage(page, 0); - }); - - test('should allow me to edit an item', async ({ page }) => { - await createDefaultTodos(page); - - const todoItems = page.getByTestId('todo-item'); - const secondTodo = todoItems.nth(1); - await secondTodo.dblclick(); - await expect(secondTodo.getByRole('textbox', { name: 'Edit' })).toHaveValue(TODO_ITEMS[1]); - await secondTodo.getByRole('textbox', { name: 'Edit' }).fill('buy some sausages'); - await secondTodo.getByRole('textbox', { name: 'Edit' }).press('Enter'); - - // Explicitly assert the new text value. - await expect(todoItems).toHaveText([ - TODO_ITEMS[0], - 'buy some sausages', - TODO_ITEMS[2] - ]); - await checkTodosInLocalStorage(page, 'buy some sausages'); - }); -}); - -test.describe('Editing', () => { - test.beforeEach(async ({ page }) => { - await createDefaultTodos(page); - await checkNumberOfTodosInLocalStorage(page, 3); - }); - - test('should hide other controls when editing', async ({ page }) => { - const todoItem = page.getByTestId('todo-item').nth(1); - await todoItem.dblclick(); - await expect(todoItem.getByRole('checkbox')).not.toBeVisible(); - await expect(todoItem.locator('label', { - hasText: TODO_ITEMS[1], - })).not.toBeVisible(); - await checkNumberOfTodosInLocalStorage(page, 3); - }); - - test('should save edits on blur', async ({ page }) => { - const todoItems = page.getByTestId('todo-item'); - await todoItems.nth(1).dblclick(); - await todoItems.nth(1).getByRole('textbox', { name: 'Edit' }).fill('buy some sausages'); - await todoItems.nth(1).getByRole('textbox', { name: 'Edit' }).dispatchEvent('blur'); - - await expect(todoItems).toHaveText([ - TODO_ITEMS[0], - 'buy some sausages', - TODO_ITEMS[2], - ]); - await checkTodosInLocalStorage(page, 'buy some sausages'); - }); - - test('should trim entered text', async ({ page }) => { - const todoItems = page.getByTestId('todo-item'); - await todoItems.nth(1).dblclick(); - await todoItems.nth(1).getByRole('textbox', { name: 'Edit' }).fill(' buy some sausages '); - await todoItems.nth(1).getByRole('textbox', { name: 'Edit' }).press('Enter'); - - await expect(todoItems).toHaveText([ - TODO_ITEMS[0], - 'buy some sausages', - TODO_ITEMS[2], - ]); - await checkTodosInLocalStorage(page, 'buy some sausages'); - }); - - test('should remove the item if an empty text string was entered', async ({ page }) => { - const todoItems = page.getByTestId('todo-item'); - await todoItems.nth(1).dblclick(); - await todoItems.nth(1).getByRole('textbox', { name: 'Edit' }).fill(''); - await todoItems.nth(1).getByRole('textbox', { name: 'Edit' }).press('Enter'); - - await expect(todoItems).toHaveText([ - TODO_ITEMS[0], - TODO_ITEMS[2], - ]); - }); - - test('should cancel edits on escape', async ({ page }) => { - const todoItems = page.getByTestId('todo-item'); - await todoItems.nth(1).dblclick(); - await todoItems.nth(1).getByRole('textbox', { name: 'Edit' }).fill('buy some sausages'); - await todoItems.nth(1).getByRole('textbox', { name: 'Edit' }).press('Escape'); - await expect(todoItems).toHaveText(TODO_ITEMS); - }); -}); - -test.describe('Counter', () => { - test('should display the current number of todo items', async ({ page }) => { - // create a new todo locator - const newTodo = page.getByPlaceholder('What needs to be done?'); - - // create a todo count locator - const todoCount = page.getByTestId('todo-count') - - await newTodo.fill(TODO_ITEMS[0]); - await newTodo.press('Enter'); - - await expect(todoCount).toContainText('1'); - - await newTodo.fill(TODO_ITEMS[1]); - await newTodo.press('Enter'); - await expect(todoCount).toContainText('2'); - - await checkNumberOfTodosInLocalStorage(page, 2); - }); -}); - -test.describe('Clear completed button', () => { - test.beforeEach(async ({ page }) => { - await createDefaultTodos(page); - }); - - test('should display the correct text', async ({ page }) => { - await page.locator('.todo-list li .toggle').first().check(); - await expect(page.getByRole('button', { name: 'Clear completed' })).toBeVisible(); - }); - - test('should remove completed items when clicked', async ({ page }) => { - const todoItems = page.getByTestId('todo-item'); - await todoItems.nth(1).getByRole('checkbox').check(); - await page.getByRole('button', { name: 'Clear completed' }).click(); - await expect(todoItems).toHaveCount(2); - await expect(todoItems).toHaveText([TODO_ITEMS[0], TODO_ITEMS[2]]); - }); - - test('should be hidden when there are no items that are completed', async ({ page }) => { - await page.locator('.todo-list li .toggle').first().check(); - await page.getByRole('button', { name: 'Clear completed' }).click(); - await expect(page.getByRole('button', { name: 'Clear completed' })).toBeHidden(); - }); -}); - -test.describe('Persistence', () => { - test('should persist its data', async ({ page }) => { - // create a new todo locator - const newTodo = page.getByPlaceholder('What needs to be done?'); - - for (const item of TODO_ITEMS.slice(0, 2)) { - await newTodo.fill(item); - await newTodo.press('Enter'); - } - - const todoItems = page.getByTestId('todo-item'); - const firstTodoCheck = todoItems.nth(0).getByRole('checkbox'); - await firstTodoCheck.check(); - await expect(todoItems).toHaveText([TODO_ITEMS[0], TODO_ITEMS[1]]); - await expect(firstTodoCheck).toBeChecked(); - await expect(todoItems).toHaveClass(['completed', '']); - - // Ensure there is 1 completed item. - await checkNumberOfCompletedTodosInLocalStorage(page, 1); - - // Now reload. - await page.reload(); - await expect(todoItems).toHaveText([TODO_ITEMS[0], TODO_ITEMS[1]]); - await expect(firstTodoCheck).toBeChecked(); - await expect(todoItems).toHaveClass(['completed', '']); - }); -}); - -test.describe('Routing', () => { - test.beforeEach(async ({ page }) => { - await createDefaultTodos(page); - // make sure the app had a chance to save updated todos in storage - // before navigating to a new view, otherwise the items can get lost :( - // in some frameworks like Durandal - await checkTodosInLocalStorage(page, TODO_ITEMS[0]); - }); - - test('should allow me to display active items', async ({ page }) => { - const todoItem = page.getByTestId('todo-item'); - await page.getByTestId('todo-item').nth(1).getByRole('checkbox').check(); - - await checkNumberOfCompletedTodosInLocalStorage(page, 1); - await page.getByRole('link', { name: 'Active' }).click(); - await expect(todoItem).toHaveCount(2); - await expect(todoItem).toHaveText([TODO_ITEMS[0], TODO_ITEMS[2]]); - }); - - test('should respect the back button', async ({ page }) => { - const todoItem = page.getByTestId('todo-item'); - await page.getByTestId('todo-item').nth(1).getByRole('checkbox').check(); - - await checkNumberOfCompletedTodosInLocalStorage(page, 1); - - await test.step('Showing all items', async () => { - await page.getByRole('link', { name: 'All' }).click(); - await expect(todoItem).toHaveCount(3); - }); - - await test.step('Showing active items', async () => { - await page.getByRole('link', { name: 'Active' }).click(); - }); - - await test.step('Showing completed items', async () => { - await page.getByRole('link', { name: 'Completed' }).click(); - }); - - await expect(todoItem).toHaveCount(1); - await page.goBack(); - await expect(todoItem).toHaveCount(2); - await page.goBack(); - await expect(todoItem).toHaveCount(3); - }); - - test('should allow me to display completed items', async ({ page }) => { - await page.getByTestId('todo-item').nth(1).getByRole('checkbox').check(); - await checkNumberOfCompletedTodosInLocalStorage(page, 1); - await page.getByRole('link', { name: 'Completed' }).click(); - await expect(page.getByTestId('todo-item')).toHaveCount(1); - }); - - test('should allow me to display all items', async ({ page }) => { - await page.getByTestId('todo-item').nth(1).getByRole('checkbox').check(); - await checkNumberOfCompletedTodosInLocalStorage(page, 1); - await page.getByRole('link', { name: 'Active' }).click(); - await page.getByRole('link', { name: 'Completed' }).click(); - await page.getByRole('link', { name: 'All' }).click(); - await expect(page.getByTestId('todo-item')).toHaveCount(3); - }); - - test('should highlight the currently applied filter', async ({ page }) => { - await expect(page.getByRole('link', { name: 'All' })).toHaveClass('selected'); - - //create locators for active and completed links - const activeLink = page.getByRole('link', { name: 'Active' }); - const completedLink = page.getByRole('link', { name: 'Completed' }); - await activeLink.click(); - - // Page change - active items. - await expect(activeLink).toHaveClass('selected'); - await completedLink.click(); - - // Page change - completed items. - await expect(completedLink).toHaveClass('selected'); - }); -}); - -async function createDefaultTodos(page: Page) { - // create a new todo locator - const newTodo = page.getByPlaceholder('What needs to be done?'); - - for (const item of TODO_ITEMS) { - await newTodo.fill(item); - await newTodo.press('Enter'); - } -} - -async function checkNumberOfTodosInLocalStorage(page: Page, expected: number) { - return await page.waitForFunction(e => { - return JSON.parse(localStorage['react-todos']).length === e; - }, expected); -} - -async function checkNumberOfCompletedTodosInLocalStorage(page: Page, expected: number) { - return await page.waitForFunction(e => { - return JSON.parse(localStorage['react-todos']).filter((todo: any) => todo.completed).length === e; - }, expected); -} - -async function checkTodosInLocalStorage(page: Page, title: string) { - return await page.waitForFunction(t => { - return JSON.parse(localStorage['react-todos']).map((todo: any) => todo.title).includes(t); - }, title); -} diff --git a/tests/home.spec.ts b/tests/home.spec.ts index be8de69..15f2fdf 100644 --- a/tests/home.spec.ts +++ b/tests/home.spec.ts @@ -1,4 +1,5 @@ import {test} from '../support/BaseTest' +import { generateRandomString } from '../support/utils/randomUtils' test.describe('Home page tests', () => { @@ -8,9 +9,38 @@ test.describe('Home page tests', () => { }); }); - test('Navigate to get started page', async ({homePage, webActions}) =>{ - await test.step('Click on Get Started button', async () => { - await webActions.clickButton(homePage.getStartedBtn) + test('Validate Contact Us form', async ({ homePage, webActions, baseURL, contactUsPage }) =>{ + await test.step('Validate URL is correct', async () => { + await webActions.validateUrl(`${baseURL}/`, 'exact') + }) + await test.step('Validate logo is correct and visible', async () => { + await webActions.isVisible(homePage.GRSLogo) + }) + await test.step('Open Contact Us form', async () => { + await webActions.clickButton(homePage.navbar.Contact) + await webActions.clickButton(homePage.navbar.ContactUs) + }) + await test.step('Validate error message when filling only name', async () => { + await webActions.inputText(contactUsPage.firstNameInput, generateRandomString(5) + 'First') + await webActions.inputText(contactUsPage.lastNameInput, generateRandomString(5) + 'Last') + await webActions.clickButton(contactUsPage.submitBtn) + await webActions.isTextVisible(contactUsPage.emailErrorMessage, 'Enter a value for this field.') + }) + await test.step('Validate error message when filling only name and email', async () => { + await webActions.inputText(contactUsPage.firstNameInput, generateRandomString(5) + 'First') + await webActions.inputText(contactUsPage.lastNameInput, generateRandomString(5) + 'Last') + await webActions.inputText(contactUsPage.emailInput, generateRandomString(10) + '@test.com') + await webActions.clickButton(contactUsPage.submitBtn) + await webActions.isTextVisible(contactUsPage.commentErrorMessage, 'Enter a value for this field.') + }) + await test.step('Validate success message when filling Fill name, email and comment', async () => { + await webActions.inputText(contactUsPage.firstNameInput, generateRandomString(5) + 'Last') + await webActions.inputText(contactUsPage.lastNameInput, generateRandomString(5) + 'Last') + await webActions.inputText(contactUsPage.emailInput, generateRandomString(10) + '@test.com') + await webActions.inputText(contactUsPage.commentSection, generateRandomString(10) + 'Test comment') + await webActions.clickButton(contactUsPage.submitBtn) + await webActions.isVisible(contactUsPage.youTubeElement) + await webActions.isTextVisible(contactUsPage.widgetElement, 'Your details have been submitted.') }) }) })