Skip to content

Commit

Permalink
real world app test
Browse files Browse the repository at this point in the history
  • Loading branch information
Tallyb committed Oct 1, 2024
1 parent 12e033b commit 6c0e3bd
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
6 changes: 6 additions & 0 deletions features/conduit.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Feature: Conduit

Scenario: Sign up
Given Use Fake time "2021-01-01"
Given Go to the conduit website
Given User signs up
1 change: 1 addition & 0 deletions features/playwright.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Feature: Playwright docs
Given Go to the playwright website

Scenario: Change theme
Given Use Fake time "2021-01-01"
Given A cat fact is recieved
When Change theme to "light" mode
# And Screen matches the base image "Light Mode"
Expand Down
22 changes: 22 additions & 0 deletions src/steps/conduit.steps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { ICustomWorld } from '../support/custom-world';
import { Given, Then } from '@cucumber/cucumber';

Check failure on line 2 in src/steps/conduit.steps.ts

View workflow job for this annotation

GitHub Actions / run (20)

'Then' is defined but never used

Check failure on line 2 in src/steps/conduit.steps.ts

View workflow job for this annotation

GitHub Actions / run (22.5.1)

'Then' is defined but never used
import { expect } from '@playwright/test';
import { v4 } from 'uuid';

Given('Go to the conduit website', async function (this: ICustomWorld) {
const page = this.page!;
await page.goto('https://demo.realworld.how');
await expect(page.locator('app-home-page').locator('.logo-font')).toHaveText('conduit');
});

Given('User signs up', async function (this: ICustomWorld) {
const page = this.page!;
this.username = `test-${v4().slice(0, 6)}`;
await page.getByText('Sign up').click();
await expect(page.locator('app-auth-page').locator('h1')).toHaveText('Sign up');
await page.getByPlaceholder('Username').fill(this.username);
await page.getByPlaceholder('Email').fill(`${this.username}@example.com`);
await page.getByPlaceholder('Password').fill('test123456');
await page.getByRole('button', { name: 'Sign up' }).click();
await expect(page.locator('app-layout-header').locator('nav')).toContainText(this.username);
});
6 changes: 5 additions & 1 deletion src/steps/general.steps.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ICustomWorld } from '../support/custom-world';
import { compareToBaseImage, getImagePath } from '../utils/compareImages';
import { Then } from '@cucumber/cucumber';
import { Given, Then } from '@cucumber/cucumber';

Then('Snapshot {string}', async function (this: ICustomWorld, name: string) {
const { page } = this;
Expand All @@ -23,3 +23,7 @@ Then('Screen matches the base image {string}', async function (this: ICustomWorl
const screenshot = await this.page!.screenshot({});
await compareToBaseImage(this, name, screenshot);
});

Given('Use Fake time {string}', async function (this: ICustomWorld, time: string) {

Check failure on line 27 in src/steps/general.steps.ts

View workflow job for this annotation

GitHub Actions / run (20)

Async function has no 'await' expression

Check failure on line 27 in src/steps/general.steps.ts

View workflow job for this annotation

GitHub Actions / run (22.5.1)

Async function has no 'await' expression
this.page!.clock.setFixedTime(new Date(time));

Check failure on line 28 in src/steps/general.steps.ts

View workflow job for this annotation

GitHub Actions / run (20)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator

Check failure on line 28 in src/steps/general.steps.ts

View workflow job for this annotation

GitHub Actions / run (22.5.1)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
});
1 change: 1 addition & 0 deletions src/support/custom-world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface ICustomWorld extends World {

server?: APIRequestContext;

username?: string;
playwrightOptions?: PlaywrightTestOptions;
}

Expand Down

0 comments on commit 6c0e3bd

Please sign in to comment.