diff --git a/playwright/helpers/recycle.ts b/playwright/helpers/recycle.ts index 9cca263..c4818c7 100644 --- a/playwright/helpers/recycle.ts +++ b/playwright/helpers/recycle.ts @@ -23,4 +23,19 @@ export async function loginUser(page: Page, testInfo: any, password: string,){ } await page.getByRole('button', { name: 'Sign In' }).click(); -} \ No newline at end of file +}; + +export async function fillUpSignUpForm(page: Page, emailAddress: string, password: string, secondPassword: string, PicName: string, username: string){ + await page.goto('https://audaf-testing.onrender.com/signup'); + await page.getByRole('textbox', { name: 'Password', exact: true }).click(); + await page.getByRole('textbox', { name: 'Password', exact: true }).fill(password); + await page.getByRole('textbox', { name: 'Confirm Password' }).click(); + await page.getByRole('textbox', { name: 'Confirm Password' }).fill(secondPassword); + await page.getByRole('textbox', { name: 'Username' }).click(); + await page.getByRole('textbox', { name: 'Username' }).fill(username); + await page.getByRole('textbox', { name: 'Email Address' }).click(); + await page.getByRole('textbox', { name: 'Email Address' }).fill(emailAddress); + await page.locator('input[type="file"]').setInputFiles(PicName); + await page.getByRole('button', { name: '-- Select country --' }).click(); + await page.getByRole('button', { name: 'Albania flag Albania' }).click(); +} diff --git a/playwright/utils/functions.ts b/playwright/utils/functions.ts index dd60d25..e35c5ee 100644 --- a/playwright/utils/functions.ts +++ b/playwright/utils/functions.ts @@ -11,6 +11,7 @@ export function getAuthFileByProjectName(projectName: string) { return path.join(authDir, `user-${projectName.toLowerCase()}.json`); } + export function getAuthFileTamperedByProjectName(projectName: string) { return path.join(authDir, `userTampered-${projectName.toLowerCase()}.json`); } diff --git a/tests/01-createAccount.spec.ts b/tests/01-createAccount.spec.ts index 812f310..aaa86ad 100644 --- a/tests/01-createAccount.spec.ts +++ b/tests/01-createAccount.spec.ts @@ -7,7 +7,8 @@ import { MailpitCodeFetcher, readEmailData, saveEmailAddressForProject, getAuthFileByProjectName, - getAuthFileUnverified} from "../playwright/utils/functions.ts" + getAuthFileUnverified} from "../playwright/utils/functions.ts"; +import {fillUpSignUpForm} from "../playwright/helpers/recycle.ts"; @@ -20,18 +21,7 @@ test.describe.serial('create accounts and testing account creation with already saveEmailAddressForProject(projectName, emailAddress); // Filling up Signup Forum - await page.goto('https://audaf-testing.onrender.com/signup'); - await page.getByRole('textbox', { name: 'Password', exact: true }).click(); - await page.getByRole('textbox', { name: 'Password', exact: true }).fill('securepassword123'); - await page.getByRole('textbox', { name: 'Confirm Password' }).click(); - await page.getByRole('textbox', { name: 'Confirm Password' }).fill('securepassword123'); - await page.getByRole('textbox', { name: 'Username' }).click(); - await page.getByRole('textbox', { name: 'Username' }).fill('testusername'); - await page.getByRole('textbox', { name: 'Email Address' }).click(); - await page.getByRole('textbox', { name: 'Email Address' }).fill(emailAddress); - await page.locator('input[type="file"]').setInputFiles('jellyfishWallpaper.jpg'); - await page.getByRole('button', { name: '-- Select country --' }).click(); - await page.getByRole('button', { name: 'Albania flag Albania' }).click(); + await fillUpSignUpForm(page, emailAddress, "securepassword123", "securepassword123", "jellyfishWallpaper.jpg", "testusername" ) await page.getByRole('button', { name: 'Create Account' }).click(); // Wait for navigation to verification page @@ -62,19 +52,8 @@ test.describe.serial('create accounts and testing account creation with already const projectName = testInfo.project.name; const emailData = readEmailData(); const emailAddress = emailData[projectName.toLowerCase()] || `test-user-${projectName.toLowerCase()}@gamil.com`; - - await page.goto('https://audaf-testing.onrender.com/signup'); - await page.getByRole('textbox', { name: 'Password', exact: true }).click(); - await page.getByRole('textbox', { name: 'Password', exact: true }).fill('securepassword123'); - await page.getByRole('textbox', { name: 'Confirm Password' }).click(); - await page.getByRole('textbox', { name: 'Confirm Password' }).fill('securepassword123'); - await page.getByRole('textbox', { name: 'Username' }).click(); - await page.getByRole('textbox', { name: 'Username' }).fill('testusername2'); - await page.getByRole('textbox', { name: 'Email Address' }).click(); - await page.getByRole('textbox', { name: 'Email Address' }).fill(emailAddress); - await page.locator('input[type="file"]').setInputFiles('jellyfishWallpaper.jpg'); - await page.getByRole('button', { name: '-- Select country --' }).click(); - await page.getByRole('button', { name: 'Albania flag Albania' }).click(); + + await fillUpSignUpForm(page, emailAddress, "securepassword123", "securepassword123", "jellyfishWallpaper.jpg", "testusername2" ) await page.getByRole('button', { name: 'Create Account' }).click(); await expect(page.getByText('Email already in use')).toBeVisible({ timeout: 15000 }); }); @@ -83,18 +62,7 @@ test.describe.serial('create accounts and testing account creation with already const projectName = testInfo.project.name; const emailAddress = `test-user-${projectName.toLowerCase()}-${Date.now()}@gamil.com`; - await page.goto('https://audaf-testing.onrender.com/signup'); - await page.getByRole('textbox', { name: 'Password', exact: true }).click(); - await page.getByRole('textbox', { name: 'Password', exact: true }).fill('securepassword123'); - await page.getByRole('textbox', { name: 'Confirm Password' }).click(); - await page.getByRole('textbox', { name: 'Confirm Password' }).fill('mismatched1'); //<- mismatching - await page.getByRole('textbox', { name: 'Username' }).click(); - await page.getByRole('textbox', { name: 'Username' }).fill('testusername2'); - await page.getByRole('textbox', { name: 'Email Address' }).click(); - await page.getByRole('textbox', { name: 'Email Address' }).fill(emailAddress); - await page.locator('input[type="file"]').setInputFiles('jellyfishWallpaper.jpg'); - await page.getByRole('button', { name: '-- Select country --' }).click(); - await page.getByRole('button', { name: 'Albania flag Albania' }).click(); + await fillUpSignUpForm(page, emailAddress, "securepassword123", "mismatched1", "jellyfishWallpaper.jpg", "testusername2" ) await expect(page.getByRole('button', { name: 'Create Account' })).toBeDisabled(); }); @@ -102,18 +70,7 @@ test.describe.serial('create accounts and testing account creation with already const projectName = testInfo.project.name; const emailAddress = `test-user-${projectName.toLowerCase()}-${Date.now()}gamil.com`; // <- invalid format - await page.goto('https://audaf-testing.onrender.com/signup'); - await page.getByRole('textbox', { name: 'Password', exact: true }).click(); - await page.getByRole('textbox', { name: 'Password', exact: true }).fill('securepassword123'); - await page.getByRole('textbox', { name: 'Confirm Password' }).click(); - await page.getByRole('textbox', { name: 'Confirm Password' }).fill('securepassword123'); - await page.getByRole('textbox', { name: 'Username' }).click(); - await page.getByRole('textbox', { name: 'Username' }).fill('testusername2'); - await page.getByRole('textbox', { name: 'Email Address' }).click(); - await page.getByRole('textbox', { name: 'Email Address' }).fill(emailAddress); - await page.locator('input[type="file"]').setInputFiles('jellyfishWallpaper.jpg'); - await page.getByRole('button', { name: '-- Select country --' }).click(); - await page.getByRole('button', { name: 'Albania flag Albania' }).click(); + await fillUpSignUpForm(page, emailAddress, "securepassword123", "securepassword123", "jellyfishWallpaper.jpg", "testusername2" ) await expect(page.getByRole('button', { name: 'Create Account' })).toBeDisabled(); }); @@ -121,18 +78,7 @@ test.describe.serial('create accounts and testing account creation with already const projectName = testInfo.project.name; const emailAddress = `test-user-${projectName.toLowerCase()}-${Date.now()}@gamil.com`; - await page.goto('https://audaf-testing.onrender.com/signup'); - await page.getByRole('textbox', { name: 'Password', exact: true }).click(); - await page.getByRole('textbox', { name: 'Password', exact: true }).fill('weak'); // <- weak password - await page.getByRole('textbox', { name: 'Confirm Password' }).click(); - await page.getByRole('textbox', { name: 'Confirm Password' }).fill('weak'); - await page.getByRole('textbox', { name: 'Username' }).click(); - await page.getByRole('textbox', { name: 'Username' }).fill('testusername2'); - await page.getByRole('textbox', { name: 'Email Address' }).click(); - await page.getByRole('textbox', { name: 'Email Address' }).fill(emailAddress); - await page.locator('input[type="file"]').setInputFiles('jellyfishWallpaper.jpg'); - await page.getByRole('button', { name: '-- Select country --' }).click(); - await page.getByRole('button', { name: 'Albania flag Albania' }).click(); + await fillUpSignUpForm(page, emailAddress, "weak", "weak", "jellyfishWallpaper.jpg", "testusername2" ) await expect(page.getByRole('button', { name: 'Create Account' })).toBeDisabled(); }); @@ -140,25 +86,11 @@ test.describe.serial('create accounts and testing account creation with already const projectName = testInfo.project.name; const emailAddress = `test-user-${projectName.toLowerCase()}-${Date.now()}@gamil.com`; - await page.goto('https://audaf-testing.onrender.com/signup'); - await page.getByRole('textbox', { name: 'Password', exact: true }).click(); - await page.getByRole('textbox', { name: 'Password', exact: true }).fill('securepassword123'); - await page.getByRole('textbox', { name: 'Confirm Password' }).click(); - await page.getByRole('textbox', { name: 'Confirm Password' }).fill('securepassword123'); - await page.getByRole('textbox', { name: 'Username' }).click(); - await page.getByRole('textbox', { name: 'Username' }).fill('testusername2'); - await page.getByRole('textbox', { name: 'Email Address' }).click(); - await page.getByRole('textbox', { name: 'Email Address' }).fill(emailAddress); - await page.locator('input[type="file"]').setInputFiles('ghibli-gif.gif'); - await page.getByRole('button', { name: '-- Select country --' }).click(); - await page.getByRole('button', { name: 'Albania flag Albania' }).click(); + await fillUpSignUpForm(page, emailAddress, "securepassword123", "securepassword123", "ghibli-gif.gif", "testusername2" ) await page.getByRole('button', { name: 'Create Account' }).click(); await page.waitForURL("https://audaf-testing.onrender.com/verify-email", { timeout: 30000 }); const allMessages = await page.consoleMessages(); - const uploadFailed = allMessages.some(msg => - msg.text().includes("avatar upload failed") - ); - + const uploadFailed = allMessages.some(msg => msg.text().includes("avatar upload failed")); expect(uploadFailed).toBe(true); }); @@ -169,18 +101,7 @@ test.describe.serial('create accounts and testing account creation with already saveEmailAddressForProject(`${projectName}-unverified`, unverifiedEmailAddress); // Filling up Signup Forum - await page.goto('https://audaf-testing.onrender.com/signup'); - await page.getByRole('textbox', { name: 'Password', exact: true }).click(); - await page.getByRole('textbox', { name: 'Password', exact: true }).fill('securepassword123'); - await page.getByRole('textbox', { name: 'Confirm Password' }).click(); - await page.getByRole('textbox', { name: 'Confirm Password' }).fill('securepassword123'); - await page.getByRole('textbox', { name: 'Username' }).click(); - await page.getByRole('textbox', { name: 'Username' }).fill('testuserunverified'); - await page.getByRole('textbox', { name: 'Email Address' }).click(); - await page.getByRole('textbox', { name: 'Email Address' }).fill(unverifiedEmailAddress); - await page.locator('input[type="file"]').setInputFiles('jellyfishWallpaper.jpg'); - await page.getByRole('button', { name: '-- Select country --' }).click(); - await page.getByRole('button', { name: 'Albania flag Albania' }).click(); + await fillUpSignUpForm(page, unverifiedEmailAddress, "securepassword123", "securepassword123", "jellyfishWallpaper.jpg", "testuserunverified" ) await page.getByRole('button', { name: 'Create Account' }).click(); await page.waitForURL("https://audaf-testing.onrender.com/verify-email", { timeout: 30000 }); diff --git a/tests/03-CRUDActionsAndNavigation.spec.ts b/tests/03-CRUDActionsAndNavigation.spec.ts index da7e555..3ddeb92 100644 --- a/tests/03-CRUDActionsAndNavigation.spec.ts +++ b/tests/03-CRUDActionsAndNavigation.spec.ts @@ -6,7 +6,6 @@ import {getAuthFileByProjectName, MailpitCodeFetcher} from "../playwright/utils/functions.ts" import {loginUser} from "../playwright/helpers/recycle.ts" - test.describe.serial('CRUD Actions and Navigation', () => { test.beforeEach(async ({ page }, testInfo) => { const authFile = getAuthFileByProjectName(testInfo.project.name); diff --git a/tests/04-cleanUpTestAccounts.spec.ts b/tests/04-cleanUpTestAccounts.spec.ts deleted file mode 100644 index 0a249a1..0000000 --- a/tests/04-cleanUpTestAccounts.spec.ts +++ /dev/null @@ -1,18 +0,0 @@ -// @ts-check -import { test, expect } from '@playwright/test'; -import path from "path"; -import { exec } from 'child_process'; -import { promisify } from 'util'; - -const cleanUpScript = path.join(__dirname, '../.github/scripts/cleanUp.js'); - -const execAsync = promisify(exec); - -test("running cleanup for unverified user", async({page})=>{ - const { stdout, stderr } = await execAsync(`node ${cleanUpScript}`); - console.log('Cleanup stdout:', stdout); - console.error('Cleanup stderr:', stderr); - - expect(stdout).toContain('Finished checking for users to delete.'); - expect(stderr).toBe(''); - }); \ No newline at end of file diff --git a/tests/04-unverifiedEmailCRUDActions.spec.ts b/tests/04-unverifiedEmailCRUDActions.spec.ts new file mode 100644 index 0000000..006ae74 --- /dev/null +++ b/tests/04-unverifiedEmailCRUDActions.spec.ts @@ -0,0 +1,42 @@ +// @ts-check +import { test, expect } from '@playwright/test'; +import path from "path"; +import { exec } from 'child_process'; +import { promisify } from 'util'; +import {loginUser} from "../playwright/helpers/recycle.ts" +import {getAuthFileUnverified, restoreAuthState} from "../playwright/utils/functions.ts" + +const cleanUpScript = path.join(__dirname, '../.github/scripts/cleanUp.js'); + +const execAsync = promisify(exec); + +test.describe.serial('Unverified Email CRUD Actions', () => { + test.beforeEach(async ({ page }, testInfo) => { + const authFileUnverified = getAuthFileUnverified(testInfo.project.name); + await restoreAuthState(page, authFileUnverified); + }); + + test.afterAll(async () => { + const { stdout, stderr } = await execAsync(`node ${cleanUpScript}`); + console.log('Cleanup stdout:', stdout); + console.error('Cleanup stderr:', stderr); + + expect(stdout).toContain('Finished checking for users to delete.'); + expect(stderr).toBe(''); + }); + + test('navigating home', async ({ page }) => { + await page.goto('https://audaf-testing.onrender.com/home'); + await expect(page.getByText('Welcome Home, testuserunverified!', { exact: true})).not.toBeVisible(); + }); + + test("logging in with correct credentials but unverified email", async({page}, testInfo)=>{ + + await loginUser(page, testInfo, "newSecurePassword123") + + await page.waitForTimeout(3000); + await expect(page.locator('form')).toBeVisible({ timeout: 10000 }); + await page.context().storageState({ path: getAuthFileUnverified(testInfo.project.name) }); + }); +}); + diff --git a/tests/05-unverifiedEmailCRUDActions.spec.ts b/tests/05-unverifiedEmailCRUDActions.spec.ts deleted file mode 100644 index 6444f84..0000000 --- a/tests/05-unverifiedEmailCRUDActions.spec.ts +++ /dev/null @@ -1,90 +0,0 @@ -// @ts-check -import { test, expect } from '@playwright/test'; -import path from "path"; -import { existsSync, readFileSync } from 'fs'; - -const emailAddressFile = path.join(__dirname, '../playwright/.auth/emails.json'); - -function getAuthFileUnverifiedByProjectName(projectName: string) { - return path.join(__dirname, '../playwright/.auth', `userUnverified-${projectName.toLowerCase()}.json`); -} - -function getUnverifiedEmailAddressForProject(testInfo: { project: { name: string } }) { - if (!existsSync(emailAddressFile)) { - return `test-user-unverified-${testInfo.project.name.toLowerCase()}@gamil.com`; - } - - try { - const emailData = JSON.parse(readFileSync(emailAddressFile, 'utf8')); - return emailData[`${testInfo.project.name.toLowerCase()}-unverified`] || `test-user-unverified-${testInfo.project.name.toLowerCase()}@gamil.com`; - } catch { - return `test-user-unverified-${testInfo.project.name.toLowerCase()}@gamil.com`; - } -} - -async function restoreAuthState(page: any, filePath: string) { - if (!existsSync(filePath)) { - return; - } - - const state = JSON.parse(readFileSync(filePath, 'utf8')); - const context = page.context(); - - if (state.cookies?.length) { - await context.addCookies(state.cookies); - } - - for (const originState of state.origins || []) { - await page.goto(originState.origin, { waitUntil: 'domcontentloaded' }).catch(() => {}); - await page.evaluate((storage: any) => { - for (const item of storage.localStorage || []) { - window.localStorage.setItem(item.name, item.value); - } - }, originState); - } -} - - -test.describe.serial('Unverified Email CRUD Actions', () => { - test.beforeEach(async ({ page }, testInfo) => { - const authFileUnverified = getAuthFileUnverifiedByProjectName(testInfo.project.name); - await restoreAuthState(page, authFileUnverified); - }); - - test('navigating home', async ({ page }) => { - await page.goto('https://audaf-testing.onrender.com/home'); - await expect(page.getByText('Welcome Home, testuserunverified!', { exact: true})).not.toBeVisible(); - }); - - test("logging in with correct credentials but unverified email", async({page}, testInfo)=>{ - const emailAddress = getUnverifiedEmailAddressForProject(testInfo); - await page.goto("https://audaf-testing.onrender.com") - await page.getByPlaceholder("Enter email").click(); - await page.getByPlaceholder("Enter email").fill(emailAddress); - await page.getByPlaceholder("Password").click(); - await page.getByPlaceholder("Password").fill('newSecurePassword123'); - - // Handle reCAPTCHA - if (await page.$('iframe[src*="recaptcha"]')) { - await page.waitForFunction(() => {return document.querySelector('iframe[src*="recaptcha"]');}); - const frames = page.frames(); - const recaptchaFrame = frames.find(f => f.url().includes('recaptcha')); - if (recaptchaFrame) {await recaptchaFrame.getByRole('checkbox', { name: "I'm not a robot" }).click();} - }else{ - // Handle reCAPTCHA – works in both Firefox and Chromium - // Wait for the reCAPTCHA iframe to appear in the DOM - await page.waitForSelector('iframe[src*="recaptcha"]', { timeout: 10000 }); - // Create a frame locator for that iframe - const recaptchaFrame = page.frameLocator('iframe[src*="recaptcha"]'); - // Click the "I'm not a robot" checkbox inside the iframe - await recaptchaFrame.getByRole('checkbox', { name: "I'm not a robot" }).click(); - } - - await page.getByRole('button', { name: 'Sign In' }).click(); - - await page.waitForTimeout(3000); - await expect(page.locator('form')).toBeVisible({ timeout: 10000 }); - await page.context().storageState({ path: getAuthFileUnverifiedByProjectName(testInfo.project.name) }); - }); -}); -