Skip to content

Commit

Permalink
demo
Browse files Browse the repository at this point in the history
  • Loading branch information
Xotabu4 committed Oct 3, 2023
1 parent 2d10020 commit 5e4933e
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 29 deletions.
2 changes: 2 additions & 0 deletions app/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { PageHolder } from "./abstractClasses";
import { AccountDetails } from "./page/account/details.page";
import { Confirmation } from "./page/confirmation.page";
import { ContactUs } from "./page/contactus.page";
import { Home } from "./page/home.page";
import { Product } from "./page/product";
import { Shop } from "./page/shop.page";
Expand All @@ -15,4 +16,5 @@ export class Application extends PageHolder {
public signIn = new SignIn(this.page);
public accountDetails = new AccountDetails(this.page);
public confirmation = new Confirmation(this.page);
public contactus = new ContactUs(this.page);
}
26 changes: 26 additions & 0 deletions app/page/contactus.page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { expect } from "@playwright/test";
import { AppPage } from "../abstractClasses";

export class ContactUs extends AppPage {
public pagePath = '/contact'

private fullNameInput = this.page.getByPlaceholder('You Full Name');
private emailInput = this.page.getByPlaceholder('Your Email Address');
private messageInput = this.page.getByPlaceholder('Please Describe Your Message');
private submitButton = this.page.getByRole('button', { name: 'Submit' });

async expectLoaded() {
await expect(this.fullNameInput).toBeVisible();
await expect(this.emailInput).toBeVisible();
await expect(this.messageInput).toBeVisible();
await expect(this.submitButton).toBeVisible();
}

async submitContactUsForm(options: { fullName: string, email: string, message: string }) {
await this.expectLoaded();
await this.fullNameInput.fill(options.fullName);
await this.emailInput.fill(options.email);
await this.messageInput.fill(options.message);
await this.submitButton.click();
}
}
1 change: 1 addition & 0 deletions app/page/product/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class Product extends AppPage {
}

async addToBag() {
await this.expectLoaded();
await this.addToBagButton.click();
}
}
8 changes: 8 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default defineConfig({
workers: 10,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
// maxFailures: 50,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
Expand All @@ -28,6 +29,13 @@ export default defineConfig({
baseURL: 'https://shopdemo-alex-hot.koyeb.app',
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
screenshot: {
fullPage: true,
mode: 'only-on-failure',
},
video: {
mode: 'on-first-retry'
},
headless: true,
},
/* Configure projects for major browsers */
Expand Down
34 changes: 5 additions & 29 deletions tests/test-1.spec.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,15 @@
import { randomUUID } from 'node:crypto';
import { test, expect } from '@playwright/test';
import { AppPage } from '../app/abstractClasses';
import { test } from '@playwright/test';
import { Application } from '../app';

test('test', async ({ page }) => {
const contactUs = new ContactUs(page);
const app = new Application(page);

await contactUs.open();
await contactUs.submitContactUsForm({
await app.contactus.open();
await app.contactus.submitContactUsForm({
email: `xotabu4+${randomUUID()}@gmail.com`,
fullName: 'test name',
message: 'test message'
});
// TODO: add success popup appears expectation
});

class ContactUs extends AppPage {
public pagePath = '/contact'

private fullNameInput = this.page.getByPlaceholder('You Full Name');
private emailInput = this.page.getByPlaceholder('Your Email Address');
private messageInput = this.page.getByPlaceholder('Please Describe Your Message');
private submitButton = this.page.getByRole('button', { name: 'Submit' });

async expectLoaded() {
await expect(this.fullNameInput).toBeVisible();
await expect(this.emailInput).toBeVisible();
await expect(this.messageInput).toBeVisible();
await expect(this.submitButton).toBeVisible();
}

async submitContactUsForm(options: { fullName: string, email: string, message: string }) {
await this.expectLoaded();
await this.fullNameInput.fill(options.fullName);
await this.emailInput.fill(options.email);
await this.messageInput.fill(options.message);
await this.submitButton.click();
}
}

0 comments on commit 5e4933e

Please sign in to comment.