Skip to content

Commit f8b52f6

Browse files
kashish2508guptakashish
andauthored
fix(loadtesting): added handling for playwright version support (#50977)
Co-authored-by: guptakashish <guptakashish@microsoft.com>
1 parent f1bab2d commit f8b52f6

File tree

7 files changed

+243
-57
lines changed

7 files changed

+243
-57
lines changed

sdk/loadtestservice/Azure.Developer.Playwright/Azure.Developer.Playwright.sln

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,4 @@ Global
4545
GlobalSection(SolutionProperties) = preSolution
4646
HideSolutionNode = FALSE
4747
EndGlobalSection
48-
GlobalSection(NestedProjects) = preSolution
49-
{F10A93E7-41D3-4557-AB3B-3F8FB8BC8542} = {827E0CD3-B72D-47B6-A68D-7590B98EB39B}
50-
{1D00EEEE-5836-4568-8CBB-EFED98207F50} = {0AB3BF05-4346-4AA6-1389-037BE0695223}
51-
EndGlobalSection
5248
EndGlobal

sdk/loadtestservice/Azure.Developer.Playwright/src/Constants.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ internal class Constants
134134
internal static readonly string s_default_os = OSConstants.s_lINUX;
135135
internal static readonly string s_default_expose_network = "<loopback>";
136136
internal static readonly string s_pLAYWRIGHT_SERVICE_DEBUG = "Logging__LogLevel__AzurePlaywright";
137+
internal static readonly string s_minimumSupportedPlaywrightVersion = "1.50.0";
137138

138139
// Entra id access token constants
139140
internal static readonly int s_entra_access_token_lifetime_left_threshold_in_minutes_for_rotation = 15;
@@ -152,6 +153,8 @@ internal class Constants
152153
internal static readonly string s_invalid_service_endpoint_error_message = "The service endpoint provided is invalid. Please verify the endpoint URL and try again.";
153154
internal static readonly string s_playwright_service_runId_length_exceeded_error_message = "Error: The Run Id you provided exceeds 200 characters. Please provide a shorter Run ID.";
154155
internal static readonly string s_playwright_service_runName_truncated_warning = "WARNING: Run name exceeds the maximum limit of 200 characters and will be truncated.";
156+
internal static readonly string s_playwright_Version_not_supported_error_message = "The Playwright version you are using does not support playwright workspaces. Please update to Playwright version 1.50.0 or higher.";
157+
internal static readonly string s_playwright_Invalid_version = "The Playwright version you are using is not supported. See the list of supported versions at https://aka.ms/mpt/supported-versions.";
155158

156159
// Internal environment variables
157160
internal static readonly string s_playwright_service_use_cloud_hosted_browsers_environment_variable = "_MPT_USE_CLOUD_HOSTED_BROWSERS";
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
using Azure.Developer.Playwright.Interface;
10+
11+
namespace Azure.Developer.Playwright.Implementation
12+
{
13+
internal class PlaywrightVersion: IPlaywrightVersion
14+
{
15+
public void ValidatePlaywrightVersion()
16+
{
17+
var minimumSupportedVersion = Constants.s_minimumSupportedPlaywrightVersion;
18+
var installedVersion = GetPlaywrightVersion();
19+
20+
var minimumSupportedVersionInfo = GetVersionInfo(minimumSupportedVersion);
21+
var installedVersionInfo = GetVersionInfo(installedVersion);
22+
23+
var isInstalledVersionGreater =
24+
installedVersionInfo.Major > minimumSupportedVersionInfo.Major ||
25+
(installedVersionInfo.Major == minimumSupportedVersionInfo.Major &&
26+
installedVersionInfo.Minor >= minimumSupportedVersionInfo.Minor);
27+
28+
if (!isInstalledVersionGreater)
29+
{
30+
throw new Exception(Constants.s_playwright_Version_not_supported_error_message);
31+
}
32+
}
33+
internal string GetPlaywrightVersion()
34+
{
35+
string assemblyName = "Microsoft.Playwright";
36+
37+
var assembly = AppDomain.CurrentDomain
38+
.GetAssemblies()
39+
.FirstOrDefault(a => a.GetName().Name == assemblyName);
40+
41+
if (assembly != null)
42+
{
43+
Version version = assembly.GetName().Version!;
44+
return version.ToString();
45+
}
46+
else
47+
{
48+
throw new Exception(Constants.s_playwright_Invalid_version);
49+
}
50+
}
51+
52+
internal (int Major, int Minor) GetVersionInfo(string version)
53+
{
54+
var parts = version.Split('.');
55+
if (parts.Length < 2 ||
56+
!int.TryParse(parts[0], out var major) ||
57+
!int.TryParse(parts[1], out var minor))
58+
{
59+
throw new ArgumentException("Invalid version format.");
60+
}
61+
return (major, minor);
62+
}
63+
}
64+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
10+
namespace Azure.Developer.Playwright.Interface
11+
{
12+
internal interface IPlaywrightVersion
13+
{
14+
void ValidatePlaywrightVersion();
15+
}
16+
}

sdk/loadtestservice/Azure.Developer.Playwright/src/PlaywrightServiceBrowserClient.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class PlaywrightServiceBrowserClient : IDisposable
2626
internal readonly PlaywrightServiceBrowserClientOptions _options;
2727
internal readonly ClientUtilities _clientUtility;
2828
internal readonly ILogger? _logger;
29+
internal readonly IPlaywrightVersion _playwrightVersion;
2930
internal Timer? RotationTimer { get; set; }
3031

3132
/// <summary>
@@ -79,15 +80,16 @@ public PlaywrightServiceBrowserClient(TokenCredential credential, PlaywrightServ
7980
// No-op
8081
}
8182

82-
internal PlaywrightServiceBrowserClient(IEnvironment? environment = null, IEntraLifecycle? entraLifecycle = null, JsonWebTokenHandler? jsonWebTokenHandler = null, ILogger? logger = null, ClientUtilities? clientUtility = null, PlaywrightServiceBrowserClientOptions? options = null, TokenCredential? tokenCredential = null)
83+
internal PlaywrightServiceBrowserClient(IEnvironment? environment = null, IEntraLifecycle? entraLifecycle = null, JsonWebTokenHandler? jsonWebTokenHandler = null, ILogger? logger = null, ClientUtilities? clientUtility = null, PlaywrightServiceBrowserClientOptions? options = null, TokenCredential? tokenCredential = null, IPlaywrightVersion? playwrightVersion = null)
8384
{
8485
_environment = environment ?? new EnvironmentHandler();
8586
_clientUtility = clientUtility ?? new ClientUtilities(_environment);
8687
_options = options ?? new PlaywrightServiceBrowserClientOptions(PlaywrightServiceBrowserClientOptions.ServiceVersion.V2025_07_01_Preview, environment: _environment, clientUtility: _clientUtility);
8788
_logger = logger ?? _options.Logger;
8889
_jsonWebTokenHandler = jsonWebTokenHandler ?? new JsonWebTokenHandler();
8990
_entraLifecycle = entraLifecycle ?? new EntraLifecycle(jsonWebTokenHandler: _jsonWebTokenHandler, logger: _logger, environment: _environment, tokenCredential: tokenCredential);
90-
91+
_playwrightVersion = playwrightVersion ?? new PlaywrightVersion();
92+
_playwrightVersion.ValidatePlaywrightVersion();
9193
// Call getters to set default environment variables if not already set before
9294
_ = _options.OS;
9395
_ = _options.RunId;

0 commit comments

Comments
 (0)