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
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Generated from: Playwright-Cucumber-Exercise-main\features\login.feature
import { test } from "playwright-bdd";

test.describe('Login Feature', () => {

test.beforeEach('Background', async ({ Given, page }, testInfo) => { if (testInfo.error) return;
await Given('I open the "https://www.saucedemo.com/" page', null, { page });
});

test('Validate the login page title', async ({ Then, page }) => {
await Then('I should see the title "Labs Swag"', null, { page });
});

test('Validate login error message', async ({ Then, page }) => {
await Then('I will login as \'locked_out_user\'', null, { page });
});

});

// == technical section ==

test.use({
$test: [({}, use) => use(test), { scope: 'test', box: true }],
$uri: [({}, use) => use('Playwright-Cucumber-Exercise-main\\features\\login.feature'), { scope: 'test', box: true }],
$bddFileData: [({}, use) => use(bddFileData), { scope: "test", box: true }],
});

const bddFileData = [ // bdd-data-start
{"pwTestLine":10,"pickleLine":6,"tags":[],"steps":[{"pwStepLine":7,"gherkinStepLine":4,"keywordType":"Context","textWithKeyword":"Given I open the \"https://www.saucedemo.com/\" page","isBg":true,"stepMatchArguments":[{"group":{"start":11,"value":"\"https://www.saucedemo.com/\"","children":[{"start":12,"value":"https://www.saucedemo.com/","children":[{"children":[]}]},{"children":[{"children":[]}]}]},"parameterTypeName":"string"}]},{"pwStepLine":11,"gherkinStepLine":8,"keywordType":"Outcome","textWithKeyword":"Then I should see the title \"Labs Swag\"","stepMatchArguments":[{"group":{"start":23,"value":"\"Labs Swag\"","children":[{"start":24,"value":"Labs Swag","children":[{"children":[]}]},{"children":[{"children":[]}]}]},"parameterTypeName":"string"}]}]},
{"pwTestLine":14,"pickleLine":10,"tags":[],"steps":[{"pwStepLine":7,"gherkinStepLine":4,"keywordType":"Context","textWithKeyword":"Given I open the \"https://www.saucedemo.com/\" page","isBg":true,"stepMatchArguments":[{"group":{"start":11,"value":"\"https://www.saucedemo.com/\"","children":[{"start":12,"value":"https://www.saucedemo.com/","children":[{"children":[]}]},{"children":[{"children":[]}]}]},"parameterTypeName":"string"}]},{"pwStepLine":15,"gherkinStepLine":11,"keywordType":"Outcome","textWithKeyword":"Then I will login as 'locked_out_user'","stepMatchArguments":[{"group":{"start":16,"value":"'locked_out_user'","children":[{"children":[{"children":[]}]},{"start":17,"value":"locked_out_user","children":[{"children":[]}]}]},"parameterTypeName":"string"}]}]},
]; // bdd-data-end
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Generated from: Playwright-Cucumber-Exercise-main\features\product.feature
import { test } from "playwright-bdd";

test.describe('Product Feature', () => {

test.beforeEach('Background', async ({ Given, page }, testInfo) => { if (testInfo.error) return;
await Given('I open the "https://www.saucedemo.com/" page', null, { page });
});

test.describe('Validate product sort by price <sort>', () => {

test('Example #1', async ({ When, Then, page }) => {
await When('I will login as \'standard_user\'', null, { page });
await Then('I sort products by "Price (low to high)"', null, { page });
});

test('Example #2', async ({ When, Then, page }) => {
await When('I will login as \'standard_user\'', null, { page });
await Then('I sort products by "Price (high to low)"', null, { page });
});

});

});

// == technical section ==

test.use({
$test: [({}, use) => use(test), { scope: 'test', box: true }],
$uri: [({}, use) => use('Playwright-Cucumber-Exercise-main\\features\\product.feature'), { scope: 'test', box: true }],
$bddFileData: [({}, use) => use(bddFileData), { scope: "test", box: true }],
});

