forked from testcontainers/testcontainers-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlaywrightBuilder.cs
More file actions
73 lines (62 loc) · 2.83 KB
/
Copy pathPlaywrightBuilder.cs
File metadata and controls
73 lines (62 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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 string PlaywrightImage = "mcr.microsoft.com/playwright:v1.55.1";
public const ushort PlaywrightPort = 8080;
/// <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; }
/// <inheritdoc />
public override PlaywrightContainer Build()
{
Validate();
return new PlaywrightContainer(DockerResourceConfiguration);
}
/// <inheritdoc />
protected override PlaywrightBuilder Init()
{
return base.Init()
.WithImage(PlaywrightImage)
.WithNetwork(new NetworkBuilder().Build())
.WithNetworkAliases(PlaywrightNetworkAlias)
.WithPortBinding(PlaywrightPort, true)
.WithEntrypoint("/bin/sh", "-c")
// Extract the Playwright version from the container at startup.
.WithCommand("npx -y playwright@$(sed --quiet 's/.*\\\"driverVersion\\\": *\"\\([^\"]*\\)\".*/\\1/p' ms-playwright/.docker-info) run-server --port " + PlaywrightPort)
.WithWaitStrategy(Wait.ForUnixContainer().UntilMessageIsLogged("Listening on ws://localhost:8080/"));
}
/// <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));
}
}