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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Dispatch to Grader

on:
pull_request_target:
types: [opened, synchronize, reopened]
workflow_dispatch:
inputs:
pr_number:
description: 'PR number in this repo (e.g., 119)'
required: true

jobs:
notify-grader:
runs-on: ubuntu-latest
steps:
- name: Verify token can access private grader repo
run: |
code=$(curl -s -o /dev/null -w "%{http_code}\n" \
-H "Authorization: token ${{ secrets.GRADER_REPO_PAT }}" \
https://api.github.com/repos/automationExamples/Playwright-Cucumber-Exercise-Eval)
echo "HTTP $code"; test "$code" = "200"

- name: Send repository_dispatch to grader
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ secrets.GRADER_REPO_PAT }}
repository: automationExamples/Playwright-Cucumber-Exercise-Eval
event-type: grade-assessment
client-payload: >
{
"pr_number": "${{ github.event_name == 'workflow_dispatch' && github.event.inputs.pr_number || github.event.pull_request.number }}",
"repo_full": "${{ github.repository }}"
}
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
58 changes: 58 additions & 0 deletions Playwright-Cucumber-Exercise-main/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Sample Playwright Automation Test

## System Requirements

node >= v18.5.x

npm >= v7


## Setup

// Install Visual Studio Code (or any editor)

https://code.visualstudio.com/download


// Install Node.js

https://nodejs.org/en/download


```bash
git clone https://github.com/automationExamples/Playwright-Cucumber-Exercise.git
npm install
npx playwright install
```

### Recommended vscode extensions

Cucumber v1.7.0

Cucumber (Gherkin) Support enhanced for Behat


## Instructions
To run the test
```bash
npm run test
```

After running, to generate the cucumber report (cucumber_report.html)
```bash
npm run report
```

It is not expected that you complete every task, however, please give your best effort

You will be scored based on your ability to complete the following tasks:

- [ ] Install and setup this repository on your personal computer
- [ ] Complete the automation tasks listed below

### Tasks
- [ ] Modify the scenario 'Validate the login page title' from [login.feature](features/login.feature#8) which runs but fails. Determine the cause of the failure and update the scenario to pass in the test
- [ ] Extend the scenario 'Validate login error message' from [login.feature](features/login.feature#10) which runs and passes but is missing a step. Extend the scenario to validate the error message received.
- [ ] Modify and extend the 'Validate successful purchase text' from [purchase.feature](features/purchase.feature#6) with steps for each comment listed. Consider writing a new steps.ts file along with an appropriate page.ts
- [ ] Modify and extend the 'Validate product sort by price sort' from [product.feature](features/product.feature#6) with steps for each comment listed. Utilize the Scenario Outline and Examples table to parameterize the test
- [ ] Extend the testing coverage with anything you believe would be beneficial
3 changes: 3 additions & 0 deletions Playwright-Cucumber-Exercise-main/cucumber.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
default: `--require-module ts-node/register --require './steps/**/*.ts' --require './hooks/**/*.ts --format @cucumber/pretty-formatter`
};
11 changes: 11 additions & 0 deletions Playwright-Cucumber-Exercise-main/features/login.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Feature: Login Feature

Background:
Given I open the "https://www.saucedemo.com/" page

Scenario: Validate the login page title
Then I should see the title "Swag Labs"

Scenario: Validate login error message
Then I will login as 'locked_out_user'
And I should see the error message "Epic sadface: Sorry, this user has been locked out."
10 changes: 10 additions & 0 deletions Playwright-Cucumber-Exercise-main/features/logout.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Feature: Logout Feature

Background:
Given I open the "https://www.saucedemo.com/" page

Scenario: Validate user logout
Then I will login as 'standard_user'
And I open the menu
And I click logout
Then I should be redirected to login page
15 changes: 15 additions & 0 deletions Playwright-Cucumber-Exercise-main/features/product.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Feature: Product Feature

Background:
Given I open the "https://www.saucedemo.com/" page

# Validate sorting using Scenario Outline
Scenario Outline: Validate product sort by price <sort>
Then I will login as 'standard_user'
And I sort the products by "<sort>"
Then I validate products are sorted by price "<sort>"

Examples:
| sort |
| Price (low to high) |
| Price (high to low) |
12 changes: 12 additions & 0 deletions Playwright-Cucumber-Exercise-main/features/purchase.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Scenario: Validate successful purchase text
Then I will login as 'standard_user'
Then I will add the backpack to the cart
And I select the cart (top-right)
And I select Checkout
And I fill in checkout details "John" "Doe" "12345"
And I select Continue
And I select Finish

Then I should see the confirmation header
And I should see the confirmation message
And I should be on the checkout complete page
13 changes: 13 additions & 0 deletions Playwright-Cucumber-Exercise-main/generate-report.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const reporter = require('cucumber-html-reporter');

const options = {
theme: 'bootstrap',
jsonFile: 'report.json',
output: 'cucumber_report.html',
reportSuiteAsScenarios: true,
scenarioTimestamp: true,
launchReport: true,
metadata: {}
};

reporter.generate(options);
17 changes: 17 additions & 0 deletions Playwright-Cucumber-Exercise-main/hooks/globalHooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Before, After } from '@cucumber/cucumber';
import { chromium, Browser, Page } from '@playwright/test';
import { pageFixture } from './pageFixture';

let browser: Browser;
let page: Page;

Before(async () => {
browser = await chromium.launch({ headless: false });
page = await browser.newPage();
pageFixture.page = page;
});

After(async () => {
await page.close();
await browser.close();
});
5 changes: 5 additions & 0 deletions Playwright-Cucumber-Exercise-main/hooks/pageFixture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Page } from '@playwright/test';

export const pageFixture = {
page: undefined as unknown as Page
};
Loading
Loading