Feature/playwright module
What does this PR do?
This pull request introduces a new module to the Testcontainers for .NET library, enabling support for Playwright-based browser testing within Docker containers. The module allows users to run Playwright tests in isolated environments, facilitating consistent and reproducible end-to-end testing scenarios.
Why is it important?
Integrating Playwright into Testcontainers for .NET addresses the growing demand for modern, reliable browser automation tools in testing workflows. Playwright offers robust features for cross-browser testing, and its inclusion enhances the library's capabilities, providing developers with a comprehensive solution for containerized testing environments.
Related issues
- Module #1033
Follow-ups
-
Update the official documentation to include usage guidelines and examples for the Playwright module.
-
Monitor community feedback to identify potential enhancements or issues related to the new module.
Deploy Preview for testcontainers-dotnet ready!
| Name | Link |
|---|---|
| Latest commit | 1a29df68ed944ab479afb931140b0f1147f1c92d |
| Latest deploy log | https://app.netlify.com/projects/testcontainers-dotnet/deploys/690d040a56d7c200084cb2d1 |
| Deploy Preview | https://deploy-preview-1288--testcontainers-dotnet.netlify.app |
| Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify project configuration.
Summary by CodeRabbit
-
New Features
- Added Playwright module support enabling browser testing with containerized Playwright instances
- Includes container builder and configuration APIs for Playwright setup
-
Documentation
- Added Playwright module documentation with configuration examples and best practices
-
Tests
- Added test suite validating Playwright container functionality
Walkthrough
This PR introduces a complete Testcontainers.Playwright module, adding containerized Playwright browser support. It includes builder and configuration classes following Testcontainers patterns, a container implementation, end-to-end tests verifying browser automation against containerized applications, and comprehensive module documentation.
Changes
| Cohort / File(s) | Summary |
|---|---|
Package Dependencies Directory.Packages.props |
Added Microsoft.Playwright v1.55.0 package version |
Solution Configuration Testcontainers.sln |
Registered new Testcontainers.Playwright and Testcontainers.Playwright.Tests projects with Debug/Release configurations and proper nesting |
Core Module Implementation src/Testcontainers.Playwright/.editorconfig, PlaywrightBuilder.cs, PlaywrightConfiguration.cs, PlaywrightContainer.cs, Testcontainers.Playwright.csproj, Usings.cs |
Added PlaywrightBuilder (sealed, extending ContainerBuilder) with Init(), Build(), and Clone() methods; PlaywrightConfiguration (sealed, extending ContainerConfiguration) with immutable constructors; PlaywrightContainer (sealed, extending DockerContainer) with GetConnectionString() and GetNetwork(); project targets net8.0/net9.0/netstandard2.0/2.1; global usings for Docker, Testcontainers, and JetBrains libraries |
Test Project Implementation tests/Testcontainers.Playwright.Tests/.editorconfig, .runs-on, PlaywrightContainerTest.cs, Testcontainers.Playwright.Tests.csproj, Usings.cs |
Added abstract PlaywrightContainerTest with IAsyncLifetime managing Playwright and hello-world containers; HeadingElementReturnsHelloWorld test validates end-to-end browser automation; nested PlaywrightDefaultConfiguration test class; project targets net9.0 with xUnit, Microsoft.Playwright, and test infrastructure dependencies; runner image set to ubuntu-24.04 |
Documentation docs/modules/index.md, docs/modules/playwright.md, mkdocs.yml |
Added Playwright module documentation with setup instructions, lifecycle management, container creation examples, network configuration guidance, and browser selection options (Chromium/Firefox/Edge); integrated into module index and MkDocs navigation |
Sequence Diagram
sequenceDiagram
participant Test as PlaywrightContainerTest
participant HelloWorld as HelloWorldContainer
participant Playwright as PlaywrightContainer
participant Browser as Playwright Browser
participant Page as Browser Page
Test->>HelloWorld: Build and start
Test->>Playwright: Build and start (default config)
Test->>Playwright: InitializeAsync
activate Playwright
Note over Playwright: WebSocket at localhost:8080
deactivate Playwright
Test->>Browser: Launch and connect via WebSocket
activate Browser
Test->>Page: Create new page
Test->>Page: Navigate to HelloWorld URL
Test->>Page: Query h1 element
Test->>Page: Get inner text
Note over Page: Assert: "Hello world"
Test->>Page: Close
Test->>Browser: Close
deactivate Browser
Test->>Playwright: DisposeAsync
Test->>HelloWorld: Dispose
Estimated Code Review Effort
🎯 3 (Moderate) | ⏱️ ~25 minutes
Areas requiring attention:
- PlaywrightBuilder.cs: Validate Init() method configuration chain (image, network, port binding, entrypoint, wait strategy) aligns with Playwright container requirements and follows established builder patterns
- PlaywrightContainer.cs: Verify GetConnectionString() correctly constructs WebSocket URI for Playwright protocol connectivity
- PlaywrightContainerTest.cs: Review end-to-end test logic for proper async lifecycle management (IAsyncLifetime), container networking setup, and browser automation assertions
- Configuration inheritance chain: Confirm PlaywrightConfiguration constructors properly propagate through base ContainerConfiguration across immutable merge patterns
- Project dependencies: Verify Testcontainers.Playwright.Tests correctly references required projects and test frameworks (xUnit, Microsoft.Playwright)
Poem
🐰 A playwright hops into a container so bright,
With browsers bundled tight, for testing each night,
The builder hops merrily, configuring with care,
While tests verify pages with automated flair,
In networks they gather, headless and bold,
Testcontainers' new stage, a tale to be told! 🎭
Pre-merge checks and finishing touches
❌ Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Docstring Coverage | ⚠️ Warning | Docstring coverage is 63.33% which is insufficient. The required threshold is 80.00%. | You can run @coderabbitai generate docstrings to improve docstring coverage. |
✅ Passed checks (2 passed)
| Check name | Status | Explanation |
|---|---|---|
| Title check | ✅ Passed | The title 'feat: Add Playwright module' accurately and concisely describes the main change—introducing a new Playwright module to the library. |
| Description check | ✅ Passed | The PR description includes both mandatory sections (What and Why), related issues reference, and follow-ups. All key information is present and well-documented. |
✨ Finishing touches
- [ ] 📝 Generate docstrings
🧪 Generate unit tests (beta)
- [ ] Create PR with unit tests
- [ ] Post copyable unit tests in a comment
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands and usage tips.