forked from OleksiiKhorunzhak/hilel-aqa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup-playwright.ps1
106 lines (86 loc) · 2.77 KB
/
setup-playwright.ps1
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
param (
[Parameter(Mandatory=$true)]
[string]$ProjectName
)
if (-not $ProjectName) {
Write-Host "Usage: .\setup-playwright.ps1 -ProjectName <YourProjectName>"
exit
}
Write-Host "Step 1: Create a new NUnit project with the specified name"
dotnet new nunit -n $ProjectName
Write-Host "Step 2: Change directory to the newly created project folder"
cd $ProjectName
Write-Host "Step 3: Add Microsoft.Playwright.NUnit package"
dotnet add package Microsoft.Playwright.NUnit
Write-Host "Step 4: Build the project"
dotnet build
Write-Host "Step 5: Install Playwright"
./bin/Debug/net8.0/playwright.ps1 install
Write-Host "Step 6: Replace content of UnitTest1.cs with the specified text"
$unitTestPath = "UnitTest1.cs"
$fixturePath = "UITestFixture.cs"
$unitTestContent = @"
using System.Text.RegularExpressions;
using Microsoft.Playwright;
namespace $ProjectName
{
[Parallelizable(ParallelScope.Self)]
[TestFixture]
public class ExampleTest : UITestFixture
{
[Test]
public async Task HasTitle()
{
await Page.GotoAsync("https://playwright.dev");
// Expect a title "to contain" a substring.
await Assertions.Expect(Page).ToHaveTitleAsync(new Regex("Playwright"));
}
[Test]
public async Task GetStartedLink()
{
await Page.GotoAsync("https://playwright.dev");
// Click the get started link.
await Page.GetByRole(AriaRole.Link, new() { Name = "Get started" }).ClickAsync();
// Expects page to have a heading with the name of Installation.
await Assertions.Expect(Page.GetByRole(AriaRole.Heading, new() { Name = "Installation" })).ToBeVisibleAsync();
}
}
}
"@
$fixtureContent = @"
using Microsoft.Playwright;
namespace $ProjectName
{
public class UITestFixture
{
public IPage Page { get; private set; }
private IBrowser browser;
[SetUp]
public async Task Setup()
{
var playwrightDriver = await Playwright.CreateAsync();
browser = await playwrightDriver.Chromium.LaunchAsync(new BrowserTypeLaunchOptions
{
Headless = false
});
var context = await browser.NewContextAsync(new BrowserNewContextOptions
{
ViewportSize = new ViewportSize
{
Width = 1920,
Height = 1080
}
});
Page = await context.NewPageAsync();
}
[TearDown]
public async Task Teardown()
{
await Page.CloseAsync();
await browser.CloseAsync();
}
}
}
"@
Set-Content -Path $unitTestPath -Value $unitTestContent
Set-Content -Path $fixturePath -Value $fixtureContent