From 974ccc887c0ce5a75eb2810fd32da1b1a7383923 Mon Sep 17 00:00:00 2001 From: Siddharth Singha Roy Date: Mon, 11 Nov 2024 03:14:22 +0530 Subject: [PATCH] fix(playwrighttesting): no auth error when scalable scenario is disabled --- .../src/PlaywrightServiceNUnit.cs | 6 +++++- .../src/PlaywrightService.cs | 1 + .../tests/PlaywrightServiceTests.cs | 4 ++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.NUnit/src/PlaywrightServiceNUnit.cs b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.NUnit/src/PlaywrightServiceNUnit.cs index c943468e3cdff..4212181a92458 100644 --- a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.NUnit/src/PlaywrightServiceNUnit.cs +++ b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.NUnit/src/PlaywrightServiceNUnit.cs @@ -5,7 +5,7 @@ using NUnit.Framework; using System.Threading.Tasks; using System.Runtime.InteropServices; -using System.Threading; +using System; using Azure.Developer.MicrosoftPlaywrightTesting.TestLogger; namespace Azure.Developer.MicrosoftPlaywrightTesting.NUnit; @@ -45,6 +45,10 @@ public PlaywrightServiceNUnit(TokenCredential? credential = null) [OneTimeSetUp] public async Task SetupAsync() { + if (!UseCloudHostedBrowsers) + return; + TestContext.Progress.WriteLine("\nRunning tests using Microsoft Playwright Testing service.\n"); + await InitializeAsync().ConfigureAwait(false); } diff --git a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/PlaywrightService.cs b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/PlaywrightService.cs index fe71869b3cb83..1a50d42912ec0 100644 --- a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/PlaywrightService.cs +++ b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/PlaywrightService.cs @@ -145,6 +145,7 @@ public async Task InitializeAsync(CancellationToken cancellationToken = default) // Since playwright-dotnet checks PLAYWRIGHT_SERVICE_ACCESS_TOKEN and PLAYWRIGHT_SERVICE_URL to be set, remove PLAYWRIGHT_SERVICE_URL so that tests are run locally. // If customers use GetConnectOptionsAsync, after setting disableScalableExecution, an error will be thrown. Environment.SetEnvironmentVariable(ServiceEnvironmentVariable.PlaywrightServiceUri, null); + return; } // If default auth mechanism is Access token and token is available in the environment variable, no need to setup rotation handler if (ServiceAuth == ServiceAuthType.AccessToken) diff --git a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/tests/PlaywrightServiceTests.cs b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/tests/PlaywrightServiceTests.cs index 2f35beeeca466..e226edb132bae 100644 --- a/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/tests/PlaywrightServiceTests.cs +++ b/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/tests/PlaywrightServiceTests.cs @@ -185,9 +185,9 @@ public void Initialize_WhenDefaultAuthIsEntraIdAccessTokenAndAccessTokenEnvironm Assert.That(Environment.GetEnvironmentVariable(ServiceEnvironmentVariable.PlaywrightServiceUri), Is.Not.Null); service.InitializeAsync().Wait(); - defaultAzureCredentialMock.Verify(x => x.GetTokenAsync(It.IsAny(), It.IsAny()), Times.Once); + defaultAzureCredentialMock.Verify(x => x.GetTokenAsync(It.IsAny(), It.IsAny()), Times.Never); - service.RotationTimer!.Dispose(); + Assert.That(service.RotationTimer, Is.Null); Assert.That(Environment.GetEnvironmentVariable(ServiceEnvironmentVariable.PlaywrightServiceUri), Is.Null); }