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:

  1. Ensure the project is built first:
dotnet build ./Tests.E2E/Tests.E2E.csproj
  1. Use the correct path to the script:
bash ./Tests.E2E/bin/Debug/net9.0/playwright.sh install --with-deps chromium
  1. For Linux, install system dependencies:
# Ubuntu/Debian sudo apt-get install -y libnss3 libatk1.0-0 libatk-bridge2.0-0 libcups2 libdrm2 libxkbcommon0 libxcomposite1 libxdamage1 libxfixes3 libxrandr2 libgbm1 libasound2 # Then install browsers bash ./Tests.E2E/bin/Debug/net9.0/playwright.sh install --with-deps chromium

.NET SDK Version Mismatch

Problem: error NETSDK1045: The current .NET SDK does not support targeting .NET 9.0

Solution:

  1. Check installed .NET versions:
dotnet --list-sdks
  1. Install .NET SDK 9.0:
# macOS brew install --cask dotnet-sdk # Or download from https://dotnet.microsoft.com/download
  1. Verify installation:
dotnet --version # Should output 9.0.x or higher

Test Execution Issues

Tests Not Found

Problem: No test is available in the given sources

Solution:

  1. Verify feature files exist:
ls Tests.E2E/Features/*.feature
  1. Ensure SpecFlow is properly configured in .csproj:
<PackageReference Include="SpecFlow" Version="3.9.74" />
<PackageReference Include="SpecFlow.NUnit" Version="3.9.74" />
  1. Rebuild the project:
dotnet clean dotnet build dotnet test

Timeout Errors

Problem: Tests fail with Timeout 5000ms exceeded

Solution:

  1. Increase timeout globally:
PW_TIMEOUT_MS=10000 dotnet test ./Tests.E2E/Tests.E2E.csproj
  1. Increase timeout for specific steps:
[When(@"I wait for element")]
public async Task WhenIWaitForElement()
{
    await Page.WaitForSelectorAsync("#element", new PageWaitForSelectorOptions 
    { 
        Timeout = 10000 
    });
}
  1. Check for slow network or application:
# Run with verbose logging dotnet test ./Tests.E2E/Tests.E2E.csproj --verbosity detailed

Element Not Found

Problem: Locator not found or Element not visible

Solution:

  1. 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}");
  1. Wait for element to be visible:
await Page.WaitForSelectorAsync("#my-element", new PageWaitForSelectorOptions 
{ 
    State = WaitForSelectorState.Visible 
});
  1. Use the Healer to find alternative selectors:
dotnet run --project ./Agents/Agents.csproj -- heal \ --test ./Tests.E2E/Tests.E2E.csproj

Healing Issues

Registry Not Found

Problem: Registry file not found: agents/selectors.registry.json

Solution:

Run the learn command to create the registry:

dotnet run --project ./Agents/Agents.csproj -- learn \ --test ./Tests.E2E/Tests.E2E.csproj \ --out ./agents/selectors.registry.json

Ensure the agents/ directory exists:

mkdir -p agents

No Working Alternatives

Problem: Healer cannot find a working alternative selector

Solution:

  1. Update the registry:
# Re-run learn to capture new selectors dotnet run --project ./Agents/Agents.csproj -- learn \ --test ./Tests.E2E/Tests.E2E.csproj \ --out ./agents/selectors.registry.json
  1. Check if element was removed:
    • Inspect the application to verify the element still exists
    • If removed, manually update the Page Object or test scenario
  2. 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:

  1. Check the modified Page Object:
# Review the changed file git diff Framework/Pages/YourPage.cs
  1. Verify selector syntax:
    • Ensure the selector is valid Playwright syntax
    • Check for missing quotes or brackets
  2. 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:

  1. Verify file location:
    • Ensure appsettings.json is in Tests.E2E/Support/
    • Check file is copied to output directory
  2. Check JSON syntax:
{
  "BaseUrl": "https://example.com/",
  "DefaultUserEmail": "user@example.com"
}
  1. Use environment variables:
BASE_URL=https://example.com dotnet test

Environment-Specific Settings Not Applied

Problem: appsettings.qa.json not loading

Solution:

  1. Set environment variable:
ENVIRONMENT=qa dotnet test ./Tests.E2E/Tests.E2E.csproj
  1. Verify file naming:
    • Must be appsettings.{ENVIRONMENT}.json
    • Case-sensitive on Linux
  2. 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:

  1. Verify JUnit XML exists:
ls -la allure-results/junit.xml
  1. Check XML format:
cat allure-results/junit.xml | head -20
  1. Re-run with JUnit logger:
dotnet test ./Tests.E2E/Tests.E2E.csproj \ --logger:"junit;LogFileName=junit.xml" \ --results-directory ./allure-results

Screenshots Not Appearing

Problem: Screenshots missing in Allure report

Solution:

  1. Verify screenshot directory:
ls -la artifacts/screenshots/
  1. 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);
    }
}
  1. Ensure directory exists:
Directory.CreateDirectory("artifacts/screenshots");

Performance Issues

Slow Test Execution

Problem: Tests take too long to run

Solution:

  1. Run in parallel:
dotnet test ./Tests.E2E/Tests.E2E.csproj -m:4
  1. Reduce timeouts:
PW_TIMEOUT_MS=2000 dotnet test ./Tests.E2E/Tests.E2E.csproj
  1. Skip non-critical tests:
dotnet test --filter "FullyQualifiedName!~@non-critical"
  1. Use headless mode:
{
  "Headless": true
}

High Memory Usage

Problem: Tests consume too much memory

Solution:

  1. Limit parallel workers:
dotnet test ./Tests.E2E/Tests.E2E.csproj -m:2
  1. Close pages after scenarios:
[AfterScenario]
public async Task Cleanup()
{
    await Page.CloseAsync();
}
  1. Disable video recording:
    • Remove or disable video capture in LifecycleHooks

Debugging Tips

Enable Verbose Logging

dotnet test ./Tests.E2E/Tests.E2E.csproj --verbosity detailed

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:

dotnet test --filter "FullyQualifiedName~@debug"

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:

  1. Check logs:
    • Test output: dotnet test --verbosity detailed
    • Application logs: Check artifacts/logs/
  2. Review documentation:
  3. Inspect artifacts:
    • Screenshots: artifacts/screenshots/
    • Videos: artifacts/videos/
    • Page sources: artifacts/pagesource/
  4. Verify configuration:
    • appsettings.json syntax
    • Environment variables
    • Selector registry format