Reqnroll based autotest framework
BddDotNet based autotest framework with Playwright integration
Key features:
- Gherkin syntax support
- C# expressions support for Gherkin syntax
- Component framework for UI testing
- Page object pattern support
- Playwright integration
- Test data management framework
Feature: CheckoutForm
Scenario: checkout form validation test
Given navigate to '@Data.Common.HomePageUrl'
When set following values:
| Name | Value |
| checkout > first name | first_name |
| checkout > last name | last_name |
And click on 'checkout > continue to checkout'
Then should be visible:
| Name |
| checkout > username error message |
And should have following values:
| Name | Value |
| checkout > username error message | Your username is required. |
- .NET 8+
- Visual Studio 2022 or Visual Studio Code
- Reqnroll plugin for Visual Studio 2022 or Cucumber plugin for Visual Studio Code
- https://www.nuget.org/packages/AutoTests.Framework
- https://www.nuget.org/packages/AutoTests.Framework.Playwright
You can find example in Bootstrap.Tests project for UI testing
Guide:
- Create new console application for .NET 9
- Install nuget packages:
Nuget package | Link |
---|---|
AutoTests.Framework.Playwright | AutoTests.Framework.Playwright |
BddDotNet.Gherkin.SourceGenerator | BddDotNet.Gherkin.SourceGenerator |
Microsoft.Playwright | Microsoft.Playwright |
- Configure application in
Program.cs
. Example:
using AutoTests.Framework;
using AutoTests.Framework.Playwright;
using BddDotNet;
using Bootstrap.Tests.Pages;
using Microsoft.Testing.Platform.Builder;
var builder = await TestApplication.CreateBuilderAsync(args);
var services = builder.AddBddDotNet();
services.SinglePageChromiumPlaywright(new() { Headless = false });
services.Page<BootstrapApplication>();
services.SourceGeneratedGherkinScenarios();
services.SourceGeneratedGherkinSteps();
using var testApp = await builder.BuildAsync();
return await testApp.RunAsync();
- Add page objects. Example:
using AutoTests.Framework.Pages;
namespace Bootstrap.Tests.Pages;
internal sealed class BootstrapApplication
{
[Route("checkout")]
public required Checkout Checkout { get; init; }
}
internal sealed class Checkout
{
[Route("continue to checkout")]
[Options(".btn-primary")]
public required Button ContinueToCheckout { get; init; }
[Route("first name")]
[Options("#firstName")]
public required Input FirstName { get; init; }
[Route("last name")]
[Options("#lastName")]
public required Input LastName { get; init; }
[Route("username error message")]
[Options("#username ~ .invalid-feedback")]
public required Label UsernameErrorMessage { get; init; }
}
- Done. You can add gherkin feature files with test scenarios. Example
CheckoutForm.feature
:
Feature: CheckoutForm
Scenario: checkout form validation test
Given navigate to 'https://getbootstrap.com/docs/4.3/examples/checkout/'
When set following values:
| Name | Value |
| checkout > first name | first_name |
| checkout > last name | last_name |
And click on 'checkout > continue to checkout'
Then should be visible:
| Name |
| checkout > username error message |
And should have following values:
| Name | Value |
| checkout > username error message | Your username is required. |
- Install
BddDotNet.Gherkin.CSharpExpressions
nuget package - Add service with C# expressions
using AutoTests.Framework.Resources;
namespace Bootstrap.Tests;
public sealed class CSharpExpressions(IDynamicDataService dynamicDataService)
{
public dynamic Data { get; } = dynamicDataService.Data;
}
- Configure
BddDotNet.Gherkin.CSharpExpressions
inProgram.cs
services.CSharpExpressions<CSharpExpressions>(ScriptOptions.Default.AddReferences("Microsoft.CSharp"));
services.DynamicResourcesData([Assembly.GetExecutingAssembly()]);
You can create json file in Data subfolder and get access to content in feature to it like:
Feature: CheckoutForm
Scenario: checkout form validation test
Given navigate to '@Data.Common.HomePageUrl' #return value HomePageUrl from Data\Common.json
You can find example in 'Bootstrap.Tests'