When inheriting PageTest class, IBrowser is already configured using runsettings.
[TestClass]
public class UnitTest1 : PageTest
{
[TestMethod]
public async Task HomepageHasPlaywrightInTitleAndGetStartedLinkLinkingtoTheIntroPage()
{
await Page.GotoAsync("https://playwright.dev");
// Expect a title "to contain" a substring.
await Expect(Page).ToHaveTitleAsync(new Regex("Playwright"));
// create a locator
var getStarted = Page.Locator("text=Get Started");
// Expect an attribute "to be strictly equal" to the value.
await Expect(getStarted).ToHaveAttributeAsync("href", "/docs/intro");
// Click the get started link.
await getStarted.ClickAsync();
// Expects the URL to contain intro.
await Expect(Page).ToHaveURLAsync(new Regex(".*intro"));
}
}
What if I wanted to instantiate IBrowser manually like this and use runsettings to set browser to be firefox?
<RunSettings>
<Playwright>
<BrowserName>chromium</BrowserName>
<LaunchOptions>
<Headless>false</Headless>
<Channel>msedge</Channel>
</LaunchOptions>
</Playwright>
</RunSettings>
var playwright = Playwright.CreateAsync().Result;
_browser = playwright.Chromium.LaunchAsync().Result;
It would explictly use Chromium, instead of whats required by runsettings.
For my use case, I tried to use Playwright-provided IBrowser, but due to some things that I need to do within AssemblyInitialize methods, I'd better have the solution of creating IBrowser manually.
The question is not totally clear, but in case you need the runsettings file to be picked up by Visual Studio when you execute your tests, then here is a possible solution.
From the Visual Studio menu,
Here is a file that uses firefox, set the headed mode.
Configure the runsettings file to be picked up by Visual Studio