Change runsettings file for Cross Browser Testing in Playwright Dotnet

Is there any way for us to just change the runsettings file for Cross Browser Testing in Playwright with dotnet (any Test Runner)? I want each test to run in multiple browsers, so that each test is independent of the other and also I accomplish CBT

CBT should work as expected

Upvotes: 1

Views: 127

Answers (1)

Gaurav Khurana
Gaurav Khurana

Reputation: 3936

There are various ways to achieve this

  1. You can do this via command line by passing a different runsettings file every time

      dotnet test --settings:chromium.runsettings
      dotnet test --settings:firefox.runsettings
      dotnet test --settings:webkit.runsettings
    
  2. You can pass like this too if you want to maintain a single runsettings file

    dotnet test -- Playwright.BrowserName=webkit
    
  3. You can place a variable in runsettings file, which you can pass from pipeline which would be changed dynamically at runtime

     <browser>#{BROWSER}#</browser>
    
  4. You can also control stuff if you are initializing your Context on your own in below line by reading the value of browser from pipeline

     If(browser == Chrome) 
     {
        await using var browser = await playwright.Chromium.LaunchAsync();
     }
     else  if (other browser)
    

Also to save resources you can do 1 thing based on time of the day or a particular day, run your test in a particular browser.

if its Monday then chrome if Tuesday then edge instead of running all browsers all the time

Upvotes: 0

Related Questions