Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions NBomber.WebBrowser.sln
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.36930.0 d17.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NBomber.WebBrowser", "src\NBomber.WebBrowser\NBomber.WebBrowser.csproj", "{73B37EAF-90E5-465F-97DB-874FD956A82C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Demo", "examples\Demo\Demo.csproj", "{A652A3E0-6518-495A-825C-32C3718C8647}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "examples", "examples", "{EE2BE11B-2872-4E3A-8B7F-FEED1174D5EE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HttpSimulator", "examples\HttpSimulator\HttpSimulator.csproj", "{B3DCE2C8-0011-42DB-8DD0-B5FA9E4A3034}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -20,8 +25,19 @@ Global
{A652A3E0-6518-495A-825C-32C3718C8647}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A652A3E0-6518-495A-825C-32C3718C8647}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A652A3E0-6518-495A-825C-32C3718C8647}.Release|Any CPU.Build.0 = Release|Any CPU
{B3DCE2C8-0011-42DB-8DD0-B5FA9E4A3034}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B3DCE2C8-0011-42DB-8DD0-B5FA9E4A3034}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B3DCE2C8-0011-42DB-8DD0-B5FA9E4A3034}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B3DCE2C8-0011-42DB-8DD0-B5FA9E4A3034}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{A652A3E0-6518-495A-825C-32C3718C8647} = {EE2BE11B-2872-4E3A-8B7F-FEED1174D5EE}
{B3DCE2C8-0011-42DB-8DD0-B5FA9E4A3034} = {EE2BE11B-2872-4E3A-8B7F-FEED1174D5EE}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {56B32A8A-8F09-4654-9750-60CE054B88D3}
EndGlobalSection
EndGlobal
68 changes: 26 additions & 42 deletions examples/Demo/Playwright/PlaywrightExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,62 +4,46 @@

namespace Demo.Playwright;

using Microsoft.Playwright;

public class PlaywrightExample
{
public static async Task Run()
{
// 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
}
);

await using var playwrightBrowserPool = new PlaywrightBrowserPool();

// Set the target number of concurrent virtual users
var targetVirtualUsers = 3;

var scenario = Scenario.Create("playwright_scenario", async context =>
{
var page = await browser.NewPageAsync();

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

var html = await page.ContentAsync();
var totalSize = await page.GetDataTransferSize();

return Response.Ok(sizeBytes: totalSize);
});
// Get a browser context from the pool
// This ensures each virtual user has its own isolated context
var browserContext = playwrightBrowserPool.GetBrowserContext(context.ScenarioInfo.InstanceNumber);
var page = await browserContext.NewPageAsync();

await Step.Run("open bing", context, async () =>
try
{
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 Step.Run("open local website", context, async () =>
{
await page.GotoAsync("http://localhost:5280");
return Response.Ok();
});

await page.CloseAsync();

return Response.Ok();
return Response.Ok();
}
finally
{
// Ensure page is closed even if there's an exception
// The browser context remains alive and will be reused
await page.CloseAsync();
}
})
.WithWarmUpDuration(TimeSpan.FromSeconds(3))
.WithInit(async context => await playwrightBrowserPool.Initialize(targetVirtualUsers, browserPath))
.WithWarmUpDuration(TimeSpan.FromSeconds(5))
.WithLoadSimulations(
Simulation.KeepConstant(1, TimeSpan.FromSeconds(30))
Simulation.KeepConstant(targetVirtualUsers, TimeSpan.FromSeconds(30))
);

NBomberRunner
Expand Down
19 changes: 19 additions & 0 deletions examples/HttpSimulator/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Microsoft.AspNetCore.Mvc;

namespace HttpSimulator.Controllers
{
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;

public HomeController(ILogger<HomeController> logger)
{
_logger = logger;
}

public IActionResult Index()
{
return View();
}
}
}
9 changes: 9 additions & 0 deletions examples/HttpSimulator/HttpSimulator.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

</Project>
31 changes: 31 additions & 0 deletions examples/HttpSimulator/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddControllersWithViews();

builder.WebHost.ConfigureKestrel(options =>
{
options.Limits.MaxConcurrentConnections = 1000;
options.Limits.MaxConcurrentUpgradedConnections = 1000;
});

var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
}
app.UseRouting();

app.UseAuthorization();

app.MapStaticAssets();

app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}")
.WithStaticAssets();


app.Run();
14 changes: 14 additions & 0 deletions examples/HttpSimulator/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@{
Layout = null;
}

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Hello World</title>
</head>
<body>
<h1>Hello World</h1>
</body>
</html>
8 changes: 8 additions & 0 deletions examples/HttpSimulator/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
9 changes: 9 additions & 0 deletions examples/HttpSimulator/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
Binary file added examples/HttpSimulator/wwwroot/favicon.ico
Binary file not shown.
3 changes: 2 additions & 1 deletion src/NBomber.WebBrowser/NBomber.WebBrowser.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Playwright" Version="1.58.0" />
<PackageReference Include="Microsoft.Playwright" Version="1.58.0" />
<PackageReference Include="NBomber" Version="6.1.0" />
<PackageReference Include="NBomber.Contracts" Version="6.1.0" />
<PackageReference Include="PuppeteerSharp" Version="21.1.1" />
</ItemGroup>
Expand Down
Loading
Loading