Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E2E tests for registration #197

Merged
merged 6 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions e2e/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import { ShoppingCart } from './page-objects/shopping-cart';
import { ProductPage } from './page-objects/product-page';
import { ContactPage } from './page-objects/contact-page';
import { SignInPage } from './page-objects/sign-in-page';
import { SignUpPage } from './page-objects/sign-up-page';

export const test = baseTest.extend<{
collectionsPage: CollectionsPage;
shoppingCart: ShoppingCart;
productPage: ProductPage;
contactPage: ContactPage;
signInPage: SignInPage;
signUpPage: SignUpPage;
}>({
collectionsPage: async ({ page }, use) => {
await use(new CollectionsPage(page));
Expand All @@ -26,5 +28,8 @@ export const test = baseTest.extend<{
},
signInPage: async ({ page }, use) => {
await use(new SignInPage(page));
},
signUpPage: async ({ page }, use) => {
await use(new SignUpPage(page));
}
});
16 changes: 16 additions & 0 deletions e2e/page-objects/sign-up-page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Page } from '@playwright/test';

export class SignUpPage {
readonly page: Page;

constructor(page: Page) {
this.page = page;
}

emailInput = () => this.page.locator('#email');
passwordInput = () => this.page.locator('#password');
passwordConfirmInput = () => this.page.locator('#passwordConfirm');
signUpButton = () => this.page.getByRole('button', { name: 'Sign up', exact: true });
createAnAccountNavBtn = () => this.page.getByText('Create an account');
signInButton = () => this.page.locator('a', { hasText: 'Sign in' });
}
43 changes: 43 additions & 0 deletions e2e/tests/registration.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { test } from '../fixtures';
import { expect } from 'playwright/test';
import { HOMEPAGE_ENDPOINT, INVALID_EMAIL, SIGN_IN_PAGE_ENDPOINT, SIGN_UP_PAGE_ENDPOINT } from '../constants';
import { getPassword, getValidEmail } from '../fake-data-generation';

test.describe('Registration form', () => {
test.beforeEach('Navigate to the Sign up page', async ({ page, signUpPage }) => {
await page.goto(HOMEPAGE_ENDPOINT);
await signUpPage.createAnAccountNavBtn().click();
await expect(page.getByText('Create your account')).toBeVisible();
expect(page.url()).toContain(SIGN_UP_PAGE_ENDPOINT);
});

test('Verify red messages appear if required fields are not filled in', async ({ page, signUpPage }) => {
await signUpPage.signUpButton().click();
await expect(page.getByText('This field is required')).toHaveCount(3);
});

test('Cannot register a new user using invalid email', async ({ page, signUpPage }) => {
const password = getPassword();

await signUpPage.emailInput().fill(INVALID_EMAIL);
await signUpPage.passwordInput().fill(password);
await signUpPage.passwordConfirmInput().fill(password);
await signUpPage.signUpButton().click();
await expect(page.getByText('Please enter a valid email')).toBeVisible();
});

test("Cannot register a new user if passwords don't match", async ({ page, signUpPage }) => {
await signUpPage.emailInput().fill(getValidEmail());
await signUpPage.passwordInput().fill(getPassword());
await signUpPage.passwordConfirmInput().fill('passworddoesntmatch');
await signUpPage.signUpButton().click();
await expect(page.getByText('The passwords do not match')).toBeVisible();
});

test('Verify user can navigate to the Sign In page', async ({ page, signUpPage }) => {
await expect(page.getByText('Already have an account?')).toBeVisible();
await signUpPage.signInButton().click();
await page.waitForTimeout(1000);
expect(page.url()).toContain(SIGN_IN_PAGE_ENDPOINT);
});
});
Loading