|
| 1 | +# Playwright TypeScript BDD Automation |
| 2 | + |
| 3 | +This project automates end-to-end testing using **Playwright, TypeScript, and Cucumber (BDD framework)**. |
| 4 | + |
| 5 | +## 📌 Prerequisites |
| 6 | + |
| 7 | +Ensure you have the following installed: |
| 8 | +- **Node.js (LTS recommended)** → [Download](https://nodejs.org/) |
| 9 | +- **Playwright** → Installed via dependencies |
| 10 | +- **Cucumber.js** → Installed via dependencies |
| 11 | + |
| 12 | +## 🚀 Installation |
| 13 | + |
| 14 | +1. Clone the repository: |
| 15 | + ```sh |
| 16 | + git clone https://github.com/your-repo/PlaywrightTypeScriptUsingBDD.git |
| 17 | + cd PlaywrightTypeScriptUsingBDD |
| 18 | + ``` |
| 19 | +2. Install dependencies: |
| 20 | + ```sh |
| 21 | + npm install |
| 22 | + ``` |
| 23 | +3. Install Playwright browsers: |
| 24 | + ```sh |
| 25 | + npx playwright install |
| 26 | + ``` |
| 27 | + |
| 28 | +## 📂 Project Structure |
| 29 | + |
| 30 | +``` |
| 31 | +📂 PlaywrightTypeScriptUsingBDD |
| 32 | + ┣ 📂 features/ # Cucumber feature files |
| 33 | + ┣ 📂 steps/ # Step definitions (Gherkin steps) |
| 34 | + ┣ 📂 support/ # Hooks and utility functions |
| 35 | + ┣ 📂 reports/ # Test reports (HTML & JSON) |
| 36 | + ┣ 📜 package.json # Dependencies & scripts |
| 37 | + ┣ 📜 playwright.config.ts # Playwright configuration |
| 38 | + ┗ 📜 README.md # Documentation |
| 39 | +``` |
| 40 | + |
| 41 | +## 📝 Writing Tests |
| 42 | + |
| 43 | +### Example Feature File (`features/login.feature`) |
| 44 | +```gherkin |
| 45 | +Feature: Login to Sauce Demo |
| 46 | + As a user |
| 47 | + I want to be able to log in with valid and invalid credentials |
| 48 | + So that I can access the inventory page or see an error message |
| 49 | +
|
| 50 | + @positive |
| 51 | + Scenario Outline: Successful Login |
| 52 | + Given I navigate to the Sauce Demo login page |
| 53 | + When I enter username "<username>" and password "<password>" |
| 54 | + And I click the login button |
| 55 | + Then I should see the products page |
| 56 | +
|
| 57 | + Examples: |
| 58 | + | username | password | |
| 59 | + | standard_user | secret_sauce | |
| 60 | +
|
| 61 | + @negative |
| 62 | + Scenario Outline: Invalid Login |
| 63 | + Given I navigate to the Sauce Demo login page |
| 64 | + When I enter username "<username>" and password "<password>" |
| 65 | + And I click the login button |
| 66 | + Then I should see an error message |
| 67 | +
|
| 68 | + Examples: |
| 69 | + | username | password | |
| 70 | + | invalid | wrong_pass | |
| 71 | +``` |
| 72 | + |
| 73 | +## ▶️ Running Tests |
| 74 | + |
| 75 | +### Run All Scenarios |
| 76 | +```sh |
| 77 | +npx cucumber-js |
| 78 | +``` |
| 79 | + |
| 80 | +### Run Only Positive Scenarios |
| 81 | +```sh |
| 82 | +npx cucumber-js --tags "@positive" |
| 83 | +``` |
| 84 | + |
| 85 | +### Run Only Negative Scenarios |
| 86 | +```sh |
| 87 | +npx cucumber-js --tags "@negative" |
| 88 | +``` |
| 89 | + |
| 90 | +### Run Tests in Headed Mode (Non-Headless) |
| 91 | +```sh |
| 92 | +HEADLESS=false npx cucumber-js |
| 93 | +``` |
| 94 | + |
| 95 | +## 📊 Generating Reports |
| 96 | + |
| 97 | +### Generate Multiple Cucumber HTML Report |
| 98 | +```sh |
| 99 | +npm run report |
| 100 | +``` |
| 101 | + |
| 102 | +### Generate Allure Report |
| 103 | +```sh |
| 104 | +npm run allure-report |
| 105 | +``` |
| 106 | + |
| 107 | +## 🛠 Debugging |
| 108 | + |
| 109 | +If you encounter issues, try: |
| 110 | +```sh |
| 111 | +npx playwright test --debug |
| 112 | +``` |
| 113 | + |
| 114 | +## 📜 License |
| 115 | +This project is licensed under the **MIT License**. |
| 116 | + |
| 117 | +# PlaywrightTypeScriptUsingBDD |
0 commit comments