-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPlaywrightTestBuilderLocalTest.cs
More file actions
84 lines (74 loc) · 3.27 KB
/
PlaywrightTestBuilderLocalTest.cs
File metadata and controls
84 lines (74 loc) · 3.27 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
74
75
76
77
78
79
80
81
82
83
84
// ----------------------------------------------------------------------
// <copyright file="PlaywrightTestBuilderLocalTest.cs" company="Xavier Solau">
// Copyright © 2021-2026 Xavier Solau.
// Licensed under the MIT license.
// See LICENSE file in the project root for full license information.
// </copyright>
// ----------------------------------------------------------------------
using Shouldly;
namespace SoloX.CodeQuality.Playwright.E2ETest
{
public class PlaywrightTestBuilderLocalTest
{
private readonly IPlaywrightTestBuilder builder;
public PlaywrightTestBuilderLocalTest()
{
var path = Path.GetFullPath(Path.GetDirectoryName(this.GetType().Assembly.Location)!);
this.builder = PlaywrightTestBuilder.Create()
.WithLocalHost(localHostBuilder =>
{
localHostBuilder
.UsePortRange(new PortRange(5000, 6000))
.UseWebHostWithWwwRoot(path, "home.html")
.UseWebHostBuilder(builder =>
{
//builder.ConfigureServices(services =>
//{
// services.AddTransient<IService, ServiceMock>();
//})
//.ConfigureAppConfiguration((app, conf) =>
//{
// conf.AddJsonFile("appsettings.Test.json");
//})
//.UseSetting("SomeKey", "SomeValue");
});
})
.WithPlaywrightOptions(opt =>
{
//opt.Headless = false;
//opt.SlowMo = 5000;
//opt.Timeout = 60000;
})
.WithPlaywrightNewContextOptions(opt =>
{
//opt.ViewportSize = new Microsoft.Playwright.ViewportSize() { Height = 800, Width = 1000 };
//opt.StorageStatePath = "State Json file";
});
}
[Theory]
[InlineData(Browser.Chromium, null)]
[InlineData(Browser.Chromium, Devices.Pixel)]
[InlineData(Browser.Chromium, Devices.PixelLandscape)]
[InlineData(Browser.Firefox, null)]
[InlineData(Browser.Webkit, null)]
[InlineData(Browser.Webkit, Devices.iPhone)]
[InlineData(Browser.Webkit, Devices.iPhoneLandscape)]
public async Task ItShouldOpenTheHomePageFromStaticHomeFile(Browser browser, string? deviceName)
{
var playwrightTest = await this.builder
.BuildAsync(browser, deviceName: deviceName)
.ConfigureAwait(true);
await using var _ = playwrightTest.ConfigureAwait(false);
await playwrightTest
.GotoPageAsync(
"home.html",
async (page) =>
{
var body = page.Locator("body");
await body.WaitForAsync().ConfigureAwait(true);
var title = await page.TitleAsync().ConfigureAwait(true);
title.ShouldBe("Home Title");
}).ConfigureAwait(true);
}
}
}