Troubleshooting
Common issues and solutions when working with the Playwright C# Agentic Framework.
Installation Issues
Playwright Browsers Not Installing
Problem: playwright.sh: command not found or browsers fail to install.
Solution:
- Ensure the project is built first:
- Use the correct path to the script:
- For Linux, install system dependencies:
.NET SDK Version Mismatch
Problem: error NETSDK1045: The current .NET SDK does not support targeting .NET 9.0
Solution:
- Check installed .NET versions:
- Install .NET SDK 9.0:
- Verify installation:
Test Execution Issues
Tests Not Found
Problem: No test is available in the given sources
Solution:
- Verify feature files exist:
- Ensure SpecFlow is properly configured in
.csproj:
<PackageReference Include="SpecFlow" Version="3.9.74" />
<PackageReference Include="SpecFlow.NUnit" Version="3.9.74" />
- Rebuild the project:
Timeout Errors
Problem: Tests fail with Timeout 5000ms exceeded
Solution:
- Increase timeout globally:
- Increase timeout for specific steps:
[When(@"I wait for element")]
public async Task WhenIWaitForElement()
{
await Page.WaitForSelectorAsync("#element", new PageWaitForSelectorOptions
{
Timeout = 10000
});
}
- Check for slow network or application:
Element Not Found
Problem: Locator not found or Element not visible
Solution:
- Verify the element exists in the DOM:
// Add debugging
var element = Page.Locator("#my-element");
var count = await element.CountAsync();
Console.WriteLine($"Element count: {count}");
- Wait for element to be visible:
await Page.WaitForSelectorAsync("#my-element", new PageWaitForSelectorOptions
{
State = WaitForSelectorState.Visible
});
- Use the Healer to find alternative selectors:
Healing Issues
Registry Not Found
Problem: Registry file not found: agents/selectors.registry.json
Solution:
Run the learn command to create the registry:
Ensure the agents/ directory exists:
No Working Alternatives
Problem: Healer cannot find a working alternative selector
Solution:
- Update the registry:
- Check if element was removed:
- Inspect the application to verify the element still exists
- If removed, manually update the Page Object or test scenario
- Verify DOM structure:
// Add debugging in your Page Object
var pageContent = await Page.ContentAsync();
Console.WriteLine(pageContent);
Roslyn Compilation Errors
Problem: Healing produces compilation errors
Solution:
- Check the modified Page Object:
- Verify selector syntax:
- Ensure the selector is valid Playwright syntax
- Check for missing quotes or brackets
- Manual fix:
- Revert the healing changes
- Manually update the selector
- Re-run learn to update the registry
Configuration Issues
AppSettings Not Loading
Problem: Configuration values are null or default
Solution:
- Verify file location:
- Ensure
appsettings.jsonis inTests.E2E/Support/ - Check file is copied to output directory
- Ensure
- Check JSON syntax:
{
"BaseUrl": "https://example.com/",
"DefaultUserEmail": "user@example.com"
}
- Use environment variables:
Environment-Specific Settings Not Applied
Problem: appsettings.qa.json not loading
Solution:
- Set environment variable:
- Verify file naming:
- Must be
appsettings.{ENVIRONMENT}.json - Case-sensitive on Linux
- Must be
- Check configuration loading:
// In your configuration class
var environment = Environment.GetEnvironmentVariable("ENVIRONMENT") ?? "";
var configBuilder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.AddJsonFile($"appsettings.{environment}.json", optional: true);
Reporting Issues
Allure Report Empty
Problem: Allure report shows no tests
Solution:
- Verify JUnit XML exists:
- Check XML format:
- Re-run with JUnit logger:
Screenshots Not Appearing
Problem: Screenshots missing in Allure report
Solution:
- Verify screenshot directory:
- Check screenshot capture in LifecycleHooks:
[AfterScenario]
public async Task CaptureScreenshotOnFailure()
{
if (ScenarioContext.ScenarioExecutionStatus == ScenarioExecutionStatus.TestError)
{
var screenshot = await Page.ScreenshotAsync();
var fileName = $"artifacts/screenshots/{ScenarioContext.ScenarioInfo.Title}.png";
await File.WriteAllBytesAsync(fileName, screenshot);
}
}
- Ensure directory exists:
Directory.CreateDirectory("artifacts/screenshots");
Performance Issues
Slow Test Execution
Problem: Tests take too long to run
Solution:
- Run in parallel:
- Reduce timeouts:
- Skip non-critical tests:
- Use headless mode:
{
"Headless": true
}
High Memory Usage
Problem: Tests consume too much memory
Solution:
- Limit parallel workers:
- Close pages after scenarios:
[AfterScenario]
public async Task Cleanup()
{
await Page.CloseAsync();
}
- Disable video recording:
- Remove or disable video capture in LifecycleHooks
Debugging Tips
Enable Verbose Logging
Add Console Logging
[When(@"I perform action")]
public async Task WhenIPerformAction()
{
Console.WriteLine("Starting action...");
await Page.ClickAsync("#button");
Console.WriteLine("Action completed");
}
Use Playwright Inspector
// Add to LifecycleHooks
[BeforeScenario("@debug")]
public async Task LaunchWithInspector()
{
await Page.PauseAsync(); // Opens Playwright Inspector
}
Run with debug tag:
Capture Network Logs
Page.Request += (sender, e) =>
{
Console.WriteLine($"Request: {e.Method} {e.Url}");
};
Page.Response += (sender, e) =>
{
Console.WriteLine($"Response: {e.Status} {e.Url}");
};
Getting Help
If you encounter issues not covered here:
- Check logs:
- Test output:
dotnet test --verbosity detailed - Application logs: Check
artifacts/logs/
- Test output:
- Review documentation:
- Inspect artifacts:
- Screenshots:
artifacts/screenshots/ - Videos:
artifacts/videos/ - Page sources:
artifacts/pagesource/
- Screenshots:
- Verify configuration:
appsettings.jsonsyntax- Environment variables
- Selector registry format