const bddFileData = [ // bdd-data-start
{"pwTestLine":12,"pickleLine":13,"tags":[],"steps":[{"pwStepLine":7,"gherkinStepLine":4,"keywordType":"Context","textWithKeyword":"Given I open the \"https://www.saucedemo.com/\" page","isBg":true,"stepMatchArguments":[{"group":{"start":11,"value":"\"https://www.saucedemo.com/\"","children":[{"start":12,"value":"https://www.saucedemo.com/","children":[{"children":[]}]},{"children":[{"children":[]}]}]},"parameterTypeName":"string"}]},{"pwStepLine":13,"gherkinStepLine":8,"keywordType":"Action","textWithKeyword":"When I will login as 'standard_user'","stepMatchArguments":[{"group":{"start":16,"value":"'standard_user'","children":[{"children":[{"children":[]}]},{"start":17,"value":"standard_user","children":[{"children":[]}]}]},"parameterTypeName":"string"}]},{"pwStepLine":14,"gherkinStepLine":9,"keywordType":"Outcome","textWithKeyword":"Then I sort products by \"Price (low to high)\"","stepMatchArguments":[{"group":{"start":19,"value":"\"Price (low to high)\"","children":[{"start":20,"value":"Price (low to high)","children":[{"children":[]}]},{"children":[{"children":[]}]}]},"parameterTypeName":"string"}]}]},
{"pwTestLine":17,"pickleLine":14,"tags":[],"steps":[{"pwStepLine":7,"gherkinStepLine":4,"keywordType":"Context","textWithKeyword":"Given I open the \"https://www.saucedemo.com/\" page","isBg":true,"stepMatchArguments":[{"group":{"start":11,"value":"\"https://www.saucedemo.com/\"","children":[{"start":12,"value":"https://www.saucedemo.com/","children":[{"children":[]}]},{"children":[{"children":[]}]}]},"parameterTypeName":"string"}]},{"pwStepLine":18,"gherkinStepLine":8,"keywordType":"Action","textWithKeyword":"When I will login as 'standard_user'","stepMatchArguments":[{"group":{"start":16,"value":"'standard_user'","children":[{"children":[{"children":[]}]},{"start":17,"value":"standard_user","children":[{"children":[]}]}]},"parameterTypeName":"string"}]},{"pwStepLine":19,"gherkinStepLine":9,"keywordType":"Outcome","textWithKeyword":"Then I sort products by \"Price (high to low)\"","stepMatchArguments":[{"group":{"start":19,"value":"\"Price (high to low)\"","children":[{"start":20,"value":"Price (high to low)","children":[{"children":[]}]},{"children":[{"children":[]}]}]},"parameterTypeName":"string"}]}]},
]; // bdd-data-end
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Generated from: Playwright-Cucumber-Exercise-main\features\purchase.feature
import { test } from "playwright-bdd";

test.describe('Purchase Feature', () => {

test.beforeEach('Background', async ({ Given, page }, testInfo) => { if (testInfo.error) return;
await Given('I open the "https://www.saucedemo.com/" page', null, { page });
});

test('Validate successful purchase text', async ({ Then, page }) => {
await Then('I will login as \'standard_user\'', null, { page });
await Then('I will add the backpack to the cart', null, { page });
});

});

// == technical section ==

test.use({
$test: [({}, use) => use(test), { scope: 'test', box: true }],
$uri: [({}, use) => use('Playwright-Cucumber-Exercise-main\\features\\purchase.feature'), { scope: 'test', box: true }],
$bddFileData: [({}, use) => use(bddFileData), { scope: "test", box: true }],
});

const bddFileData = [ // bdd-data-start
{"pwTestLine":10,"pickleLine":6,"tags":[],"steps":[{"pwStepLine":7,"gherkinStepLine":4,"keywordType":"Context","textWithKeyword":"Given I open the \"https://www.saucedemo.com/\" page","isBg":true,"stepMatchArguments":[{"group":{"start":11,"value":"\"https://www.saucedemo.com/\"","children":[{"start":12,"value":"https://www.saucedemo.com/","children":[{"children":[]}]},{"children":[{"children":[]}]}]},"parameterTypeName":"string"}]},{"pwStepLine":11,"gherkinStepLine":7,"keywordType":"Outcome","textWithKeyword":"Then I will login as 'standard_user'","stepMatchArguments":[{"group":{"start":16,"value":"'standard_user'","children":[{"children":[{"children":[]}]},{"start":17,"value":"standard_user","children":[{"children":[]}]}]},"parameterTypeName":"string"}]},{"pwStepLine":12,"gherkinStepLine":8,"keywordType":"Outcome","textWithKeyword":"Then I will add the backpack to the cart","stepMatchArguments":[]}]},
]; // bdd-data-end
27 changes: 27 additions & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Playwright Tests
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
jobs:
test:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
- name: Install dependencies
run: npm ci
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Run Playwright tests
run: npx playwright test
- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: playwright-report
path: playwright-report/
retention-days: 30
11 changes: 8 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
report.json
cucumber_report.html
/node_modules

# Playwright
node_modules/
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
/playwright/.auth/
3 changes: 3 additions & 0 deletions Playwright-Cucumber-Exercise-main/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
report.json
cucumber_report.html
/node_modules
File renamed without changes.
File renamed without changes.
File renamed without changes.
26 changes: 26 additions & 0 deletions Playwright-Cucumber-Exercise-main/features/login/login.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//import { Given, When, Then } from "cypress-cucumber-preprocessor/steps";
import { createBdd } from "playwright-bdd";

