Description
🚀 Feature Request
Currently, setting the BrowserTypeLaunchOptions
when running tests with the Microsoft.Playwright.MSTest
, Microsoft.Playwright.NUnit
or Microsoft.Playwright.Xunit
pacakge is controlled through the .runsettings configuration file.
It would be nice to be able to control the launch options programmatically, just like BrowserNewContextOptions
can be controlled programmatically by overriding the ContextOptions()
method.
Example
using System;
using System.Threading.Tasks;
using Microsoft.Playwright;
using Microsoft.Playwright.TestAdapter;
using Microsoft.Playwright.Xunit;
using Xunit;
public class IntegrationTests(WebAppFixture webAppFixture) : PageTest, IClassFixture<WebAppFixture>
{
// 👇 Proposed new virtual method where browser, launch options and more can be controlled programmatically
protected override PlaywrightSettings PlaywrightSettings()
{
return new PlaywrightSettings
{
Browser = PlaywrightBrowser.Firefox,
LaunchOptions = new BrowserTypeLaunchOptions
{
Headless = false,
SlowMo = 100,
Timeout = 20_000,
},
ExpectTimeout = TimeSpan.FromSeconds(10),
};
}
[Fact]
public async Task TestSearchPage()
{
await Page.GotoAsync(webAppFixture.Url("search"));
await Expect(Page).ToHaveTitleAsync("Search");
}
}
This example is given with Xunit but would work the same with MSTest or NUnit.
Motivation
Controlling options programatically opens up new possibilities that are not achievable with a .runsettings
file. For example, one could decide to run tests on Firefox based on some runtime conditions or change the value of the Timeout
based on what hardware the tests are running on. This would give a lot of power to Playwright users.
Also, having a new PlaywrightSettings
type is great for discoverability. Typing properties with autocompletion support from your IDE is a much better experience than writing XML elements in a .runsettings
file without any autocompletion.
Finally, .runsettings
support in Rider is pretty broken, I was not able to get the Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter.ISettingsProvider.Load
method to be called, rendring Playwright .runsettings
unusable with Rider. See also TestCaseFilter
in .runsettings
ignored.