You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
usingSystem;usingSystem.Threading.Tasks;usingMicrosoft.Playwright;usingMicrosoft.Playwright.TestAdapter;usingMicrosoft.Playwright.Xunit;usingXunit;publicclassIntegrationTests(WebAppFixturewebAppFixture):PageTest,IClassFixture<WebAppFixture>{// 👇 Proposed new virtual method where browser, launch options and more can be controlled programmaticallyprotectedoverridePlaywrightSettingsPlaywrightSettings(){returnnewPlaywrightSettings{Browser=PlaywrightBrowser.Firefox,LaunchOptions=newBrowserTypeLaunchOptions{Headless=false,SlowMo=100,Timeout=20_000,},ExpectTimeout=TimeSpan.FromSeconds(10),};}[Fact]publicasyncTaskTestSearchPage(){awaitPage.GotoAsync(webAppFixture.Url("search"));awaitExpect(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.
The text was updated successfully, but these errors were encountered:
0xced
added a commit
to 0xced/playwright-dotnet
that referenced
this issue
Dec 8, 2024
We intentionally had these settings configured on a global level before - this would require us to diverge from what we do in Node.js or Python. Usually for end-to-end tests, you write a test once and run them on all the browsers. For that you run dotnet test 3 times. I recommend to reach out to Jetbrains to fix the issue with runsettings - in the CLI it seems to work all expected, so its an issue with the IDE. Do you mind elaborating why you want to run some test files only in a specific browser? We recommend having multiple runsettings files if you want to specify custom timeouts etc.
🚀 Feature Request
Currently, setting the
BrowserTypeLaunchOptions
when running tests with theMicrosoft.Playwright.MSTest
,Microsoft.Playwright.NUnit
orMicrosoft.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 theContextOptions()
method.Example
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 theTimeout
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 theMicrosoft.VisualStudio.TestPlatform.ObjectModel.Adapter.ISettingsProvider.Load
method to be called, rendring Playwright.runsettings
unusable with Rider. See alsoTestCaseFilter
in.runsettings
ignored.The text was updated successfully, but these errors were encountered: