An open API service indexing awesome lists of open source software.

https://github.com/phmatray/autotests

Automated E2E testing demo for Blazor using Reqnroll, showcasing BDD acceptance tests with Gherkin syntax and Playwright .NET
https://github.com/phmatray/autotests

blazor csharp demo dotnet e2e gherkin nunit playwright reqnroll testing

Last synced: 26 days ago
JSON representation

Automated E2E testing demo for Blazor using Reqnroll, showcasing BDD acceptance tests with Gherkin syntax and Playwright .NET

Awesome Lists containing this project

README

          

# Ticket Booking Demo Project 🎟️

This repository demonstrates **Automated E2E Testing for Blazor using Reqnroll**. It showcases a simple ticket booking system with acceptance tests written in Gherkin syntax and executed with Playwright .NET.

---

## Table of Contents

- [Features πŸš€](#features-)
- [Prerequisites βš™οΈ](#prerequisites-)
- [Getting Started πŸ”§](#getting-started-)
- [Running the Application πŸš€](#running-the-application-)
- [Running the Tests πŸ§ͺ](#running-the-tests-)
- [Project Structure πŸ“‚](#project-structure-)
- [Contributing 🀝](#contributing-)
- [License πŸ“„](#license-)

---

## Features πŸš€

- **Event Listing:** Displays a list of upcoming events.
- **Event Details:** Shows detailed information for each event.
- **Ticket Booking:** Allows users to book tickets by entering their name.
- **Automated Acceptance Tests:** Validates key user flows using Gherkin-based specifications with Reqnroll and Playwright .NET.

---

## Prerequisites βš™οΈ

- [.NET 9 SDK](https://dotnet.microsoft.com/download/dotnet/9.0) or later

---

## Getting Started πŸ”§

1. **Clone the Repository**

```bash
git clone https://github.com/phmatray/AutoTests.git
cd AutoTests
```

2. **Restore .NET Packages**

From the solution directory, run:

```bash
dotnet restore
```

3. **Install Playwright Browsers**

Navigate to the test project directory and install the required browsers:

```bash
cd TicketBookingApp.EndToEndTests
pwsh bin/Debug/net9.0/playwright.ps1 install
```

4**Project Configuration**

The test project uses the following `csproj` configuration:

```xml


net9.0









```

---

## Running the Application πŸš€

1. **Navigate to the Blazor Project Directory**

```bash
cd TicketBookingApp
```

2. **Run the Blazor Server Application**

```bash
dotnet run
```

3. **Access the Application**

Open your browser and navigate to `http://localhost:5140/` (or the URL provided by your console) to view the ticket booking system.

---

## Running the Tests πŸ§ͺ

1. **Ensure the Blazor Application Is Running**

Start the Blazor app as described above.

2. **Navigate to the Test Project Directory**

```bash
cd TicketBookingApp.EndToEndTests
```

3. **Run the Test Suite**

```bash
dotnet test
```

The acceptance tests are written in Gherkin and located in the `/features` folder. Here’s an example of the feature file:

```gherkin
Feature: Ticket Booking System
As a user,
I want to view available events and book tickets,
So that I can attend an event.

Scenario: Home page lists available events
Given I navigate to the home page
Then I should see a list of events

Scenario: Event details are displayed correctly
Given I navigate to the event details page for event with id 1
Then I should see the event title "Rock Concert"

Scenario: Booking a ticket successfully
Given I navigate to the booking page for event with id 1
When I enter "John Doe" into the "User Name" field
And I click on "Confirm Booking"
Then I should see a confirmation message "Booking Confirmed"
```

---

## Project Structure πŸ“‚

```
/TicketBookingApp
β”œβ”€β”€ Models/ // Data models (e.g., Event.cs)
β”œβ”€β”€ Pages/ // Blazor pages (Index.razor, EventDetails.razor, Booking.razor)
β”œβ”€β”€ Services/ // Application services (e.g., EventService.cs)
└── Program.cs // Application entry point

/TicketBookingApp.EndToEndTests
β”œβ”€β”€ Features/ // Gherkin feature files (e.g., TicketBooking.feature)
β”œβ”€β”€ Hooks/ // Playwright setup and teardown hooks
β”œβ”€β”€ Pages/ // Page object models (Home, Event Details, Booking pages)
β”œβ”€β”€ StepDefinitions/ // Reqnroll/SpecFlow step definitions binding Gherkin to Playwright
└── TicketBooking.feature // Acceptance tests in Gherkin syntax
```

---

## Contributing 🀝

Contributions are welcome! If you have suggestions, bug fixes, or new features, please open an issue or submit a pull request.
**Maintainer:** [phmatray](https://github.com/phmatray)

---

## License πŸ“„

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.

---

Happy coding and testing! πŸŽ‰