Running Tests
Execute your SpecFlow test suite with various options for filtering, parallelisation, and output formats.
Basic Test Execution
Run All Tests
This executes all scenarios in your Tests.E2E/Features/ directory using the NUnit test runner.
Run Specific Features
Filter by feature file name:
Filter by feature tag:
Run Specific Scenarios
Parallel Execution
Run tests in parallel to reduce execution time:
Best practices:
- Start with 2-4 workers and increase based on system resources
- Monitor CPU and memory usage
- Some tests may require sequential execution (use
@sequentialtag)
Sequential Execution
For tests that must run in order:
@sequential
Feature: Multi-step Workflow
Scenario: Complete checkout process
Given I add items to cart
When I proceed to checkout
Then I should see order confirmation
Run sequential tests:
Environment Configuration
Using Environment Variables
Override configuration at runtime:
Environment-Specific Settings
The framework automatically loads environment-specific configuration:
appsettings.json(base)appsettings.{ENVIRONMENT}.json(overrides)
Example:
Test Output Formats
Console Output (Default)
Standard NUnit console output:
HTML Report
Generate an HTML report:
Output location: Tests.E2E/TestResults/report.html
JUnit XML (for Allure)
Generate JUnit XML for Allure reporting:
See Reporting for Allure setup.
Verbose Output
Get detailed test execution information:
Test Filtering Strategies
By Tag
By Feature
By Scenario
Timeout Configuration
Global Timeout
Set via environment variable:
Per-Test Timeout
Override in LifecycleHooks.cs:
[BeforeScenario]
public async Task SetTimeout()
{
var timeoutMs = Environment.GetEnvironmentVariable("PW_TIMEOUT_MS");
if (!string.IsNullOrEmpty(timeoutMs))
{
Page.SetDefaultTimeout(int.Parse(timeoutMs));
}
}
Browser Configuration
Headless Mode
Configure in appsettings.json:
{
"Headless": true
}
Or override at runtime:
Browser Selection
The framework uses Chromium by default. To change:
- Update
LifecycleHooks.cs:
[BeforeScenario]
public async Task SetupBrowser()
{
var browserType = Environment.GetEnvironmentVariable("BROWSER") ?? "chromium";
// Initialise browser based on type
}
- Run with browser selection:
Debugging Tests
Attach Debugger
Run tests with debugger attached:
Set breakpoints in your step definitions or Page Objects, then attach your IDE debugger.
Screenshots on Failure
Screenshots are automatically captured on test failure. Location: artifacts/screenshots/
Video Recording
Enable video recording for failed tests in LifecycleHooks.cs:
[AfterScenario]
public async Task CaptureVideoOnFailure()
{
if (ScenarioContext.ScenarioExecutionStatus == ScenarioExecutionStatus.TestError)
{
await Page.Video.SaveAsAsync($"artifacts/videos/{ScenarioContext.ScenarioInfo.Title}.webm");
}
}
Performance Optimisation
Reduce Timeouts for Faster Runs
Skip Non-Critical Tests
Tag non-critical tests and exclude them:
@non-critical
Scenario: Advanced feature test
Use Test Retries
Configure retries in nunit.runsettings:
<NUnit>
<TestSettings>
<RetryCount>2</RetryCount>
</TestSettings>
</NUnit>