microsoft / microsoft/playwright-dotnet
[BUG] Issue with Remote Cloud Integration with Nunit
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 3k
- Forks
- 304
- Avg merge
- 20h 47m
- Merged PRs (30d)
- 6
Description
Context:
- Playwright Version: 1.28
- Operating System: Mac
- .NET version: .NET 7
- Browser: All
Hi Team,
We are trying to inject the remote browser into playwright-nunit framework. While doing so we noticed that the Browser never gets closed using Browser.close() which results in "Abrupt Close" at the remote cloud's end. We have rewritten the BrowserService.cs by extending the IWorkerService and used the browserType.ConnectAsync method with BrowserStack's CDP URL to connect to the remote cloud.
Apart from this we also noticed that the browser gets closed only in cases of errors/assertion errors.
Code Snippet
Below is the code snippet for the rewritten BrowserService.cs
using System.Threading.Tasks;
using Microsoft.Playwright;
using Microsoft.Playwright.NUnit;
using Microsoft.Playwright.TestAdapter;
using Newtonsoft.Json;
internal class BrowserStackService : IWorkerService
{
public IBrowser Browser { get; internal set; } = null!;
public static Task<BrowserStackService> Register(WorkerAwareTest test, IBrowserType browserType)
{
Dictionary<string, string> browserstackOptions = new Dictionary<string, string>();
browserstackOptions.Add("os", "osx");
browserstackOptions.Add("os_version", "catalina");
browserstackOptions.Add("browser", "chrome");
browserstackOptions.Add("browserstack.username", "BROWSERSTACK_USERNAME");
browserstackOptions.Add("browserstack.accessKey", "BROWSERSTACK_ACCESS_KEY");
string capsJson = JsonConvert.SerializeObject(browserstackOptions);
string cdpUrl = "wss://cdp.browserstack.com/playwright?caps=" + Uri.EscapeDataString(capsJson);
return test.RegisterService("Browser", async () => new BrowserStackService
{
Browser = await browserType.ConnectAsync(cdpUrl).ConfigureAwait(false)
}) ;
}
public Task ResetAsync() => Task.CompletedTask;
public Task DisposeAsync() => Browser.CloseAsync();
}
Please let me know your thoughts on this.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the BrowserStackService.cs example and the Playwright NUnit lifecycle around WorkerAwareTest, IWorkerService, RegisterService, ConnectAsync, and DisposeAsync. Reproduce the remote connection and trace normal test completion versus assertion failure; done means the connected browser is closed cleanly in the normal lifecycle without an abrupt remote close.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100