Skip to content

Commit

Permalink
fix(playwrighttesting): no auth error when scalable scenario is disab…
Browse files Browse the repository at this point in the history
…led (#47050)

Co-authored-by: Siddharth Singha Roy <ssingharoy@microsoft.com>
  • Loading branch information
Sid200026 and Siddharth Singha Roy authored Nov 11, 2024
1 parent 94939dc commit d9e0d05
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TokenRequestContext>(), It.IsAny<CancellationToken>()), Times.Once);
defaultAzureCredentialMock.Verify(x => x.GetTokenAsync(It.IsAny<TokenRequestContext>(), It.IsAny<CancellationToken>()), Times.Never);

service.RotationTimer!.Dispose();
Assert.That(service.RotationTimer, Is.Null);

Assert.That(Environment.GetEnvironmentVariable(ServiceEnvironmentVariable.PlaywrightServiceUri), Is.Null);
}
Expand Down

0 comments on commit d9e0d05

Please sign in to comment.