-
Notifications
You must be signed in to change notification settings - Fork 140
Expand file tree
/
Copy pathPuppeteerExample.cs
More file actions
66 lines (52 loc) · 2.17 KB
/
PuppeteerExample.cs
File metadata and controls
66 lines (52 loc) · 2.17 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
namespace Demo.WebBrowsers.Puppeteer;
using PuppeteerSharp;
using NBomber.CSharp;
using NBomber.WebBrowser.Puppeteer;
public class PuppeteerExample
{
public async Task Run()
{
// downloading the Chrome
var installedBrowser = await new BrowserFetcher(SupportedBrowser.Chrome).DownloadAsync(BrowserTag.Stable);
var browserPath = installedBrowser.GetExecutablePath();
await using var browser = await Puppeteer.LaunchAsync(
new LaunchOptions
{
Headless = true,
ExecutablePath = browserPath
}
);
var scenario = Scenario.Create("puppeteer_scenario", async context =>
{
await using var page = await browser.NewPageAsync();
await page.SetCacheEnabledAsync(false); // disable caching
await Step.Run("open nbomber", context, async () =>
{
var pageResponse = await page.GoToAsync("https://nbomber.com/");
var html = await page.GetContentAsync();
var totalSize = await page.GetDataTransferSize();
return Response.Ok(sizeBytes: totalSize);
});
await Step.Run("open bing", context, async () =>
{
var pageResponse = await page.GoToAsync("https://www.bing.com/maps");
await page.WaitForSelectorAsync(".searchbox input");
await page.FocusAsync(".searchbox input");
await page.Keyboard.TypeAsync("CN Tower, Toronto, Ontario, Canada");
await page.Keyboard.PressAsync("Enter");
await page.WaitForNavigationAsync(new NavigationOptions { WaitUntil = [WaitUntilNavigation.Load]});
var totalSize = await page.GetDataTransferSize();
return Response.Ok(sizeBytes: totalSize);
});
await page.CloseAsync();
return Response.Ok();
})
.WithWarmUpDuration(TimeSpan.FromSeconds(3))
.WithLoadSimulations(
Simulation.KeepConstant(1, TimeSpan.FromSeconds(30))
);
NBomberRunner
.RegisterScenarios(scenario)
.Run();
}
}