Skip to content

Commit

Permalink
Updated WebBrowser Testing
Browse files Browse the repository at this point in the history
  • Loading branch information
AntyaDev committed Jul 4, 2024
1 parent 7f6d965 commit 0b2632f
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 18 deletions.
2 changes: 1 addition & 1 deletion examples/Demo/Demo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +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.5.0" />
<PackageReference Include="NBomber.WebBrowser" Version="0.1.0-beta.0" />
<PackageReference Include="NBomber.WebBrowser" Version="0.1.0" />
<PackageReference Include="NBomber.WebSockets" Version="0.1.0" />
<PackageReference Include="NBomber.Sinks.InfluxDB" Version="5.0.2" />

Expand Down
46 changes: 38 additions & 8 deletions examples/Demo/WebBrowsers/Playwright/PlaywrightExample.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace Demo.WebBrowsers.Playwright;

using PuppeteerSharp;
using Microsoft.Playwright;
using NBomber.CSharp;
using NBomber.WebBrowser.Playwright;
Expand All @@ -8,27 +9,56 @@ public class PlaywrightExample
{
public async Task Run()
{
var browserPath = "C:/Program Files/Google/Chrome/Application/chrome.exe";
// downloading the Chrome
var installedBrowser = await new BrowserFetcher(SupportedBrowser.Chrome).DownloadAsync(BrowserTag.Stable);
var browserPath = installedBrowser.GetExecutablePath();

using var playwright = await Playwright.CreateAsync();

await using var browser = await playwright.Chromium.LaunchAsync(
new BrowserTypeLaunchOptions { Headless = true, ExecutablePath = browserPath }
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();
await Step.Run("open nbomber", context, async () =>
{
var pageResponse = await page.GotoAsync("https://nbomber.com/");

return response;
var html = await page.ContentAsync();
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.WaitForLoadStateAsync(LoadState.Load);

var totalSize = await page.GetDataTransferSize();
return Response.Ok(sizeBytes: totalSize);
});

await page.CloseAsync();

return Response.Ok();
})
.WithoutWarmUp()
.WithWarmUpDuration(TimeSpan.FromSeconds(3))
.WithLoadSimulations(
Simulation.KeepConstant(1, TimeSpan.FromMinutes(1))
Simulation.KeepConstant(1, TimeSpan.FromSeconds(30))
);

NBomberRunner
Expand Down
48 changes: 39 additions & 9 deletions examples/Demo/WebBrowsers/Puppeteer/PuppeteerExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,61 @@

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

public class PuppeteerExample
{
public async Task Run()
{
var browserPath = "C:/Program Files/Google/Chrome/Application/chrome.exe";
// 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 }
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/");
await page.SetCacheEnabledAsync(false); // disable caching

var response = await pageResponse.ToNBomberResponse();
page.CloseAsync();
await Step.Run("open nbomber", context, async () =>
{
var pageResponse = await page.GoToAsync("https://nbomber.com/");

return response;
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();
})
.WithoutWarmUp()
.WithWarmUpDuration(TimeSpan.FromSeconds(3))
.WithLoadSimulations(
Simulation.KeepConstant(1, TimeSpan.FromSeconds(60))
Simulation.KeepConstant(1, TimeSpan.FromSeconds(30))
);

NBomberRunner
Expand Down

0 comments on commit 0b2632f

Please sign in to comment.