Skip to content
Open
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
1 change: 1 addition & 0 deletions Playwright-Cucumber-Exercise
Submodule Playwright-Cucumber-Exercise added at b56632
5 changes: 3 additions & 2 deletions features/login.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ Feature: Login Feature

Scenario: Validate the login page title
# TODO: Fix this failing scenario
Then I should see the title "Labs Swag"
Then I should see the title "Swag Labs"

Scenario: Validate login error message
Then I will login as 'locked_out_user'
# TODO: Add a step to validate the error message received
# TODO: Add a step to validate the error message received
Then I should see the error message "Epic sadface: Sorry, this user has been locked out."
6 changes: 5 additions & 1 deletion features/product.feature
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ Feature: Product Feature
Scenario Outline: Validate product sort by price <sort>
Then I will login as 'standard_user'
# TODO: Sort the items by <sort>
Then I sort the products by "<sort>"
# TODO: Validate all 6 items are sorted correctly by price
Then the products should be sorted by price "<sort>"
Examples:
# TODO: extend the datatable to paramterize this test
| sort |
| sort |
| Price (low to high) |
| Price (high to low) |
8 changes: 7 additions & 1 deletion features/purchase.feature
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@ Feature: Purchase Feature
Then I will login as 'standard_user'
Then I will add the backpack to the cart
# TODO: Select the cart (top-right)
Then I select the cart
# TODO: Select Checkout
Then I select Checkout
# TODO: Fill in the First Name, Last Name, and Zip/Postal Code
Then I fill in the checkout information
# TODO: Select Continue
Then I select Continue
# TODO: Select Finish
# TODO: Validate the text 'Thank you for your order!'
Then I select Finish
# TODO: Validate the text 'Thank you for your order!'
Then I should see the text "Thank you for your order!"
69 changes: 59 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@
"cucumber-html-reporter": "^7.1.1",
"ts-node": "^10.9.1",
"typescript": "^5.3.2"
},
"dependencies": {
"reflect-metadata": "^0.2.2",
"uuid": "^13.0.0"
}
}
35 changes: 35 additions & 0 deletions pages/purchase.pages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Page } from '@playwright/test';

export class PurchasePage {
constructor(private page: Page) {}

async addBackpackToCart() {
await this.page.click('[data-test="add-to-cart-sauce-labs-backpack"]');
}

async openCart() {
await this.page.click('.shopping_cart_link');
}

async clickCheckout() {
await this.page.click('[data-test="checkout"]');
}

async fillCheckoutInfo() {
await this.page.fill('[data-test="firstName"]', 'John');
await this.page.fill('[data-test="lastName"]', 'Doe');
await this.page.fill('[data-test="postalCode"]', '12345');
}

async clickContinue() {
await this.page.click('[data-test="continue"]');
}

async clickFinish() {
await this.page.click('[data-test="finish"]');
}

async getSuccessText() {
return this.page.locator('.complete-header').textContent();
}
}
13 changes: 12 additions & 1 deletion steps/login.steps.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
import { Then } from '@cucumber/cucumber';
import { getPage } from '../playwrightUtilities';
import { Login } from '../pages/login.page';
import { expect } from '@playwright/test';
import { Page } from '@playwright/test';

Then('I should see the title {string}', async (expectedTitle) => {
await new Login(getPage()).validateTitle(expectedTitle);
});

Then('I will login as {string}', async (userName) => {
await new Login(getPage()).loginAsUser(userName);
});
});

Then(
'I should see the login error message {string}',
async function (this: { page: Page }, expectedMessage: string) {
const errorLocator = this.page.locator('h3[data-test="error"]');
const actualMessage = await errorLocator.textContent();
expect(actualMessage?.trim()).toBe(expectedMessage);
}
);
46 changes: 46 additions & 0 deletions steps/purchase.steps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { Given, Then } from '@cucumber/cucumber';
import { expect } from '@playwright/test';
import { PurchasePage } from '../pages/purchase.page';
import { Page } from '@playwright/test';

let purchasePage: PurchasePage;

Given('I open the {string} page', async function (this: { page: Page }, url: string) {
await this.page.goto(url);
purchasePage = new PurchasePage(this.page);
});

Then("I will login as {string}", async function (this: { page: Page }, username: string) {
await this.page.fill('[data-test="username"]', username);
await this.page.fill('[data-test="password"]', 'secret_sauce');
await this.page.click('[data-test="login-button"]');
});

Then('I will add the backpack to the cart', async function () {
await purchasePage.addBackpackToCart();
});

Then('I select the cart', async function () {
await purchasePage.openCart();
});

Then('I select Checkout', async function () {
await purchasePage.clickCheckout();
});

Then('I fill in the checkout information', async function () {
await purchasePage.fillCheckoutInfo();
});

Then('I select Continue', async function () {
await purchasePage.clickContinue();
});

Then('I select Finish', async function () {
await purchasePage.clickFinish();
});

Then('I should see the text {string}', async function (expectedText: string) {
const actualText = await purchasePage.getSuccessText();
expect(actualText?.trim()).toBe(expectedText);
});