From 65d7f704ef7add2e565958af2c5de40d8aea1543 Mon Sep 17 00:00:00 2001 From: Tariq Alshwaiki <99204465+alshwaikit@users.noreply.github.com> Date: Thu, 21 Mar 2024 14:35:51 -0500 Subject: [PATCH] test: added playwright homepage --- .gitignore | 6 +++- e2e/homepage.spec.js | 40 ++++++++++++++++++++++ package-lock.json | 67 +++++++++++++++++++++++++++++++++++-- package.json | 2 ++ playwright.config.js | 79 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 190 insertions(+), 4 deletions(-) create mode 100644 e2e/homepage.spec.js create mode 100644 playwright.config.js diff --git a/.gitignore b/.gitignore index 24337287d8..3aaf4b3938 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,8 @@ coverage *.log # output of build-storybook for chromatic usage -storybook-static \ No newline at end of file +storybook-static +/test-results/ +/playwright-report/ +/blob-report/ +/playwright/.cache/ diff --git a/e2e/homepage.spec.js b/e2e/homepage.spec.js new file mode 100644 index 0000000000..2af9c81974 --- /dev/null +++ b/e2e/homepage.spec.js @@ -0,0 +1,40 @@ +// @ts-check +const { test, expect } = require('@playwright/test'); + +test('signUp', async ({ page }) => { + await page.goto('https://themesinternal-the-gazette-dev.web.arc-cdn.net/All-blocks-qa/'); + await page.goto('https://themesinternal-the-gazette-dev.web.arc-cdn.net/account/signup/'); + await page.getByLabel('Email address').click(); + await page.getByLabel('Email address').fill('qa1.test@gmail.com'); + await page.getByLabel('Password', { exact: true }).click(); + await page.getByLabel('Password', { exact: true }).fill('Qatest@123456'); + await page.getByLabel('Confirm password').click(); + await page.getByLabel('Confirm password').fill('Qatest@123456'); + await page.getByRole('button', { name: 'Sign Up' }).click(); +}); + +test('log in', async ({ page }) => { + await page.goto('https://themesinternal-the-gazette-dev.web.arc-cdn.net/All-blocks-qa/'); + await page.goto('https://themesinternal-the-gazette-dev.web.arc-cdn.net/account/login/'); + await page.getByLabel('Email address').click(); + await page.getByLabel('Email address').fill('qa1.test@gmail.com'); + await page.getByLabel('Password').click(); + await page.getByLabel('Password').fill('Qatest@123456'); + await page.getByRole('button', { name: 'Log In' }).click(); +}); + +test('section search bar', async ({ page }) => { + await page.goto('https://themesinternal-the-gazette-dev.web.arc-cdn.net/All-blocks-qa/'); + await page.getByTestId('nav-chain-nav-components-desktop-left').getByTestId('nav-chain-nav-section-button').click(); + await page.getByTestId('nav-chain-nav-components-desktop').getByPlaceholder('Search').click(); + await page.getByTestId('nav-chain-nav-components-desktop').getByPlaceholder('Search').fill('sport'); + await page.getByTestId('nav-chain-nav-components-desktop').getByPlaceholder('Search').press('Enter'); + await page.goto('https://themesinternal-the-gazette-dev.web.arc-cdn.net/All-blocks-qa/'); +}); + +test('section drop down', async ({ page }) => { + await page.goto('https://themesinternal-the-gazette-dev.web.arc-cdn.net/All-blocks-qa/'); + await page.getByTestId('nav-chain-nav-components-desktop-left').getByTestId('nav-chain-nav-section-button').click(); + await page.locator('#flyout-overlay').getByRole('link', { name: 'News' }).click(); + await page.goto('https://themesinternal-the-gazette-dev.web.arc-cdn.net/All-blocks-qa/'); +}); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 3bdb70af05..d7e5d14103 100644 --- a/package-lock.json +++ b/package-lock.json @@ -94,6 +94,7 @@ "@babel/preset-env": "^7.23.2", "@babel/preset-react": "^7.22.15", "@etchteam/storybook-addon-css-variables-theme": "^1.5.1", + "@playwright/test": "^1.42.1", "@storybook/addon-a11y": "^7.5.1", "@storybook/addon-docs": "^7.5.1", "@storybook/addon-essentials": "^7.5.1", @@ -103,6 +104,7 @@ "@stripe/stripe-js": "^2.1.9", "@testing-library/jest-dom": "^6.1.4", "@testing-library/react": "^14.0.0", + "@types/node": "^20.11.30", "@wpmedia/arc-themes-components": "arc-themes-release-version-2.3.0", "algoliasearch": "^4.20.0", "babel-jest": "^29.7.0", @@ -5973,6 +5975,21 @@ "node": ">=14" } }, + "node_modules/@playwright/test": { + "version": "1.42.1", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.42.1.tgz", + "integrity": "sha512-Gq9rmS54mjBL/7/MvBaNOBwbfnh7beHvS6oS4srqXFcQHpQCV1+c8JXWE8VLPyRDhgS3H8x8A7hztqI9VnwrAQ==", + "dev": true, + "dependencies": { + "playwright": "1.42.1" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=16" + } + }, "node_modules/@radix-ui/number": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/@radix-ui/number/-/number-1.0.1.tgz", @@ -8117,9 +8134,9 @@ "dev": true }, "node_modules/@types/node": { - "version": "20.11.19", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.11.19.tgz", - "integrity": "sha512-7xMnVEcZFu0DikYjWOlRq7NTPETrm7teqUT2WkQjrTIkEgUyyGdWsj/Zg8bEJt5TNklzbPD1X3fqfsHw3SpapQ==", + "version": "20.11.30", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.11.30.tgz", + "integrity": "sha512-dHM6ZxwlmuZaRmUPfv1p+KrdD1Dci04FbdEm/9wEMouFqxYoFl5aMkt0VMAUtYRQDyYvD41WJLukhq/ha3YuTw==", "dev": true, "dependencies": { "undici-types": "~5.26.4" @@ -22657,6 +22674,50 @@ "node": ">=4" } }, + "node_modules/playwright": { + "version": "1.42.1", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.42.1.tgz", + "integrity": "sha512-PgwB03s2DZBcNRoW+1w9E+VkLBxweib6KTXM0M3tkiT4jVxKSi6PmVJ591J+0u10LUrgxB7dLRbiJqO5s2QPMg==", + "dev": true, + "dependencies": { + "playwright-core": "1.42.1" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=16" + }, + "optionalDependencies": { + "fsevents": "2.3.2" + } + }, + "node_modules/playwright-core": { + "version": "1.42.1", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.42.1.tgz", + "integrity": "sha512-mxz6zclokgrke9p1vtdy/COWBH+eOZgYUVVU34C73M+4j4HLlQJHtfcqiqqxpP0o8HhMkflvfbquLX5dg6wlfA==", + "dev": true, + "bin": { + "playwright-core": "cli.js" + }, + "engines": { + "node": ">=16" + } + }, + "node_modules/playwright/node_modules/fsevents": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", + "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", + "dev": true, + "hasInstallScript": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, "node_modules/polished": { "version": "4.3.1", "resolved": "https://registry.npmjs.org/polished/-/polished-4.3.1.tgz", diff --git a/package.json b/package.json index 163c66341b..7cad9d814e 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,7 @@ "@babel/preset-env": "^7.23.2", "@babel/preset-react": "^7.22.15", "@etchteam/storybook-addon-css-variables-theme": "^1.5.1", + "@playwright/test": "^1.42.1", "@storybook/addon-a11y": "^7.5.1", "@storybook/addon-docs": "^7.5.1", "@storybook/addon-essentials": "^7.5.1", @@ -64,6 +65,7 @@ "@stripe/stripe-js": "^2.1.9", "@testing-library/jest-dom": "^6.1.4", "@testing-library/react": "^14.0.0", + "@types/node": "^20.11.30", "@wpmedia/arc-themes-components": "arc-themes-release-version-2.3.0", "algoliasearch": "^4.20.0", "babel-jest": "^29.7.0", diff --git a/playwright.config.js b/playwright.config.js new file mode 100644 index 0000000000..132835e599 --- /dev/null +++ b/playwright.config.js @@ -0,0 +1,79 @@ +// @ts-check +const { defineConfig, devices } = require('@playwright/test'); + +/** + * Read environment variables from file. + * https://github.com/motdotla/dotenv + */ +// require('dotenv').config(); + +/** + * @see https://playwright.dev/docs/test-configuration + */ +module.exports = defineConfig({ + testDir: './e2e', + /* Run tests in files in parallel */ + fullyParallel: true, + /* Fail the build on CI if you accidentally left test.only in the source code. */ + forbidOnly: !!process.env.CI, + /* Retry on CI only */ + retries: process.env.CI ? 2 : 0, + /* Opt out of parallel tests on CI. */ + workers: process.env.CI ? 1 : undefined, + /* Reporter to use. See https://playwright.dev/docs/test-reporters */ + reporter: 'html', + /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ + use: { + /* Base URL to use in actions like `await page.goto('/')`. */ + // baseURL: 'http://127.0.0.1:3000', + + /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ + trace: 'on-first-retry', + }, + + /* Configure projects for major browsers */ + projects: [ + { + name: 'chromium', + use: { ...devices['Desktop Chrome'] }, + }, + + { + name: 'firefox', + use: { ...devices['Desktop Firefox'] }, + }, + + { + name: 'webkit', + use: { ...devices['Desktop Safari'] }, + }, + + /* Test against mobile viewports. */ + // { + // name: 'Mobile Chrome', + // use: { ...devices['Pixel 5'] }, + // }, + // { + // name: 'Mobile Safari', + // use: { ...devices['iPhone 12'] }, + // }, + + /* Test against branded browsers. */ + // { + // name: 'Microsoft Edge', + // use: { ...devices['Desktop Edge'], channel: 'msedge' }, + // }, + // { + // name: 'Google Chrome', + // use: { ...devices['Desktop Chrome'], channel: 'chrome' }, + // }, + ], + + /* Run your local dev server before starting the tests */ + // webServer: { + // command: 'npm run start', + // url: 'http://127.0.0.1:3000', + // reuseExistingServer: !process.env.CI, + // }, +}); +