diff --git a/examples/Demo/Demo.csproj b/examples/Demo/Demo.csproj index dfe3a0a5..30ff2f6b 100644 --- a/examples/Demo/Demo.csproj +++ b/examples/Demo/Demo.csproj @@ -64,7 +64,7 @@ - + diff --git a/examples/Demo/WebBrowsers/Playwright/PlaywrightExample.cs b/examples/Demo/WebBrowsers/Playwright/PlaywrightExample.cs index 7df97a62..38273ba0 100644 --- a/examples/Demo/WebBrowsers/Playwright/PlaywrightExample.cs +++ b/examples/Demo/WebBrowsers/Playwright/PlaywrightExample.cs @@ -1,5 +1,6 @@ namespace Demo.WebBrowsers.Playwright; +using PuppeteerSharp; using Microsoft.Playwright; using NBomber.CSharp; using NBomber.WebBrowser.Playwright; @@ -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 diff --git a/examples/Demo/WebBrowsers/Puppeteer/PuppeteerExample.cs b/examples/Demo/WebBrowsers/Puppeteer/PuppeteerExample.cs index 74eb7283..4cd602f2 100644 --- a/examples/Demo/WebBrowsers/Puppeteer/PuppeteerExample.cs +++ b/examples/Demo/WebBrowsers/Puppeteer/PuppeteerExample.cs @@ -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