Skip to content
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
<PackageVersion Include="Microsoft.Azure.Cosmos" Version="3.32.1"/>
<PackageVersion Include="Microsoft.Azure.Kusto.Data" Version="12.2.8"/>
<PackageVersion Include="Microsoft.Data.SqlClient" Version="5.2.2"/>
<PackageVersion Include="Microsoft.Playwright" Version="1.55.0"/>
<PackageVersion Include="Milvus.Client" Version="2.2.2-preview.6"/>
<PackageVersion Include="MongoDB.Driver" Version="3.2.0"/>
<PackageVersion Include="MyCouch" Version="7.6.0"/>
Expand Down
14 changes: 14 additions & 0 deletions Testcontainers.sln
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Oracle", "sr
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Papercut", "src\Testcontainers.Papercut\Testcontainers.Papercut.csproj", "{B2608563-8EE4-49AA-A9A0-B1614486AEEF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Playwright", "src\Testcontainers.Playwright\Testcontainers.Playwright.csproj", "{7F91A202-4F07-470D-881C-9A46A700DCA5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.PostgreSql", "src\Testcontainers.PostgreSql\Testcontainers.PostgreSql.csproj", "{8AB91636-9055-4900-A72A-7CFFACDFDBF0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.PubSub", "src\Testcontainers.PubSub\Testcontainers.PubSub.csproj", "{E6642255-667D-476B-B584-089AA5E6C0B1}"
Expand Down Expand Up @@ -230,6 +232,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Platform.Lin
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Platform.Windows.Tests", "tests\Testcontainers.Platform.Windows.Tests\Testcontainers.Platform.Windows.Tests.csproj", "{3E55CBE8-AFE8-426D-9470-49D63CD1051C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Playwright.Tests", "tests\Testcontainers.Playwright.Tests\Testcontainers.Playwright.Tests.csproj", "{DE065875-1B7B-4E20-9332-C88C8437333D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.PostgreSql.Tests", "tests\Testcontainers.PostgreSql.Tests\Testcontainers.PostgreSql.Tests.csproj", "{56D0DCA5-567F-4B3B-8B79-CB108F8EB8A6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.PubSub.Tests", "tests\Testcontainers.PubSub.Tests\Testcontainers.PubSub.Tests.csproj", "{0F86BCE8-62E1-4BFC-AA84-63C7514C90AC}"
Expand Down Expand Up @@ -434,6 +438,10 @@ Global
{B2608563-8EE4-49AA-A9A0-B1614486AEEF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B2608563-8EE4-49AA-A9A0-B1614486AEEF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B2608563-8EE4-49AA-A9A0-B1614486AEEF}.Release|Any CPU.Build.0 = Release|Any CPU
{7F91A202-4F07-470D-881C-9A46A700DCA5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7F91A202-4F07-470D-881C-9A46A700DCA5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7F91A202-4F07-470D-881C-9A46A700DCA5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7F91A202-4F07-470D-881C-9A46A700DCA5}.Release|Any CPU.Build.0 = Release|Any CPU
{8AB91636-9055-4900-A72A-7CFFACDFDBF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8AB91636-9055-4900-A72A-7CFFACDFDBF0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8AB91636-9055-4900-A72A-7CFFACDFDBF0}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -690,6 +698,10 @@ Global
{3E55CBE8-AFE8-426D-9470-49D63CD1051C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3E55CBE8-AFE8-426D-9470-49D63CD1051C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3E55CBE8-AFE8-426D-9470-49D63CD1051C}.Release|Any CPU.Build.0 = Release|Any CPU
{DE065875-1B7B-4E20-9332-C88C8437333D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DE065875-1B7B-4E20-9332-C88C8437333D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DE065875-1B7B-4E20-9332-C88C8437333D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DE065875-1B7B-4E20-9332-C88C8437333D}.Release|Any CPU.Build.0 = Release|Any CPU
{56D0DCA5-567F-4B3B-8B79-CB108F8EB8A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{56D0DCA5-567F-4B3B-8B79-CB108F8EB8A6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{56D0DCA5-567F-4B3B-8B79-CB108F8EB8A6}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -805,6 +817,7 @@ Global
{49051DBC-6B80-4412-8505-BC2764A877BD} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{596EAFC1-0496-495C-B382-D57415FA456A} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{B2608563-8EE4-49AA-A9A0-B1614486AEEF} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{7F91A202-4F07-470D-881C-9A46A700DCA5} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{8AB91636-9055-4900-A72A-7CFFACDFDBF0} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{E6642255-667D-476B-B584-089AA5E6C0B1} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{27D46863-65B9-4934-B3C8-2383B217A477} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
Expand Down Expand Up @@ -869,6 +882,7 @@ Global
{F03FA970-BE2B-4AE2-96FE-7E1F805CEA20} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{DA1D7ADE-452C-4369-83CC-56289176EACD} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{3E55CBE8-AFE8-426D-9470-49D63CD1051C} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{DE065875-1B7B-4E20-9332-C88C8437333D} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{56D0DCA5-567F-4B3B-8B79-CB108F8EB8A6} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{0F86BCE8-62E1-4BFC-AA84-63C7514C90AC} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{D05FCB31-793E-43E0-BD6C-077013AE9113} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
Expand Down
1 change: 1 addition & 0 deletions docs/modules/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ await moduleNameContainer.StartAsync();
| OpenSearch | `opensearchproject/opensearch:2.12.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.OpenSearch) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.OpenSearch) |
| Oracle | `gvenzl/oracle-xe:21.3.0-slim-faststart` | [NuGet](https://www.nuget.org/packages/Testcontainers.Oracle) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Oracle) |
| Papercut | `changemakerstudiosus/papercut-smtp:latest` | [NuGet](https://www.nuget.org/packages/Testcontainers.Papercut) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Papercut) |
| Playwright | `jacoblincool/playwright:chrome-server-1.55.1` | [NuGet](https://www.nuget.org/packages/Testcontainers.Playwright) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Playwright) |
| PostgreSQL | `postgres:15.1` | [NuGet](https://www.nuget.org/packages/Testcontainers.PostgreSql) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.PostgreSql) |
| PubSub | `gcr.io/google.com/cloudsdktool/google-cloud-cli:446.0.1-emulators` | [NuGet](https://www.nuget.org/packages/Testcontainers.PubSub) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.PubSub) |
| Pulsar | `apachepulsar/pulsar:3.0.6` | [NuGet](https://www.nuget.org/packages/Testcontainers.Pulsar) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Pulsar) |
Expand Down
72 changes: 72 additions & 0 deletions docs/modules/playwright.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Playwright

[Playwright](https://playwright.dev/) is a framework for web testing and automation. It allows testing across all modern rendering engines including Chromium, WebKit, and Firefox with a single API. This module provides pre-configured browser containers for automated testing.

Add the following dependency to your project file:

```shell title="NuGet"
dotnet add package Testcontainers.Playwright
```

You can start a Playwright container instance from any .NET application. To create and start a container instance with the default configuration (Chrome browser), use the module-specific builder as shown below:

=== "Start a Playwright container"
```csharp
var playwrightContainer = new PlaywrightBuilder().Build();
await playwrightContainer.StartAsync();
```

This example uses xUnit.net's `IAsyncLifetime` interface to manage the lifecycle of the container. The container is started in the `InitializeAsync` method before the test method runs, ensuring that the environment is ready for testing. After the test completes, the container is removed in the `DisposeAsync` method.

This example demonstrates the Playwright container accessing a web site running inside another container (using the [`testcontainers/helloworld`](https://github.com/testcontainers/helloworld) image). Both containers are assigned to a shared network (see the [Network configuration](#network-configuration) section) to enable communication between them.

=== "Usage Example"
```csharp
--8<-- "tests/Testcontainers.Playwright.Tests/PlaywrightContainerTest.cs:UsePlaywrightContainer"
```

The test example uses the following NuGet dependencies:

=== "Package References"
```xml
--8<-- "tests/Testcontainers.Playwright.Tests/Testcontainers.Playwright.Tests.csproj:PackageReferences"
```

To execute the tests, use the command `dotnet test` from a terminal.

--8<-- "docs/modules/_call_out_test_projects.txt"

## Browser selection

By default, the Playwright module uses Chrome as the browser. You can configure different browsers using the `WithBrowser` method:

=== "Chromium"
```csharp
var playwrightContainer = new PlaywrightBuilder()
.WithBrowser(PlaywrightBrowser.Chromium)
.Build();
```

=== "Firefox"
```csharp
var playwrightContainer = new PlaywrightBuilder()
.WithBrowser(PlaywrightBrowser.Firefox)
.Build();
```

=== "Edge"
```csharp
var playwrightContainer = new PlaywrightBuilder()
.WithBrowser(PlaywrightBrowser.Edge)
.Build();
```

## Network configuration

The Playwright container is configured with a network that can be shared with other containers. This is useful when testing applications that need to communicate with other services. Use the `GetNetwork()` method to access the container's network:

```csharp
var helloWorldContainer = new ContainerBuilder()
.WithNetwork(playwrightContainer.GetNetwork())
.Build();
```
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ nav:
- modules/mssql.md
- modules/neo4j.md
- modules/opensearch.md
- modules/playwright.md
- modules/postgres.md
- modules/qdrant.md
- modules/rabbitmq.md
Expand Down
1 change: 1 addition & 0 deletions src/Testcontainers.Playwright/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
root = true
56 changes: 56 additions & 0 deletions src/Testcontainers.Playwright/PlaywrightBrowser.cs
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; }
}
81 changes: 81 additions & 0 deletions src/Testcontainers.Playwright/PlaywrightBuilder.cs
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));
}
}
53 changes: 53 additions & 0 deletions src/Testcontainers.Playwright/PlaywrightConfiguration.cs
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)
{
}
}
36 changes: 36 additions & 0 deletions src/Testcontainers.Playwright/PlaywrightContainer.cs
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();
}
}
Loading