microsoft / playwright-dotnet

.NET version of the Playwright testing and automation library.
https://playwright.dev/dotnet/
MIT License
2.47k stars 235 forks source link

Running multiple tests at the same time C# #1907

Closed BrandonQA closed 2 years ago

BrandonQA commented 2 years ago

Hi guys, currently looking for the best way to run multiple tests at the same time using Playwright. I'm not sure if this is possible from the artical i was reading on https://playwright.dev/dotnet/docs/test-runners.

Thank you for your help and information in advance, brandon

mxschmitt commented 2 years ago

We recommend nunit as a test-runner for C#, since it provides the best integration with Playwright, gives you an isolated page out of the box and works well with parallelism: https://playwright.dev/dotnet/docs/test-runners#running-nunit-tests-in-parallel

isn't Testcafe only for JS/TS? (If you are using JS/TS, see here.)

For other third-party test-runners we can't provide any support.

BrandonQA commented 2 years ago

We recommend nunit as a test-runner for C#, since it provides the best integration with Playwright, gives you an isolated page out of the box and works well with parallelism: https://playwright.dev/dotnet/docs/test-runners#running-nunit-tests-in-parallel

isn't Testcafe only for JS/TS? (If you are using JS/TS, see here.)

For other third-party test-runners we can't provide any support.

Hi Sorry miss type on old application i'm using playwright

mxschmitt commented 2 years ago

Do you mean you are using Playwright with Node.js or C#?

BrandonQA commented 2 years ago

Using Playwright with C# when using -- NUnit.NumberOfTestWorkers=10 my tests still seem to run individually not at the same time

BrandonQA commented 2 years ago

Using -- NUnit.NumberOfTestWorkers=10 My test still seem to run individually not at the same time.

StevenDenman commented 2 years ago

Are you using SpecFlow?

BrandonQA commented 2 years ago

Are you using SpecFlow?

No

StevenDenman commented 2 years ago

This worked fine for me, although I noticed that if you were following the instructions here then it doesn't state to setup your runsettings file, nor to set the Scope accordingly (note I have set it to All as his will make the methods run in parallel)

using Microsoft.Playwright;
using NUnit.Framework;
using System.Threading.Tasks;

namespace PlaywrightParallel
{
    [TestFixture]
    [Parallelizable(ParallelScope.All)]
    public class Tests
    {
        private static IBrowserContext Context;

        [SetUp]
        public async Task Setup()
        {
            var pw = await Playwright.CreateAsync();

            var chromium = await pw.Chromium.LaunchAsync(new BrowserTypeLaunchOptions
            {
                Headless = false
            });

            Context = await chromium.NewContextAsync();
        }

        [Test]
        public async Task Test1()
        {
            var page = await Context.NewPageAsync();
            await page.GotoAsync("https://playwright.dev/dotnet/docs");
            await Task.Delay(5000);
        }

        [Test]
        public async Task Test2()
        {
            var page = await Context.NewPageAsync();
            await page.GotoAsync("https://playwright.dev/dotnet/docs");
            await Task.Delay(5000);
        }

        [Test]
        public async Task Test3()
        {
            var page = await Context.NewPageAsync();
            await page.GotoAsync("https://playwright.dev/dotnet/docs");
            await Task.Delay(5000);
        }

        [Test]
        public async Task Test4()
        {
            var page = await Context.NewPageAsync();
            await page.GotoAsync("https://playwright.dev/dotnet/docs");
            await Task.Delay(5000);
        }

        [Test]
        public async Task Test5()
        {
            var page = await Context.NewPageAsync();
            await page.GotoAsync("https://playwright.dev/dotnet/docs");
            await Task.Delay(5000);
        }
    }
}
mxschmitt commented 2 years ago

Closing since it works with nunit and multiple test-runners / setups are mixed here. For a guide for nunit, please refer to the docs here and use the latest version.