microsoft / microsoft/playwright-dotnet
[Feature]: Load Playwright settings programmatically as an alternative to a `.runsettings` file
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 3k
- Forks
- 305
- Avg merge
- 20h 47m
- Merged PRs (30d)
- 6
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Review the Microsoft.Playwright.MSTest, Microsoft.Playwright.NUnit, and Microsoft.Playwright.Xunit integrations, along with the existing .runsettings configuration and ContextOptions() handling. Compare how browser launch and test settings are currently supplied, then define equivalent programmatic behavior across all three runners and verify that the proposed PlaywrightSettings API covers the requested options.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- developer-experience, testing-qa
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100