-
-
Notifications
You must be signed in to change notification settings - Fork 342
feat: Add Playwright module #1288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
HofmeisterAn
merged 19 commits into
testcontainers:develop
from
alimahboubi:feature/PlaywrightModule
Nov 7, 2025
Merged
Changes from 15 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
1586132
Add Testcontainers.Playwright library
alimahboubi f7e2e31
Add Playwright test setup and initial tests
alimahboubi 9a0800a
Update xunit package reference to latest version
alimahboubi c4bea33
Refactor test project settings
alimahboubi 70018cb
Add missing System and threading imports
alimahboubi 3733a88
Refactor usings in test files
alimahboubi b93c4a6
Merge remote-tracking branch 'origin/develop' into feature/Playwright…
alimahboubi 6c55ebf
Fix merge conflicts
alimahboubi f805a4f
Add Playwright test to CiCD
alimahboubi 26c6749
Merge branch 'develop' into feature/PlaywrightModule
alimahboubi f1e6d08
Merge remote-tracking branch 'origin/develop' into fork/alimahboubi/f…
HofmeisterAn b877abc
chore: Update project configurations
HofmeisterAn fc50cad
fix: Implement XunitV3 interface
HofmeisterAn 2e037be
chore: Align with the WebDriver module
HofmeisterAn 2534b90
chore: Remove BOM
HofmeisterAn e2effe8
docs: Add Playwright module docs
HofmeisterAn d7ce6ac
chore: Add some more info
HofmeisterAn 3d1d913
chore: Use MS image
HofmeisterAn 1a29df6
Merge branch 'develop' into feature/PlaywrightModule
HofmeisterAn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| root = true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| namespace Testcontainers.Playwright; | ||
|
|
||
| /// <summary> | ||
| /// Playwright browser configuration. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// The browsers are standalone, pre-built Playwright versions from the | ||
| /// https://github.com/JacobLinCool/playwright-docker repository. | ||
| /// </remarks> | ||
| [PublicAPI] | ||
| public readonly struct PlaywrightBrowser | ||
| { | ||
| /// <summary> | ||
| /// Gets the Playwright standalone Chrome configuration. | ||
| /// </summary> | ||
| public static readonly PlaywrightBrowser Chrome = new PlaywrightBrowser("jacoblincool/playwright:chrome-server-1.55.1"); | ||
|
|
||
| /// <summary> | ||
| /// Gets the Playwright standalone Chromium configuration. | ||
| /// </summary> | ||
| public static readonly PlaywrightBrowser Chromium = new PlaywrightBrowser("jacoblincool/playwright:chromium-server-1.55.1"); | ||
|
|
||
| /// <summary> | ||
| /// Gets the Playwright standalone Firefox configuration. | ||
| /// </summary> | ||
| public static readonly PlaywrightBrowser Firefox = new PlaywrightBrowser("jacoblincool/playwright:firefox-server-1.55.1"); | ||
|
|
||
| /// <summary> | ||
| /// Gets the Playwright standalone Edge configuration. | ||
| /// </summary> | ||
| public static readonly PlaywrightBrowser Edge = new PlaywrightBrowser("jacoblincool/playwright:msedge-server-1.55.1"); | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="PlaywrightBrowser" /> struct. | ||
| /// </summary> | ||
| /// <param name="image">The Playwright standalone Docker image.</param> | ||
| public PlaywrightBrowser(string image) | ||
| : this(new DockerImage(image)) | ||
| { | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="PlaywrightBrowser" /> struct. | ||
| /// </summary> | ||
| /// <param name="image">The Playwright standalone Docker image.</param> | ||
| public PlaywrightBrowser(IImage image) | ||
| { | ||
| Image = image; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets the Playwright standalone Docker image. | ||
| /// </summary> | ||
| [NotNull] | ||
| public IImage Image { get; } | ||
| } | ||
HofmeisterAn marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| namespace Testcontainers.Playwright; | ||
|
|
||
| /// <inheritdoc cref="ContainerBuilder{TBuilderEntity, TContainerEntity, TConfigurationEntity}" /> | ||
| [PublicAPI] | ||
| public sealed class PlaywrightBuilder : ContainerBuilder<PlaywrightBuilder, PlaywrightContainer, PlaywrightConfiguration> | ||
| { | ||
| public const string PlaywrightNetworkAlias = "standalone-container"; | ||
|
|
||
| public const ushort PlaywrightPort = 53333; | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="PlaywrightBuilder" /> class. | ||
| /// </summary> | ||
| public PlaywrightBuilder() | ||
| : this(new PlaywrightConfiguration()) | ||
| { | ||
| DockerResourceConfiguration = Init().DockerResourceConfiguration; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="PlaywrightBuilder" /> class. | ||
| /// </summary> | ||
| /// <param name="resourceConfiguration">The Docker resource configuration.</param> | ||
| private PlaywrightBuilder(PlaywrightConfiguration resourceConfiguration) | ||
| : base(resourceConfiguration) | ||
| { | ||
| DockerResourceConfiguration = resourceConfiguration; | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| protected override PlaywrightConfiguration DockerResourceConfiguration { get; } | ||
|
|
||
| /// <summary> | ||
| /// Sets the Playwright browser configuration. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// https://github.com/JacobLinCool/playwright-docker. | ||
| /// </remarks> | ||
| /// <param name="playwrightBrowser">The Playwright browser configuration.</param> | ||
| /// <returns>A configured instance of <see cref="PlaywrightBuilder" />.</returns> | ||
| public PlaywrightBuilder WithBrowser(PlaywrightBrowser playwrightBrowser) | ||
| { | ||
| return WithImage(playwrightBrowser.Image); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public override PlaywrightContainer Build() | ||
| { | ||
| Validate(); | ||
| return new PlaywrightContainer(DockerResourceConfiguration); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| protected override PlaywrightBuilder Init() | ||
| { | ||
| return base.Init() | ||
| .WithBrowser(PlaywrightBrowser.Chrome) | ||
| .WithNetwork(new NetworkBuilder().Build()) | ||
| .WithNetworkAliases(PlaywrightNetworkAlias) | ||
| .WithPortBinding(PlaywrightPort, true) | ||
| .WithWaitStrategy(Wait.ForUnixContainer().UntilMessageIsLogged("ws://localhost:" + PlaywrightPort + "/playwright")); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| protected override PlaywrightBuilder Clone(IResourceConfiguration<CreateContainerParameters> resourceConfiguration) | ||
| { | ||
| return Merge(DockerResourceConfiguration, new PlaywrightConfiguration(resourceConfiguration)); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| protected override PlaywrightBuilder Clone(IContainerConfiguration resourceConfiguration) | ||
| { | ||
| return Merge(DockerResourceConfiguration, new PlaywrightConfiguration(resourceConfiguration)); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| protected override PlaywrightBuilder Merge(PlaywrightConfiguration oldValue, PlaywrightConfiguration newValue) | ||
| { | ||
| return new PlaywrightBuilder(new PlaywrightConfiguration(oldValue, newValue)); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| namespace Testcontainers.Playwright; | ||
|
|
||
| /// <inheritdoc cref="ContainerConfiguration" /> | ||
| [PublicAPI] | ||
| public sealed class PlaywrightConfiguration : ContainerConfiguration | ||
| { | ||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="PlaywrightConfiguration" /> class. | ||
| /// </summary> | ||
| public PlaywrightConfiguration() | ||
| { | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="PlaywrightConfiguration" /> class. | ||
| /// </summary> | ||
| /// <param name="resourceConfiguration">The Docker resource configuration.</param> | ||
| public PlaywrightConfiguration(IResourceConfiguration<CreateContainerParameters> resourceConfiguration) | ||
| : base(resourceConfiguration) | ||
| { | ||
| // Passes the configuration upwards to the base implementations to create an updated immutable copy. | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="PlaywrightConfiguration" /> class. | ||
| /// </summary> | ||
| /// <param name="resourceConfiguration">The Docker resource configuration.</param> | ||
| public PlaywrightConfiguration(IContainerConfiguration resourceConfiguration) | ||
| : base(resourceConfiguration) | ||
| { | ||
| // Passes the configuration upwards to the base implementations to create an updated immutable copy. | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="PlaywrightConfiguration" /> class. | ||
| /// </summary> | ||
| /// <param name="resourceConfiguration">The Docker resource configuration.</param> | ||
| public PlaywrightConfiguration(PlaywrightConfiguration resourceConfiguration) | ||
| : this(new PlaywrightConfiguration(), resourceConfiguration) | ||
| { | ||
| // Passes the configuration upwards to the base implementations to create an updated immutable copy. | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="PlaywrightConfiguration" /> class. | ||
| /// </summary> | ||
| /// <param name="oldValue">The old Docker resource configuration.</param> | ||
| /// <param name="newValue">The new Docker resource configuration.</param> | ||
| public PlaywrightConfiguration(PlaywrightConfiguration oldValue, PlaywrightConfiguration newValue) | ||
| : base(oldValue, newValue) | ||
| { | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| namespace Testcontainers.Playwright; | ||
|
|
||
| /// <inheritdoc cref="DockerContainer" /> | ||
| [PublicAPI] | ||
| public sealed class PlaywrightContainer : DockerContainer | ||
| { | ||
| private readonly PlaywrightConfiguration _configuration; | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="PlaywrightContainer" /> class. | ||
| /// </summary> | ||
| /// <param name="configuration">The container configuration.</param> | ||
| public PlaywrightContainer(PlaywrightConfiguration configuration) | ||
| : base(configuration) | ||
| { | ||
| _configuration = configuration; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets the Playwright connection string. | ||
| /// </summary> | ||
| /// <returns>The Playwright connection string.</returns> | ||
| public string GetConnectionString() | ||
| { | ||
| return new UriBuilder("ws", Hostname, GetMappedPublicPort(PlaywrightBuilder.PlaywrightPort), "/playwright").ToString(); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets the Playwright network. | ||
| /// </summary> | ||
| /// <returns>The Playwright network.</returns> | ||
| public INetwork GetNetwork() | ||
| { | ||
| return _configuration.Networks.Single(); | ||
| } | ||
| } |
12 changes: 12 additions & 0 deletions
12
src/Testcontainers.Playwright/Testcontainers.Playwright.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <TargetFrameworks>net8.0;net9.0;netstandard2.0;netstandard2.1</TargetFrameworks> | ||
| <LangVersion>latest</LangVersion> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <PackageReference Include="JetBrains.Annotations" VersionOverride="2023.3.0" PrivateAssets="All"/> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <ProjectReference Include="../Testcontainers/Testcontainers.csproj"/> | ||
| </ItemGroup> | ||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| global using System; | ||
| global using System.Linq; | ||
| global using Docker.DotNet.Models; | ||
| global using DotNet.Testcontainers.Builders; | ||
| global using DotNet.Testcontainers.Configurations; | ||
| global using DotNet.Testcontainers.Containers; | ||
| global using DotNet.Testcontainers.Images; | ||
| global using DotNet.Testcontainers.Networks; | ||
| global using JetBrains.Annotations; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| root = true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ubuntu-24.04 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.