-
Notifications
You must be signed in to change notification settings - Fork 1
/
PlaywrightTests.cs
115 lines (83 loc) · 3.43 KB
/
PlaywrightTests.cs
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
107
108
109
110
111
112
113
114
115
//using PlaywrightSharp;
//using System;
//using System.Threading.Tasks;
//using Xunit;
//namespace PlaywrightDemo
//{
// public class PlaywrightTests: IDisposable
// {
// //[Fact]
// //public async Task FirstTest()
// //{
// // await Playwright.InstallAsync();
// // using var playwright = await Playwright.CreateAsync();
// // await using var browser = await playwright.Chromium.LaunchAsync(headless: false);
// // var page = await browser.NewPageAsync();
// // await page.GoToAsync("http://www.stackoverflow.com");
// //}
// public IBrowser Browser;
// public PlaywrightTests()
// {
// if (Browser == null)
// {
// Browser = Task.Run(() => GetBrowserAsync()).Result;
// }
// }
// private async Task<IBrowser> GetBrowserAsync()
// {
// await Playwright.InstallAsync();
// var playwright = await Playwright.CreateAsync();
// return await playwright.Chromium.LaunchAsync(headless: false);
// }
// public IPage page;
// public void Dispose()
// {
// page?.CloseAsync();
// }
// //css selectors - https://playwright.dev/#version=v1.5.1&path=docs%2Fselectors.md&q=
// [Fact]
// public async Task ValidateDevelopersTitle()
// {
// var context = await Browser.NewContextAsync();
// page = await context.NewPageAsync();
// await page.GoToAsync("http://www.stackoverflow.com");
// var developersLinkText = (await page.GetTextContentAsync("a[href=\"#for-developers\"]")).Trim();
// Assert.Equal("For developers", developersLinkText);
// }
// //input options - https://playwright.dev/#version=v1.5.1&path=docs%2Finput.md&q=text-input
// [Fact]
// public async Task SearchCSharp()
// {
// var context = await Browser.NewContextAsync();
// page = await context.NewPageAsync();
// await page.GoToAsync("http://www.stackoverflow.com");
// var searchBar = "input[name=\"q\"]";
// await page.TypeAsync(searchBar, "c#");
// await page.ClickAsync(searchBar);
// await page.PressAsync(searchBar, "Enter");
// var headLineText = (await page.GetTextContentAsync(".fs-headline1")).Trim();
// Assert.Equal("Questions tagged [c#]", headLineText);
// }
// //notice no waits
// //default timeout is 30 seconds but you can configure it
// //ABORT REQUESTS
// //https://playwright.dev/#version=v1.5.1&path=docs%2Fnetwork.md&q=
// //stop image downloads during tests
// [Fact]
// public async Task StopImageDownloads()
// {
// var context = await Browser.NewContextAsync();
// page = await context.NewPageAsync();
// // Abort based on the request type
// await page.RouteAsync("**", (route, _) =>
// {
// if (route.Request.ResourceType == ResourceType.Image) {
// route.AbortAsync();
// }
// route.ContinueAsync();
// });
// await page.GoToAsync("http://www.stackoverflow.com");
// var headLineText = (await page.GetTextContentAsync(".fs-headline1")).Trim();
// }
// }
//}