mirror of
https://github.com/microsoft/playwright-dotnet.git
synced 2026-10-29 14:11:20 +08:00
chore(driver): Copy drivers on build time (#991)
* Drivers as part of the package
* Remove ApiChecker
* Package config project
* Builds
* Rename workflow
* Don't linux on Windows
* Ops
* Download drivers earlier
* Fix tests
* Fix encoding
* Drop .net framework test
* Fix temp nuget folder
* Split actions
* Rename action
* Delete log file
* Revert "Remove ApiChecker"
This reverts commit 2c89fed867.
* Improve build
* Before restore
* Update .github/workflows/nuget-package-tests.yml
Co-authored-by: Max Schmitt <max@schmitt.mx>
* Update nuget-package-tests.yml
* update .NET Core install
Co-authored-by: Max Schmitt <max@schmitt.mx>
This commit is contained in:
co-authored by
Max Schmitt
parent
1aca40a8fc
commit
c558f7d618
@@ -0,0 +1,45 @@
|
||||
name: Tests Nuget Packages
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
test-nuget-packages:
|
||||
name: Nuget Tests on ${{ matrix.os }}
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [windows-latest, ubuntu-latest, macos-latest]
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Setup .NET Core (On Mac)
|
||||
if: ${{ matrix.os == 'macos-latest' }}
|
||||
uses: actions/setup-dotnet@v1
|
||||
with:
|
||||
dotnet-version: 3.1.100
|
||||
env:
|
||||
DOTNET_INSTALL_DIR: /users/runner/alternate/dotnet
|
||||
- name: Setup .NET Core (Not on mac)
|
||||
if: ${{ matrix.os != 'macos-latest' }}
|
||||
uses: actions/setup-dotnet@v1
|
||||
with:
|
||||
dotnet-version: 3.1.100
|
||||
- name: Build Project
|
||||
run: dotnet build ./src/PlaywrightSharp/PlaywrightSharp.csproj -c Debug
|
||||
- name: Delete browsers on Mac
|
||||
if: matrix.os == 'macos-latest'
|
||||
run: rm -r ~/Library/Caches/ms-playwright
|
||||
- name: Delete browsers on Linux
|
||||
if: ${{ matrix.os == 'ubuntu-latest' }}
|
||||
run: rm -r ~/.cache/ms-playwright
|
||||
- name: Delete browsers on windows
|
||||
if: matrix.os == 'windows-latest'
|
||||
run: Remove-Item -path $env:USERPROFILE\AppData\Local\ms-playwright -recurse
|
||||
- name: Run Tests
|
||||
run: dotnet test ./src/PlaywrightSharp.LocalNugetTest/PlaywrightSharp.LocalNugetTest.csproj
|
||||
@@ -40,15 +40,19 @@ jobs:
|
||||
if: ${{ matrix.os != 'ubuntu-latest' }}
|
||||
env:
|
||||
PRODUCT: ${{ matrix.product }}
|
||||
run: dotnet test ./src/PlaywrightSharp.Tests/PlaywrightSharp.Tests.csproj -c Debug -f netcoreapp3.1 --logger "trx;LogFileName=TestResults.xml"
|
||||
run: |
|
||||
dotnet build ./src/PlaywrightSharp/PlaywrightSharp.csproj -c Debug
|
||||
dotnet test ./src/PlaywrightSharp.Tests/PlaywrightSharp.Tests.csproj -c Debug -f netcoreapp3.1 --logger "trx;LogFileName=TestResults.xml"
|
||||
- name: Run tests (Linux)
|
||||
if: ${{ matrix.os == 'ubuntu-latest' }}
|
||||
env:
|
||||
PRODUCT: ${{ matrix.product }}
|
||||
run: xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- bash -c "ulimit -c unlimited && dotnet test ./src/PlaywrightSharp.Tests/PlaywrightSharp.Tests.csproj -c Debug -f netcoreapp3.1 --logger \"trx;LogFileName=TestResults.xml\""
|
||||
run: |
|
||||
dotnet build ./src/PlaywrightSharp/PlaywrightSharp.csproj -c Debug
|
||||
xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- bash -c "ulimit -c unlimited && dotnet test ./src/PlaywrightSharp.Tests/PlaywrightSharp.Tests.csproj -c Debug -f netcoreapp3.1 --logger \"trx;LogFileName=TestResults.xml\""
|
||||
- name: Test results
|
||||
uses: actions/upload-artifact@v1
|
||||
if: always()
|
||||
with:
|
||||
name: TestResult.xml
|
||||
path: ./src/PlaywrightSharp.Tests/TestResults/TestResults.xml
|
||||
path: ./src/PlaywrightSharp.Tests/TestResults/TestResults.xml
|
||||
@@ -351,3 +351,4 @@ MigrationBackup/
|
||||
.idea
|
||||
src/PlaywrightSharp.sln.DotSettings
|
||||
src/PlaywrightSharp/Drivers
|
||||
src/PlaywrightSharp/runtimes
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<PackageVersion>0.152.0</PackageVersion>
|
||||
<AssemblyVersion>0.162.0</AssemblyVersion>
|
||||
<PackageVersion>$(AssemblyVersion)-alpha</PackageVersion>
|
||||
<DriverVersion>0.162.1</DriverVersion>
|
||||
<AssemblyVersion>$(PackageVersion)</AssemblyVersion>
|
||||
<ReleaseVersion>$(PackageVersion)</ReleaseVersion>
|
||||
<FileVersion>$(PackageVersion)</FileVersion>
|
||||
<ReleaseVersion>$(AssemblyVersion)</ReleaseVersion>
|
||||
<FileVersion>$(AssemblyVersion)</FileVersion>
|
||||
<Authors>Darío Kondratiuk</Authors>
|
||||
<Owners>Darío Kondratiuk</Owners>
|
||||
<PackageProjectUrl>https://github.com/microsoft/playwright-sharp</PackageProjectUrl>
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<packageSources>
|
||||
<add key="repositoryPath" value="../PlaywrightSharp/bin/Debug" />
|
||||
</packageSources>
|
||||
</configuration>
|
||||
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace PlaywrightSharp.LocalNugetTest
|
||||
{
|
||||
public class NugetTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task ShouldWork()
|
||||
{
|
||||
using var playwright = await Playwright.CreateAsync();
|
||||
await using var browser = await playwright.Chromium.LaunchAsync();
|
||||
|
||||
var page = await browser.NewPageAsync();
|
||||
Console.WriteLine("Navigating google");
|
||||
await page.GoToAsync("http://www.google.com");
|
||||
|
||||
Assert.Contains("Google", await page.GetTitleAsync());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
<LangVersion>8.0</LangVersion>
|
||||
<ReleaseVersion>0.0.0</ReleaseVersion>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="PlaywrightSharp" Version="0.160.0-alpha" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,22 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlaywrightSharp.LocalNugetTest", "PlaywrightSharp.LocalNugetTest.csproj", "{A4AEC544-D521-4CD4-9A8F-F6926DEFC233}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{4611591F-E17F-4601-89AC-F4D9BE665940}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
NuGet.Config = NuGet.Config
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{A4AEC544-D521-4CD4-9A8F-F6926DEFC233}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{A4AEC544-D521-4CD4-9A8F-F6926DEFC233}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A4AEC544-D521-4CD4-9A8F-F6926DEFC233}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{A4AEC544-D521-4CD4-9A8F-F6926DEFC233}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -14,15 +14,13 @@ namespace PlaywrightSharp.Tests.BaseTests
|
||||
|
||||
internal static async Task SetupAsync()
|
||||
{
|
||||
var downloaderTask = PlaywrightSharp.Playwright.InstallAsync();
|
||||
|
||||
Server = SimpleServer.Create(TestConstants.Port, TestUtils.FindParentDirectory("PlaywrightSharp.TestServer"));
|
||||
HttpsServer = SimpleServer.CreateHttps(TestConstants.HttpsPort, TestUtils.FindParentDirectory("PlaywrightSharp.TestServer"));
|
||||
|
||||
var serverStart = Server.StartAsync();
|
||||
var httpsServerStart = HttpsServer.StartAsync();
|
||||
|
||||
await Task.WhenAll(downloaderTask, serverStart, httpsServerStart);
|
||||
await Task.WhenAll(serverStart, httpsServerStart);
|
||||
}
|
||||
|
||||
internal static Task TeardownAsync() => Task.WhenAll(Server.StopAsync(), HttpsServer.StopAsync());
|
||||
|
||||
@@ -24,12 +24,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlaywrightSharp.Demo", "Pla
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tools", "Tools", "{5C6D57B1-C82A-48D6-9EBD-73B712CAE476}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ApiChecker", "tools\ApiChecker\ApiChecker.csproj", "{9430DBAB-C5E3-4D37-84B2-EF86566D5AAA}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlaywrightSharpTool", "tools\PlaywrightSharpTool\PlaywrightSharpTool.csproj", "{795BA2A6-D983-4D96-B817-6921A145AB56}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DriverDownloader", "tools\DriverDownloader\DriverDownloader.csproj", "{27C6BCBD-94DC-4D1F-8F61-85DD3258A8EB}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ApiChecker", "tools\ApiChecker\ApiChecker.csproj", "{307DF999-0B02-40C9-971F-7BA5203DBE61}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -52,10 +52,6 @@ Global
|
||||
{FB3348E3-9759-4B90-9C8C-391F44AD5F8F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{FB3348E3-9759-4B90-9C8C-391F44AD5F8F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{FB3348E3-9759-4B90-9C8C-391F44AD5F8F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{9430DBAB-C5E3-4D37-84B2-EF86566D5AAA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9430DBAB-C5E3-4D37-84B2-EF86566D5AAA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9430DBAB-C5E3-4D37-84B2-EF86566D5AAA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9430DBAB-C5E3-4D37-84B2-EF86566D5AAA}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{795BA2A6-D983-4D96-B817-6921A145AB56}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{795BA2A6-D983-4D96-B817-6921A145AB56}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{795BA2A6-D983-4D96-B817-6921A145AB56}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
@@ -63,15 +59,19 @@ Global
|
||||
{27C6BCBD-94DC-4D1F-8F61-85DD3258A8EB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{27C6BCBD-94DC-4D1F-8F61-85DD3258A8EB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{27C6BCBD-94DC-4D1F-8F61-85DD3258A8EB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{307DF999-0B02-40C9-971F-7BA5203DBE61}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{307DF999-0B02-40C9-971F-7BA5203DBE61}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{307DF999-0B02-40C9-971F-7BA5203DBE61}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{307DF999-0B02-40C9-971F-7BA5203DBE61}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{A907B324-4541-4FAF-8CAE-D0B512B4BC36} = {D250D790-5A30-4C38-8F60-50FA96DB4E67}
|
||||
{9430DBAB-C5E3-4D37-84B2-EF86566D5AAA} = {5C6D57B1-C82A-48D6-9EBD-73B712CAE476}
|
||||
{795BA2A6-D983-4D96-B817-6921A145AB56} = {5C6D57B1-C82A-48D6-9EBD-73B712CAE476}
|
||||
{27C6BCBD-94DC-4D1F-8F61-85DD3258A8EB} = {5C6D57B1-C82A-48D6-9EBD-73B712CAE476}
|
||||
{307DF999-0B02-40C9-971F-7BA5203DBE61} = {5C6D57B1-C82A-48D6-9EBD-73B712CAE476}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {8D6EDE73-B005-4ABC-BCF8-BB3C154497EC}
|
||||
|
||||
@@ -92,7 +92,6 @@ namespace PlaywrightSharp
|
||||
/// </summary>
|
||||
/// <param name="loggerFactory">Logger.</param>
|
||||
/// <param name="scheduler">Task scheduler for long running tasks.</param>
|
||||
/// <param name="driversLocationPath">Drivers location. Defaults to the PlaywrightSharp assembly path.</param>
|
||||
/// <param name="driverExecutablePath">Playwright driver path. If not set <see cref="InstallAsync(string, string)"/> needs to be used.</param>
|
||||
/// <param name="browsersPath">Specify a shared folder that playwright will use to download browsers and to look for browsers when launching browser instances.
|
||||
/// It is a shortcut to the PLAYWRIGHT_BROWSERS_PATH environment variable.
|
||||
@@ -104,7 +103,6 @@ namespace PlaywrightSharp
|
||||
public static async Task<IPlaywright> CreateAsync(
|
||||
ILoggerFactory loggerFactory = null,
|
||||
TransportTaskScheduler scheduler = null,
|
||||
string driversLocationPath = null,
|
||||
string driverExecutablePath = null,
|
||||
string browsersPath = null,
|
||||
string debug = null)
|
||||
@@ -114,7 +112,7 @@ namespace PlaywrightSharp
|
||||
Environment.SetEnvironmentVariable("DEBUG", debug);
|
||||
}
|
||||
|
||||
var connection = new Connection(loggerFactory, scheduler, driversLocationPath, driverExecutablePath, browsersPath);
|
||||
var connection = new Connection(loggerFactory, scheduler, driverExecutablePath, browsersPath);
|
||||
|
||||
var playwright = await connection.WaitForObjectWithKnownName<Playwright>("Playwright").ConfigureAwait(false);
|
||||
playwright.Connection = connection;
|
||||
@@ -132,12 +130,6 @@ namespace PlaywrightSharp
|
||||
public static Task InstallAsync(string browsersPath = null, string driverExecutablePath = null)
|
||||
=> Connection.InstallAsync(driverExecutablePath, browsersPath);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a Playwright driver in the specified <paramref name="path"/>.
|
||||
/// </summary>
|
||||
/// <param name="path">Destination path.</param>
|
||||
public static void InstallDriver(string path) => Connection.InstallDriver(path);
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<RootNamespace>PlaywrightSharp</RootNamespace>
|
||||
<ReleaseVersion>0.0.0</ReleaseVersion>
|
||||
<BuildFromSource>True</BuildFromSource>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<NoWarn>1701;1702;CS0067</NoWarn>
|
||||
@@ -24,6 +25,7 @@
|
||||
<Import Project="../Common/Dependencies.props" />
|
||||
<Import Project="../Common/SignAssembly.props" />
|
||||
<Import Project="../Common/PackageInfo.props" />
|
||||
<Import Project="build/netstandard2.0/PlaywrightSharp.targets" />
|
||||
<ItemGroup>
|
||||
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
|
||||
<_Parameter1>PlaywrightSharp.Tests, PublicKey=$(AssemblyPublicKey)</_Parameter1>
|
||||
@@ -32,32 +34,43 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Esprima" Version="1.0.1270" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.1" />
|
||||
<PackageReference Include="System.Text.Json" Version="4.7.0" />
|
||||
<PackageReference Include="System.Text.Json" Version="4.7.2" />
|
||||
<PackageReference Include="Macross.Json.Extensions" Version="1.5.0" />
|
||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
|
||||
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="1.1.1" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Remove="Drivers\playwright-cli-linux.zip" />
|
||||
<EmbeddedResource Include="Drivers\playwright-cli-linux.zip">
|
||||
</EmbeddedResource>
|
||||
<None Remove="Drivers\playwright-cli-mac.zip" />
|
||||
<EmbeddedResource Include="Drivers\playwright-cli-mac.zip">
|
||||
</EmbeddedResource>
|
||||
<None Remove="Drivers\playwright-cli-win32_x64.zip" />
|
||||
<EmbeddedResource Include="Drivers\playwright-cli-win32_x64.zip">
|
||||
</EmbeddedResource>
|
||||
<None Remove="Drivers\playwright-cli-win32.zip" />
|
||||
<EmbeddedResource Include="Drivers\playwright-cli-win32.zip">
|
||||
</EmbeddedResource>
|
||||
<None Include="runtimes\osx\**" Pack="true" PackagePath="runtimes\osx\native" />
|
||||
<None Include="runtimes\unix\**" Pack="true" PackagePath="runtimes\unix\native" />
|
||||
<None Include="runtimes\win-x64\**" Pack="true" PackagePath="runtimes\win-x64\native" />
|
||||
<None Include="runtimes\win-x86\**" Pack="true" PackagePath="runtimes\win-x86\native" />
|
||||
<None Include="build\**" Pack="true" PackagePath="build" />
|
||||
</ItemGroup>
|
||||
<Target Name="Download Drivers" BeforeTargets="BeforeBuild">
|
||||
<Target Name="Download Drivers" BeforeTargets="Restore">
|
||||
<ConvertToAbsolutePath Paths="$(ProjectDir)..\tools\DriverDownloader\">
|
||||
<Output TaskParameter="AbsolutePaths" PropertyName="DriverDownloaderPath" />
|
||||
</ConvertToAbsolutePath>
|
||||
<ConvertToAbsolutePath Paths="$(ProjectDir)\Drivers\">
|
||||
<ConvertToAbsolutePath Paths="$(ProjectDir)\runtimes\">
|
||||
<Output TaskParameter="AbsolutePaths" PropertyName="DriversPath" />
|
||||
</ConvertToAbsolutePath>
|
||||
<Exec WorkingDirectory="$(DriverDownloaderPath)" Command="dotnet run -p DriverDownloader.csproj -- $(DriversPath) $(DriverVersion)" />
|
||||
</Target>
|
||||
</Project>
|
||||
<ItemGroup Condition="$([MSBuild]::IsOSPlatform('Windows'))">
|
||||
<ContentWithTargetPath Include="runtimes\win-x64\*.*">
|
||||
<TargetPath>%(Filename)%(Extension)</TargetPath>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</ContentWithTargetPath>
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="$([MSBuild]::IsOSPlatform('OSX'))">
|
||||
<ContentWithTargetPath Include="runtimes\osx\*.*">
|
||||
<TargetPath>%(Filename)%(Extension)</TargetPath>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</ContentWithTargetPath>
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="$([MSBuild]::IsOSPlatform('Linux'))">
|
||||
<ContentWithTargetPath Include="runtimes\unix\*.*">
|
||||
<TargetPath>%(Filename)%(Extension)</TargetPath>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</ContentWithTargetPath>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -2,7 +2,6 @@ using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text.Json;
|
||||
@@ -11,8 +10,6 @@ using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PlaywrightSharp.Chromium;
|
||||
using PlaywrightSharp.Helpers;
|
||||
using PlaywrightSharp.Helpers.Linux;
|
||||
using PlaywrightSharp.Transport;
|
||||
using PlaywrightSharp.Transport.Channels;
|
||||
using PlaywrightSharp.Transport.Converters;
|
||||
using PlaywrightSharp.Transport.Protocol;
|
||||
@@ -38,15 +35,9 @@ namespace PlaywrightSharp.Transport
|
||||
public Connection(
|
||||
ILoggerFactory loggerFactory,
|
||||
TransportTaskScheduler scheduler,
|
||||
string driversLocationPath = null,
|
||||
string driverExecutablePath = null,
|
||||
string browsersPath = null)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(driverExecutablePath) && !string.IsNullOrEmpty(driversLocationPath))
|
||||
{
|
||||
throw new ArgumentException("Passing a driver executable path and a driver location path is not allowed");
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(browsersPath))
|
||||
{
|
||||
Environment.SetEnvironmentVariable(BrowsersPathEnvironmentVariable, Path.GetFullPath(browsersPath));
|
||||
@@ -58,7 +49,7 @@ namespace PlaywrightSharp.Transport
|
||||
|
||||
_rootObject = new ChannelOwnerBase(null, this, string.Empty);
|
||||
|
||||
_playwrightServerProcess = GetProcess(driversLocationPath, driverExecutablePath);
|
||||
_playwrightServerProcess = GetProcess(driverExecutablePath);
|
||||
_playwrightServerProcess.StartInfo.Arguments = "run-driver";
|
||||
_playwrightServerProcess.Start();
|
||||
_playwrightServerProcess.Exited += (sender, e) => Close("Process exited");
|
||||
@@ -101,45 +92,6 @@ namespace PlaywrightSharp.Transport
|
||||
await tcs.Task.ConfigureAwait(false);
|
||||
}
|
||||
|
||||
internal static string InstallDriver(string driversPath)
|
||||
{
|
||||
if (string.IsNullOrEmpty(driversPath) && !string.IsNullOrEmpty(Environment.GetEnvironmentVariable(DriverPathEnvironmentVariable)))
|
||||
{
|
||||
driversPath = Environment.GetEnvironmentVariable(DriverPathEnvironmentVariable);
|
||||
}
|
||||
|
||||
var assembly = typeof(Playwright).Assembly;
|
||||
string tempDirectory = new FileInfo(assembly.Location).Directory.FullName;
|
||||
driversPath ??= Path.Combine(tempDirectory, "playwright-sharp-drivers");
|
||||
string platform = "win32";
|
||||
string driver = "playwright-cli-win32.zip";
|
||||
string executableFile = "playwright-cli.exe";
|
||||
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && RuntimeInformation.OSArchitecture == Architecture.X64)
|
||||
{
|
||||
platform = "win32_x64";
|
||||
driver = "playwright-cli-win32_x64.zip";
|
||||
}
|
||||
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||
{
|
||||
platform = "macos";
|
||||
driver = "playwright-cli-mac.zip";
|
||||
executableFile = "playwright-cli";
|
||||
}
|
||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
{
|
||||
platform = "linux";
|
||||
driver = "playwright-cli-linux.zip";
|
||||
executableFile = "playwright-cli";
|
||||
}
|
||||
|
||||
string directory = Path.Combine(driversPath, assembly.GetName().Version.ToString(), platform);
|
||||
string file = Path.Combine(directory, driver);
|
||||
ExtractDriver(file, driver);
|
||||
return Path.Combine(directory, executableFile);
|
||||
}
|
||||
|
||||
internal void RemoveObject(string guid) => Objects.TryRemove(guid, out _);
|
||||
|
||||
internal Task<JsonElement?> SendMessageToServer(
|
||||
@@ -265,12 +217,12 @@ namespace PlaywrightSharp.Transport
|
||||
}
|
||||
}
|
||||
|
||||
private static Process GetProcess(string driversLocationPath = null, string driverExecutablePath = null)
|
||||
private static Process GetProcess(string driverExecutablePath = null)
|
||||
=> new Process
|
||||
{
|
||||
StartInfo =
|
||||
{
|
||||
FileName = string.IsNullOrEmpty(driverExecutablePath) ? GetExecutablePath(driversLocationPath) : driverExecutablePath,
|
||||
FileName = string.IsNullOrEmpty(driverExecutablePath) ? GetExecutablePath() : driverExecutablePath,
|
||||
UseShellExecute = false,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardInput = true,
|
||||
@@ -279,41 +231,59 @@ namespace PlaywrightSharp.Transport
|
||||
},
|
||||
};
|
||||
|
||||
private static string GetExecutablePath(string driversPath = null)
|
||||
private static string GetExecutablePath()
|
||||
{
|
||||
if (string.IsNullOrEmpty(driversPath) && !string.IsNullOrEmpty(Environment.GetEnvironmentVariable(DriverPathEnvironmentVariable)))
|
||||
string driversPath;
|
||||
|
||||
if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable(DriverPathEnvironmentVariable)))
|
||||
{
|
||||
driversPath = Environment.GetEnvironmentVariable(DriverPathEnvironmentVariable);
|
||||
}
|
||||
|
||||
return InstallDriver(driversPath);
|
||||
}
|
||||
|
||||
private static void ExtractDriver(string file, string driver)
|
||||
{
|
||||
var directory = new FileInfo(file).Directory;
|
||||
|
||||
if (!directory.Exists)
|
||||
else
|
||||
{
|
||||
Directory.CreateDirectory(directory.FullName);
|
||||
var assembly = typeof(Playwright).Assembly;
|
||||
driversPath = new FileInfo(assembly.Location).Directory.FullName;
|
||||
}
|
||||
|
||||
using (var resource = typeof(Playwright).Assembly.GetManifestResourceStream($"PlaywrightSharp.Drivers.{driver}"))
|
||||
using (var zipStream = new ZipArchive(resource))
|
||||
{
|
||||
zipStream.ExtractToDirectory(directory.FullName);
|
||||
}
|
||||
string executableFile = Path.Combine(driversPath, "playwright-cli.exe");
|
||||
|
||||
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) || RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
{
|
||||
executableFile = Path.Combine(driversPath, "playwright-cli");
|
||||
}
|
||||
|
||||
if (!new FileInfo(executableFile).Exists)
|
||||
{
|
||||
string binPath = executableFile;
|
||||
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
foreach (var executable in directory.GetFiles().Where(f => f.Name == "playwright-cli" || f.Name.Contains("ffmpeg")))
|
||||
if (RuntimeInformation.OSArchitecture == Architecture.X64)
|
||||
{
|
||||
if (LinuxSysCall.Chmod(executable.FullName, LinuxSysCall.ExecutableFilePermissions) != 0)
|
||||
{
|
||||
throw new PlaywrightSharpException($"Unable to chmod the driver ({Marshal.GetLastWin32Error()})");
|
||||
}
|
||||
executableFile = Path.Combine(driversPath, "runtimes", "win-x64", "native", "playwright-cli.exe");
|
||||
}
|
||||
else
|
||||
{
|
||||
executableFile = Path.Combine(driversPath, "runtimes", "win-x86", "native", "playwright-cli.exe");
|
||||
}
|
||||
}
|
||||
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||
{
|
||||
executableFile = Path.Combine(driversPath, "runtimes", "osx", "native", "playwright-cli");
|
||||
}
|
||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
{
|
||||
executableFile = Path.Combine(driversPath, "runtimes", "unix", "native", "playwright-cli");
|
||||
}
|
||||
|
||||
if (!new FileInfo(executableFile).Exists)
|
||||
{
|
||||
throw new PlaywrightSharpException($"Driver not found neither at '{executableFile}', nor '{binPath}'");
|
||||
}
|
||||
}
|
||||
|
||||
return executableFile;
|
||||
}
|
||||
|
||||
private void Transport_MessageReceived(object sender, MessageReceivedEventArgs e)
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<!--
|
||||
NuGet packages.config doesn't support native assemblies automatically,
|
||||
so copy the native assemblies to the output directory.
|
||||
-->
|
||||
<ItemGroup Condition="Exists('packages.config') OR Exists('$(MSBuildProjectName).packages.config') OR Exists('packages.$(MSBuildProjectName).config')">
|
||||
<Content Include="$(MSBuildThisFileDirectory)\..\..\runtimes\win-x64\native\*.*" Condition="'$(PlatformTarget)' != 'x86'">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<Visible>false</Visible>
|
||||
<Link>%(Filename)%(Extension)</Link>
|
||||
</Content>
|
||||
<Content Include="$(MSBuildThisFileDirectory)\..\..\runtimes\win-x86\native\*.*" Condition="'$(PlatformTarget)' == 'x86'">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<Visible>false</Visible>
|
||||
<Link>%(Filename)%(Extension)</Link>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<NativeFolder Condition="'$(BuildFromSource)' == 'True'">
|
||||
</NativeFolder>
|
||||
<NativeFolder Condition="'$(BuildFromSource)' != 'True'">\native</NativeFolder>
|
||||
</PropertyGroup>
|
||||
<Target Name="InstallBrowsers" AfterTargets="CopyFilesToOutputDirectory">
|
||||
<Message Text="Playwright is checking browser dependencies">
|
||||
</Message>
|
||||
<Exec Condition="$([MSBuild]::IsOSPlatform('Linux'))" WorkingDirectory="$(MSBuildThisFileDirectory)..\..\runtimes\unix$(NativeFolder)" Command="./playwright-cli install" />
|
||||
<Exec Condition="$([MSBuild]::IsOSPlatform('OSX'))" WorkingDirectory="$(MSBuildThisFileDirectory)..\..\runtimes\osx$(NativeFolder)" Command="./playwright-cli install" />
|
||||
<Exec Condition="'$(PlatformTarget)' != 'x86' AND $([MSBuild]::IsOSPlatform('Windows'))" WorkingDirectory="$(MSBuildThisFileDirectory)\..\..\runtimes\win-x64$(NativeFolder)" Command="playwright-cli.exe install" />
|
||||
<Exec Condition="'$(PlatformTarget)' == 'x86' AND $([MSBuild]::IsOSPlatform('Windows'))" WorkingDirectory="$(MSBuildThisFileDirectory)\..\..\runtimes\win-x89$(NativeFolder)" Command="playwright-cli.exe install" />
|
||||
</Target>
|
||||
</Project>
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
using System;
|
||||
|
||||
namespace PlaywrightSharp.Helpers.Linux
|
||||
namespace DriverDownloader.Linux
|
||||
{
|
||||
[Flags]
|
||||
internal enum FileAccessPermissions : uint
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace PlaywrightSharp.Helpers.Linux
|
||||
namespace DriverDownloader.Linux
|
||||
{
|
||||
internal static class LinuxSysCall
|
||||
{
|
||||
@@ -1,13 +1,25 @@
|
||||
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.Threading.Tasks;
|
||||
using DriverDownloader.Linux;
|
||||
|
||||
namespace DriverDownloader
|
||||
{
|
||||
class Program
|
||||
{
|
||||
private static readonly (string Platform, string Runtime)[] _platforms = new[]
|
||||
{
|
||||
("mac", "osx"),
|
||||
("linux", "unix"),
|
||||
("win32_x64", "win-x64"),
|
||||
("win32", "win-x86")
|
||||
};
|
||||
|
||||
static async Task Main(string[] args)
|
||||
{
|
||||
if (args.Length < 2)
|
||||
@@ -35,9 +47,9 @@ namespace DriverDownloader
|
||||
|
||||
versionFile.CreateText();
|
||||
var tasks = new List<Task>();
|
||||
foreach (string platform in new[] { "mac", "linux", "win32_x64", "win32" })
|
||||
foreach (var platform in _platforms)
|
||||
{
|
||||
tasks.Add(DownloadDriverAsync(destinationDirectory, driverVersion, platform));
|
||||
tasks.Add(DownloadDriverAsync(destinationDirectory, driverVersion, platform.Platform, platform.Runtime));
|
||||
}
|
||||
|
||||
await Task.WhenAll(tasks);
|
||||
@@ -48,7 +60,7 @@ namespace DriverDownloader
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task DownloadDriverAsync(DirectoryInfo destinationDirectory, string driverVersion, string platform)
|
||||
private static async Task DownloadDriverAsync(DirectoryInfo destinationDirectory, string driverVersion, string platform, string runtime)
|
||||
{
|
||||
Console.WriteLine("Downloading driver for " + platform);
|
||||
const string cdn = "https://playwright.azureedge.net/builds/cli";
|
||||
@@ -61,8 +73,19 @@ namespace DriverDownloader
|
||||
return;
|
||||
}
|
||||
|
||||
using var fs = new FileStream(Path.Combine(destinationDirectory.FullName, $"playwright-cli-{platform}.zip"), FileMode.CreateNew);
|
||||
await response.Content.CopyToAsync(fs);
|
||||
var directory = new DirectoryInfo(Path.Combine(destinationDirectory.FullName, runtime));
|
||||
new ZipArchive(await response.Content.ReadAsStreamAsync()).ExtractToDirectory(directory.FullName);
|
||||
|
||||
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
foreach (var executable in directory.GetFiles().Where(f => f.Name == "playwright-cli" || f.Name.Contains("ffmpeg")))
|
||||
{
|
||||
if (LinuxSysCall.Chmod(executable.FullName, LinuxSysCall.ExecutableFilePermissions) != 0)
|
||||
{
|
||||
throw new Exception($"Unable to chmod the driver ({Marshal.GetLastWin32Error()})");
|
||||
}
|
||||
}
|
||||
}
|
||||
Console.WriteLine($"Driver for {platform} downloaded");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
using System;
|
||||
using CommandLine;
|
||||
|
||||
namespace PlaywrightSharpTool.Options
|
||||
{
|
||||
[Verb("install-all", HelpText = "Install the playwright driver and the required browsers. Pass --driverpath to specify the driver location and --browserpath to specify the location of the browsers.")]
|
||||
public class InstallAllOptions
|
||||
{
|
||||
[Option(Required = false, HelpText = "Browsers destination path. If not passed, the default shared location will be used.")]
|
||||
public string DriverPath { get; set; }
|
||||
|
||||
[Option(Required = false, HelpText = "Driver destination path. If not passed, CWD will be used.")]
|
||||
public string BrowsersPath { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
using System;
|
||||
using CommandLine;
|
||||
|
||||
namespace PlaywrightSharpTool.Options
|
||||
{
|
||||
[Verb("install-driver", HelpText = "Install the playwright driver. Pass --path to specify the driver location.")]
|
||||
public class InstallDriverOptions
|
||||
{
|
||||
[Option(Required = false, HelpText = "Driver destination path. If not passed, CWD will be used.")]
|
||||
public string Path { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -10,27 +10,11 @@ namespace PlaywrightSharpTool
|
||||
{
|
||||
static Task Main(string[] args)
|
||||
{
|
||||
return Parser.Default.ParseArguments<InstallBrowsersOptions, InstallDriverOptions, InstallAllOptions>(args).MapResult(
|
||||
return Parser.Default.ParseArguments<InstallBrowsersOptions>(args).MapResult(
|
||||
async (InstallBrowsersOptions opts) => await InstallAsync(opts),
|
||||
async (InstallDriverOptions opts) => await InstallDriverAsync(opts),
|
||||
async (InstallAllOptions opts) => await InstallAllDriverAsync(opts),
|
||||
_ => Task.FromResult<object>(null));
|
||||
}
|
||||
|
||||
private static async Task InstallAllDriverAsync(InstallAllOptions opts)
|
||||
{
|
||||
opts.DriverPath ??= ".";
|
||||
|
||||
Playwright.InstallDriver(opts.DriverPath);
|
||||
await Playwright.InstallAsync(opts.DriverPath, opts.BrowsersPath);
|
||||
}
|
||||
|
||||
private static Task InstallDriverAsync(InstallDriverOptions opts)
|
||||
{
|
||||
Playwright.InstallDriver(opts.Path ?? ".");
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private static Task InstallAsync(InstallBrowsersOptions opts) => Playwright.InstallAsync(browsersPath: opts.Path);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user