mirror of
https://github.com/microsoft/playwright-dotnet.git
synced 2026-10-28 22:05:13 +08:00
fix: get rid of driver wrapper (#2786)
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
|
||||
| | Linux | macOS | Windows |
|
||||
| :--- | :---: | :---: | :---: |
|
||||
| Chromium <!-- GEN:chromium-version -->120.0.6099.28<!-- GEN:stop --> | ✅ | ✅ | ✅ |
|
||||
| Chromium <!-- GEN:chromium-version -->120.0.6099.56<!-- GEN:stop --> | ✅ | ✅ | ✅ |
|
||||
| WebKit <!-- GEN:webkit-version -->17.4<!-- GEN:stop --> | ✅ | ✅ | ✅ |
|
||||
| Firefox <!-- GEN:firefox-version -->119.0<!-- GEN:stop --> | ✅ | ✅ | ✅ |
|
||||
|
||||
|
||||
@@ -51,9 +51,6 @@ function update_assets() {
|
||||
}
|
||||
|
||||
function roll_driver() {
|
||||
cat "${upstream_repo_path}/utils/build/run-driver-posix.sh" | sed "s|package|../../package|" > "src/Playwright/Scripts/playwright.sh"
|
||||
cat "${upstream_repo_path}/utils/build/run-driver-win.cmd" | sed "s|package|..\\\..\\\package|" > "src/Playwright/Scripts/playwright.cmd"
|
||||
|
||||
new_driver_version="$1"
|
||||
upstream_package_version=$(node -e "console.log(require('${upstream_repo_path}/package.json').version)")
|
||||
echo "Rolling .NET driver to driver ${new_driver_version} and upstream version ${upstream_package_version}..."
|
||||
|
||||
@@ -520,7 +520,8 @@ public class BrowserTypeConnectTests : PlaywrightTestEx
|
||||
{
|
||||
try
|
||||
{
|
||||
var startInfo = new ProcessStartInfo(Driver.GetExecutablePath(), $"launch-server --browser {browserName}")
|
||||
var (executablePath, getArgs) = Driver.GetExecutablePath();
|
||||
var startInfo = new ProcessStartInfo(executablePath, getArgs($"launch-server --browser {browserName}"))
|
||||
{
|
||||
UseShellExecute = false,
|
||||
RedirectStandardOutput = true,
|
||||
|
||||
@@ -39,7 +39,7 @@ internal static class Driver
|
||||
["PW_CLI_DISPLAY_VERSION"] = typeof(Driver).Assembly.GetName().Version.ToString(3),
|
||||
};
|
||||
|
||||
internal static string GetExecutablePath()
|
||||
internal static (string ExecutablePath, Func<string, string> GetArgs) GetExecutablePath()
|
||||
{
|
||||
DirectoryInfo assemblyDirectory = null;
|
||||
if (!string.IsNullOrEmpty(AppContext.BaseDirectory))
|
||||
@@ -64,53 +64,54 @@ internal static class Driver
|
||||
}
|
||||
|
||||
string executableFile;
|
||||
Func<string, string> getArgs;
|
||||
|
||||
// When loading the Assembly via the memory we don't have any references where the driver might be located.
|
||||
// To workaround this we pass this env from the .ps1 wrapper over to the Assembly.
|
||||
var driverSearchPath = Environment.GetEnvironmentVariable("PLAYWRIGHT_DRIVER_SEARCH_PATH");
|
||||
if (!string.IsNullOrEmpty(driverSearchPath))
|
||||
{
|
||||
executableFile = GetPath(driverSearchPath);
|
||||
(executableFile, getArgs) = GetPath(driverSearchPath);
|
||||
if (!File.Exists(executableFile))
|
||||
{
|
||||
throw new PlaywrightException("Couldn't find driver in \"PLAYWRIGHT_DRIVER_SEARCH_PATH\"");
|
||||
}
|
||||
return executableFile;
|
||||
return (executableFile, getArgs);
|
||||
}
|
||||
|
||||
executableFile = GetPath(assemblyDirectory.FullName);
|
||||
(executableFile, getArgs) = GetPath(assemblyDirectory.FullName);
|
||||
if (File.Exists(executableFile))
|
||||
{
|
||||
return executableFile;
|
||||
return (executableFile, getArgs);
|
||||
}
|
||||
|
||||
// if the above fails, we can assume we're in the nuget registry
|
||||
executableFile = GetPath(assemblyDirectory.Parent.Parent.FullName);
|
||||
(executableFile, getArgs) = GetPath(assemblyDirectory.Parent.Parent.FullName);
|
||||
if (File.Exists(executableFile))
|
||||
{
|
||||
return executableFile;
|
||||
return (executableFile, getArgs);
|
||||
}
|
||||
|
||||
throw new PlaywrightException($"Driver not found: {executableFile}");
|
||||
}
|
||||
|
||||
private static string GetPath(string driversPath)
|
||||
private static (string ExecutablePath, Func<string, string> GetArgs) GetPath(string driversPath)
|
||||
{
|
||||
string platformId;
|
||||
string runnerName;
|
||||
string nodeExecutable;
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
platformId = "win32_x64";
|
||||
runnerName = "playwright.cmd";
|
||||
nodeExecutable = "node.exe";
|
||||
}
|
||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||
{
|
||||
runnerName = "playwright.sh";
|
||||
nodeExecutable = "node";
|
||||
platformId = RuntimeInformation.ProcessArchitecture == Architecture.Arm64 ? "darwin-arm64" : "darwin-x64";
|
||||
}
|
||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
{
|
||||
runnerName = "playwright.sh";
|
||||
nodeExecutable = "node";
|
||||
platformId = RuntimeInformation.ProcessArchitecture == Architecture.Arm64 ? "linux-arm64" : "linux-x64";
|
||||
}
|
||||
else
|
||||
@@ -118,6 +119,13 @@ internal static class Driver
|
||||
throw new PlaywrightException("Unknown platform");
|
||||
}
|
||||
|
||||
return Path.Combine(driversPath, ".playwright", "node", platformId, runnerName);
|
||||
var cliEntrypoint = Path.Combine(driversPath, ".playwright", "package", "lib", "cli", "cli.js");
|
||||
string getArgs(string args)
|
||||
{
|
||||
return !string.IsNullOrEmpty(args) ? $"\"{cliEntrypoint}\" {args}" : cliEntrypoint;
|
||||
}
|
||||
return (
|
||||
Environment.GetEnvironmentVariable("PLAYWRIGHT_NODEJS_PATH") ?? Path.GetFullPath(Path.Combine(driversPath, ".playwright", "node", platformId, nodeExecutable)),
|
||||
getArgs);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,11 +43,6 @@
|
||||
<None Include=".drivers\mac\node" Link=".playwright\node\darwin-x64\node" CopyToOutputDirectory="PreserveNewest" Pack="true" PackagePath=".playwright\node\darwin-x64" />
|
||||
<None Include=".drivers\mac-arm64\node" Link=".playwright\node\darwin-arm64\node" CopyToOutputDirectory="PreserveNewest" Pack="true" PackagePath=".playwright\node\darwin-arm64" />
|
||||
<None Include=".drivers\win32_x64\node.exe" Link=".playwright\node\win32_x64\node.exe" CopyToOutputDirectory="PreserveNewest" Pack="true" PackagePath=".playwright\node\win32_x64" />
|
||||
<None Include="Scripts\playwright.sh" Link=".playwright\node\linux-x64\playwright.sh" CopyToOutputDirectory="PreserveNewest" Pack="true" PackagePath=".playwright\node\linux-x64" />
|
||||
<None Include="Scripts\playwright.sh" Link=".playwright\node\linux-arm64\playwright.sh" CopyToOutputDirectory="PreserveNewest" Pack="true" PackagePath=".playwright\node\linux-arm64" />
|
||||
<None Include="Scripts\playwright.sh" Link=".playwright\node\darwin-x64\playwright.sh" CopyToOutputDirectory="PreserveNewest" Pack="true" PackagePath=".playwright\node\darwin-x64" />
|
||||
<None Include="Scripts\playwright.sh" Link=".playwright\node\darwin-arm64\playwright.sh" CopyToOutputDirectory="PreserveNewest" Pack="true" PackagePath=".playwright\node\darwin-arm64" />
|
||||
<None Include="Scripts\playwright.cmd" Link=".playwright\node\win32_x64\playwright.cmd" CopyToOutputDirectory="PreserveNewest" Pack="true" PackagePath=".playwright\node\win32_x64" />
|
||||
<None Include="build\playwright.ps1" Link="playwright.ps1" CopyToOutputDirectory="PreserveNewest" />
|
||||
<None Include="build\**" Pack="true" PackagePath="buildTransitive" />
|
||||
<None Include="build\**" Pack="true" PackagePath="build" />
|
||||
|
||||
@@ -38,18 +38,18 @@ public class Program
|
||||
|
||||
public int Run(string[] args)
|
||||
{
|
||||
string pwPath = null;
|
||||
Func<string, string> getArgs;
|
||||
string executablePath;
|
||||
try
|
||||
{
|
||||
pwPath = Driver.GetExecutablePath();
|
||||
(executablePath, getArgs) = Driver.GetExecutablePath();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return PrintError("Microsoft.Playwright assembly was found, but is missing required assets. Please ensure to build your project before running Playwright tool.");
|
||||
}
|
||||
|
||||
string allArgs = args != null && args.Length > 0 ? "\"" + string.Join("\" \"", args) + "\"" : string.Empty;
|
||||
var playwrightStartInfo = new ProcessStartInfo(pwPath, allArgs)
|
||||
var playwrightStartInfo = new ProcessStartInfo(executablePath, getArgs(args?.Length > 0 ? "\"" + string.Join("\" \"", args) + "\"" : null))
|
||||
{
|
||||
UseShellExecute = false,
|
||||
// This works after net8.0-preview-4
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
@echo off
|
||||
setlocal
|
||||
if not defined PLAYWRIGHT_NODEJS_PATH set PLAYWRIGHT_NODEJS_PATH=%~dp0node.exe
|
||||
"%PLAYWRIGHT_NODEJS_PATH%" "%~dp0..\..\package\lib\cli\cli.js" %*
|
||||
@@ -1,6 +0,0 @@
|
||||
#!/bin/sh
|
||||
SCRIPT_PATH="$(cd "$(dirname "$0")" ; pwd -P)"
|
||||
if [ -z "$PLAYWRIGHT_NODEJS_PATH" ]; then
|
||||
PLAYWRIGHT_NODEJS_PATH="$SCRIPT_PATH/node"
|
||||
fi
|
||||
"$PLAYWRIGHT_NODEJS_PATH" "$SCRIPT_PATH/../../package/lib/cli/cli.js" "$@"
|
||||
@@ -43,8 +43,7 @@ internal class StdIOTransport : IDisposable
|
||||
|
||||
internal StdIOTransport()
|
||||
{
|
||||
_process = GetProcess();
|
||||
_process.StartInfo.Arguments = "run-driver";
|
||||
_process = GetProcess("run-driver");
|
||||
StartProcessWithUTF8IOEncoding(_process);
|
||||
_process.Exited += (_, _) => Close(new TargetClosedException("Process exited"));
|
||||
_process.ErrorDataReceived += (_, error) =>
|
||||
@@ -112,9 +111,10 @@ internal class StdIOTransport : IDisposable
|
||||
}
|
||||
}
|
||||
|
||||
private static Process GetProcess()
|
||||
private static Process GetProcess(string driverArgs)
|
||||
{
|
||||
var startInfo = new ProcessStartInfo(Driver.GetExecutablePath())
|
||||
var (executablePath, getArgs) = Driver.GetExecutablePath();
|
||||
var startInfo = new ProcessStartInfo(executablePath, getArgs(driverArgs))
|
||||
{
|
||||
UseShellExecute = false,
|
||||
RedirectStandardOutput = true,
|
||||
|
||||
@@ -57,10 +57,10 @@
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
</Target>
|
||||
<Target Name="PlaywrightChmodExecutables" AfterTargets="CopyFilesToOutputDirectory;CopyFilesToPublishDirectory" Condition="!$([MSBuild]::IsOSPlatform('Windows'))">
|
||||
<Target Name="PlaywrightChmodExecutables" AfterTargets="CopyFilesToOutputDirectory;CopyFilesToPublishDirectory" Condition="!$([MSBuild]::IsOSPlatform('Windows'))">
|
||||
<ItemGroup>
|
||||
<_PlaywrightChmodItems Include="$(OutputPath).playwright\node\*\playwright.sh" />
|
||||
<_PlaywrightChmodItems Include="$(PublishDir).playwright\node\*\playwright.sh" />
|
||||
<_PlaywrightChmodItems Include="$(OutputPath).playwright\node\*\node" />
|
||||
<_PlaywrightChmodItems Include="$(PublishDir).playwright\node\*\node" />
|
||||
</ItemGroup>
|
||||
<Exec Command="chmod +x "%(_PlaywrightChmodItems.FullPath)"" />
|
||||
</Target>
|
||||
|
||||
@@ -26,13 +26,10 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
using DriverDownloader.Linux;
|
||||
using Playwright.Tooling.Options;
|
||||
|
||||
namespace Playwright.Tooling;
|
||||
@@ -137,20 +134,6 @@ internal class DriverDownloader
|
||||
|
||||
new ZipArchive(await response.Content.ReadAsStreamAsync().ConfigureAwait(false)).ExtractToDirectory(directory.FullName);
|
||||
|
||||
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
var executables = new[] { "playwright.sh", "node" }
|
||||
.Select(f => Path.Combine(directory.FullName, f));
|
||||
|
||||
foreach (string executable in executables)
|
||||
{
|
||||
if (new FileInfo(executable).Exists && LinuxSysCall.Chmod(executable, LinuxSysCall.ExecutableFilePermissions) != 0)
|
||||
{
|
||||
throw new($"Unable to chmod {executable} ({Marshal.GetLastWin32Error()})");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine($"Driver for {platform} downloaded");
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020 Darío Kondratiuk
|
||||
* Modifications copyright (c) Microsoft Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
using System;
|
||||
|
||||
namespace DriverDownloader.Linux;
|
||||
|
||||
[Flags]
|
||||
internal enum FileAccessPermissions : uint
|
||||
{
|
||||
OtherExecute = 1,
|
||||
OtherWrite = 2,
|
||||
OtherRead = 4,
|
||||
|
||||
GroupExecute = 8,
|
||||
GroupWrite = 16,
|
||||
GroupRead = 32,
|
||||
|
||||
UserExecute = 64,
|
||||
UserWrite = 128,
|
||||
UserRead = 256,
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020 Darío Kondratiuk
|
||||
* Modifications copyright (c) Microsoft Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace DriverDownloader.Linux;
|
||||
|
||||
internal static class LinuxSysCall
|
||||
{
|
||||
internal const FileAccessPermissions ExecutableFilePermissions =
|
||||
FileAccessPermissions.UserRead |
|
||||
FileAccessPermissions.UserWrite |
|
||||
FileAccessPermissions.UserExecute |
|
||||
FileAccessPermissions.GroupRead |
|
||||
FileAccessPermissions.GroupExecute |
|
||||
FileAccessPermissions.OtherRead |
|
||||
FileAccessPermissions.OtherExecute;
|
||||
|
||||
[DllImport("libc", SetLastError = true, EntryPoint = "chmod")]
|
||||
internal static extern int Chmod(string path, FileAccessPermissions mode);
|
||||
}
|
||||
Reference in New Issue
Block a user