Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Issue with Remote Cloud Integration with Nunit #2475

Open
princebaretto99 opened this issue Feb 3, 2023 · 2 comments
Open

[BUG] Issue with Remote Cloud Integration with Nunit #2475

princebaretto99 opened this issue Feb 3, 2023 · 2 comments

Comments

@princebaretto99
Copy link

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.

@sreenikarthik
Copy link

@mxschmitt, any updates on this one?

@karanshah-browserstack
Copy link

@mxschmitt @pavelfeldman @avodovnik Any updates on suggestion on how this could be done? As per our investigation this is the line of code causing the issue https://github.com/microsoft/playwright-dotnet/blob/main/src/Playwright.NUnit/WorkerAwareTest.cs#L78 . If we can add a check for TestOk() and connection.isRemote(). But the connection or channel object is not available here. We would be happy to contribute too, can someone help on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants