Skip to content

Commit

Permalink
fix: make sure it works with packages.config (.NET 4.8)
Browse files Browse the repository at this point in the history
Extended Playwright.CreateAsync() with optional driversPath param

Fixes microsoft#1842, fixes microsoft#2240, fixes microsoft#2004
  • Loading branch information
BeniFreitag committed Aug 8, 2022
1 parent 84abeee commit 381d751
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
7 changes: 6 additions & 1 deletion src/Playwright/Helpers/Driver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,13 @@ namespace Microsoft.Playwright.Helpers
{
internal static class Driver
{
internal static string GetExecutablePath()
internal static string GetExecutablePath(string driversPath = null)
{
if (driversPath != null)
{
return GetPath(driversPath);
}

DirectoryInfo assemblyDirectory = new(AppContext.BaseDirectory);
if (!assemblyDirectory.Exists || !File.Exists(Path.Combine(assemblyDirectory.FullName, "Microsoft.Playwright.dll")))
{
Expand Down
5 changes: 3 additions & 2 deletions src/Playwright/Playwright.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ public static class Playwright
/// <summary>
/// Launches Playwright.
/// </summary>
/// <param name="driversPath">Playwright driver path.</param>
/// <returns>A <see cref="Task"/> that completes when the playwright driver is ready to be used.</returns>
public static async Task<IPlaywright> CreateAsync()
public static async Task<IPlaywright> CreateAsync(string driversPath = null)
{
#pragma warning disable CA2000 // Dispose objects before losing scope
var transport = new StdIOTransport();
var transport = new StdIOTransport(driversPath);
#pragma warning restore CA2000
var connection = new Connection();
transport.MessageReceived += (_, message) => connection.Dispatch(JsonSerializer.Deserialize<PlaywrightServerMessage>(message, JsonExtensions.DefaultJsonSerializerOptions));
Expand Down
8 changes: 4 additions & 4 deletions src/Playwright/Transport/StdIOTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ internal class StdIOTransport : IConnectionTransport, IDisposable
private readonly List<byte> _data = new();
private int? _currentMessageSize;

internal StdIOTransport()
internal StdIOTransport(string driversPath = null)
{
_process = GetProcess();
_process = GetProcess(driversPath);
_process.StartInfo.Arguments = "run-driver";
_process.Start();
_process.Exited += (_, _) => Close("Process exited");
Expand Down Expand Up @@ -114,9 +114,9 @@ public async Task SendAsync(byte[] message)
}
}

private static Process GetProcess()
private static Process GetProcess(string driversPath = null)
{
var startInfo = new ProcessStartInfo(Driver.GetExecutablePath())
var startInfo = new ProcessStartInfo(Driver.GetExecutablePath(driversPath))
{
UseShellExecute = false,
RedirectStandardOutput = true,
Expand Down

0 comments on commit 381d751

Please sign in to comment.