Skip to content

Commit

Permalink
WebBrowser Testing #649
Browse files Browse the repository at this point in the history
  • Loading branch information
AntyaDev committed Jun 21, 2024
1 parent 5bcc3b2 commit 459c887
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/Demo/Demo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
<PackageReference Include="NBomber.Http" Version="5.1.0" />
<PackageReference Include="NBomber.MQTT" Version="0.1.0" />
<PackageReference Include="NBomber.Sinks.Timescale" Version="0.1.0" />
<PackageReference Include="NBomber.WebBrowser" Version="0.1.0-beta.0" />
<PackageReference Include="NBomber.WebSockets" Version="0.1.0" />
<PackageReference Include="NBomber.Sinks.InfluxDB" Version="5.0.2" />

Expand Down
8 changes: 8 additions & 0 deletions examples/Demo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
using Demo.HTTP.WebAppSimulator;
using Demo.HTTP.SimpleBookstore;
using Demo.MQTT.ClientPool;
using Demo.WebBrowsers.Playwright;
using Demo.WebBrowsers.Puppeteer;
using Demo.WebSockets;

// -------------------------------
Expand Down Expand Up @@ -125,3 +127,9 @@
// new ManualClusterExample().Run(args: new [] { "--cluster-node-type=coordinator" });
// new ManualClusterExample().Run(args: new [] { "--cluster-node-type=agent", "--cluster-agent-group=1" });

// --------------------------
// ----- Web Browsers -------
// --------------------------
// await new PuppeteerExample().Run();
// await new PlaywrightExample().Run();

38 changes: 38 additions & 0 deletions examples/Demo/WebBrowsers/Playwright/PlaywrightExample.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
namespace Demo.WebBrowsers.Playwright;

using Microsoft.Playwright;
using NBomber.CSharp;
using NBomber.WebBrowser.Playwright;

public class PlaywrightExample
{
public async Task Run()
{
var browserPath = "C:/Program Files/Google/Chrome/Application/chrome.exe";

using var playwright = await Playwright.CreateAsync();

await using var browser = await playwright.Chromium.LaunchAsync(
new BrowserTypeLaunchOptions { Headless = true, ExecutablePath = browserPath }
);

var scenario = Scenario.Create("playwright_scenario", async context =>
{
var page = await browser.NewPageAsync();
var pageResponse = await page.GotoAsync("https://translate.google.com/");

var response = await pageResponse.ToNBomberResponse();
page.CloseAsync();

Check warning on line 25 in examples/Demo/WebBrowsers/Playwright/PlaywrightExample.cs

View workflow job for this annotation

GitHub Actions / build

Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.

return response;
})
.WithoutWarmUp()
.WithLoadSimulations(
Simulation.KeepConstant(1, TimeSpan.FromMinutes(1))
);

NBomberRunner
.RegisterScenarios(scenario)
.Run();
}
}
36 changes: 36 additions & 0 deletions examples/Demo/WebBrowsers/Puppeteer/PuppeteerExample.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
namespace Demo.WebBrowsers.Puppeteer;

using PuppeteerSharp;
using NBomber.CSharp;
using NBomber.WebBrowser.PuppeteerSharp;

public class PuppeteerExample
{
public async Task Run()
{
var browserPath = "C:/Program Files/Google/Chrome/Application/chrome.exe";

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();
var pageResponse = await page.GoToAsync("https://translate.google.com/");

var response = await pageResponse.ToNBomberResponse();
page.CloseAsync();

Check warning on line 23 in examples/Demo/WebBrowsers/Puppeteer/PuppeteerExample.cs

View workflow job for this annotation

GitHub Actions / build

Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.

return response;
})
.WithoutWarmUp()
.WithLoadSimulations(
Simulation.KeepConstant(1, TimeSpan.FromSeconds(60))
);

NBomberRunner
.RegisterScenarios(scenario)
.Run();
}
}

0 comments on commit 459c887

Please sign in to comment.