import { expect } from "@playwright/test"; // Import expect


const { Given, When, Then }= createBdd();

Given('I open the {string} page', async ({page}, url) => {
await page.goto(url);
});
Then('I should see the title {string}',async ({page},title) => {
(await page.title()).includes(title).toBeTruthy;});


Then('I will login as {string}', async ({page}, username) => {

await page.locator('#user-name').fill(username);
await page.locator('#password').fill('secret_sauce');
await page.locator('#login-button').click();

const errorMessage = await page.locator('.error-message-container').allInnerTexts();
expect(errorMessage.includes('Epic sadface')).toBeTruthy;
});


Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ Feature: Product Feature

# Create a datatable to validate the Price (high to low) and Price (low to high) sort options (top-right) using a Scenario Outline
Scenario Outline: Validate product sort by price <sort>
Then I will login as 'standard_user'
# TODO: Sort the items by <sort>
# TODO: Validate all 6 items are sorted correctly by price
Examples:
# TODO: extend the datatable to paramterize this test
| sort |
When I will login as 'standard_user'
Then I sort products by "<sort_option>"

Examples:
| sort_option |
| Price (low to high) |
| Price (high to low) |



53 changes: 53 additions & 0 deletions Playwright-Cucumber-Exercise-main/features/product/product.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { createBdd } from "playwright-bdd";
import { test, expect } from '@playwright/test';
const { Given, When, Then }= createBdd();

Given('I open the Product page', async({page},url) => {
await page.goto(url);
});

When('I will login as user', async ({page}, username) => {

await page.locator('#user-name').fill(username);
await page.locator('#password').fill('secret_sauce');
await page.locator('#login-button').click();
await page.locator('.inventory_list').isVisible();
await page.locator('.inventory_list').shouldBeVisible();
});

Then('I sort products by {string}', async ({page}, sort_option) => {

if(sort_option === 'Price (low to high)') {

await page.locator('.product_sort_container').click();
await page.locator('.product_sort_container').selectOption('lohi');

const firstProductText = await page.locator('.inventory_item').first().allInnerTexts();
console.log('First product:', firstProductText);
expect(firstProductText.some(text => text.includes('Sauce Labs Onesie'))).toBeTruthy();

const lastProductText = await page.locator('.inventory_item').last().allInnerTexts();

console.log('Last product:', lastProductText);
expect(lastProductText.some(text => text.includes('Sauce Labs Fleece Jacket'))).toBeTruthy();


}
else if(sort_option === 'Price (high to low)') {

await page.locator('.product_sort_container').click();
await page.locator('.product_sort_container').selectOption('hilo');

const firstProductText = await page.locator('.inventory_item').first().allInnerTexts();
console.log('First product:', firstProductText);
expect(firstProductText.some(text => text.includes('Sauce Labs Fleece Jacket'))).toBeTruthy();

const lastProductText = await page.locator('.inventory_item').last().allInnerTexts();

console.log('Last product:', lastProductText);
expect(lastProductText.some(text => text.includes('Sauce Labs Onesie'))).toBeTruthy();


}

});
File renamed without changes.
32 changes: 32 additions & 0 deletions Playwright-Cucumber-Exercise-main/features/purchase/purchase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { createBdd } from "playwright-bdd";

const { Given, When, Then }= createBdd();

//import { Given, When, Then } from "cypress-cucumber-preprocessor/steps";

Given('I open the Purchase page', async({page},url) => {
await page.goto(url);
});

Then("Then I will login as {string}", async({page},username) => {
await page.locator('#user-name').fill(username);
await page.locator('#password').fill('secret_sauce');
await page.locator('#login-button').click();
});

Then('I will add the backpack to the cart', async({page},item) => {
await page.locator('#add-to-cart-sauce-labs-backpack').click();
//await page.locator('.shopping_cart_badge').includes('1').tobeTruthy;
await page.locator('.shopping_cart_link').click();

//await page.locator('.cart_item').includes('Sauce Labs Backpack').tobeTruthy;
await page.locator('#checkout').click();
await page.locator('#first-name').fill('Smrutiranjan');
await page.locator('#last-name').fill('Mohanty');
await page.locator('#postal-code').fill('123456');
await page.locator('#continue').click();

//await page.locator('.cart_item').includes('Sauce Labs Backpack').tobeTruthy;
await page.locator('#finish').click();
//await page.locator('.complete-header').includes('Thank you for your order!').tobeTruthy;
});
File renamed without changes.
File renamed without changes.
Loading
Loading