karan kural
karan kural

Reputation: 35

Rider is not opening browser on running playwright unit tests

I am trying to run my tests in Playwright cucumber tests and my tests are running fine in headless mode but it's not launching the browser with this .runSettings configuration

browser.runsettings

`<LaunchOptions>
    <Headless>false</Headless>
    <Channel>chrome</Channel>
 </LaunchOptions>`

However, I am able to launch the browser in VScode by running playwright cucumber tests. Any idea?

I've configured a custom runSettings file with LaunchOptions in unit test runner settings in the rider. Chrome is enabled in Web browsers and Preview.

Upvotes: 1

Views: 679

Answers (2)

Jamey
Jamey

Reputation: 843

I couldn't get the environment variable solution to work for some reason, so I went for this slightly hacky solution which takes advantage of the public Load function within PlaywrightSettingsProvider:

    public override Task InitializeAsync()
    {
        using var stringReader = new System.IO.StringReader(@"
<Playwright>
    <BrowserName>chromium</BrowserName>
    <LaunchOptions>
        <Headless>false</Headless>
    </LaunchOptions>
    <ExpectTimeout>5000</ExpectTimeout>
    <Retries>3</Retries>
</Playwright>");
        using var xmlReader = XmlReader.Create(stringReader);
        new PlaywrightSettingsProvider().Load(xmlReader);

        return base.InitializeAsync();
    }

This can be placed in a test/base class, and gives me access to BrowserTypeLaunchOptions which I can use to configure most of the bits I need programatically - including headed mode for local debugging.

Upvotes: 0

Matthias McRobbin
Matthias McRobbin

Reputation: 21

I found a work-around that worked for me:

  1. Open Settings dialog (Ctrl+Alt+S on Windows, Cmd+, on Mac)
  2. Go to Build, Execution, Deployment > Unit Testing > Test Runner
  3. Add a new Environment Variable named HEADED with value 1

https://youtrack.jetbrains.com/issue/RSRP-496572/Test-runner-does-not-pick-up-playwright-LaunchOptions-value-from-.runsettings-file

Upvotes: 2

Related Questions