【发布时间】:2021-12-04 13:55:16
【问题描述】:
在我发布到 Azure 云后,我无法运行调用 playwright 测试的 azure 函数。
异常如下
Playwright Test or Playwright was just installed or updated.
║ ║ Please run the following command to download new browsers: ║ ║
║ ║ playwright install ║ ║
║ ║ <3 Playwright Team ║
问题是我不知道如何运行playwright install。
有一些remote build possibility,但文档没有包含详细信息。
所以我尝试关注
- 将chrome浏览器
%USERPROFILE%\AppData\Local\ms-playwright\chrome-win复制到项目文件夹中。 - 将 chrome-win 文件夹附加到项目中。
- 更新
.csproj,这样chrome浏览器就会在输出目录中并输出zip
<ItemGroup>
<Content Include="chrome-win\**">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
- 更新 playwright 中的可执行路径
await using var browser = await playwright.Chromium.LaunchAsync(new() { ExecutablePath = "chrome-win/chrome.exe"});
在本地,它运行良好。 Zip Deploy to Azure 也成功了。但是当Azure函数被触发时,它会抛出一些未知的异常
Result: Failure Exception: System.AggregateException: One or more errors occurred. (spawn UNKNOWN =========================== logs =========================== <launching> chrome-win/chrome.exe --disable-background-networking --enable-features=NetworkService,NetworkServiceInProcess --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=ImprovedCookieControls,LazyFrameLoading,GlobalMediaControls,DestroyProfileOnBrowserClose,MediaRouter --allow-pre-commit-input --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --disable-sync --force-color-profile=srgb --metrics-recording-only --no-first-run --enable-automation --password-store=basic --use-mock-keychain --no-service-autorun --user-data-dir=C:\local\Temp\playwright_chromiumdev_profile-rw44Ph --remote-debugging-pipe --headless --hide-scrollbars --mute-audio --blink-settings=primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4 --no-sandbox --no-startup-window ============================================================) ---> Microsoft.Playwright.PlaywrightException: spawn UNKNOWN
我只是不想相信,因为终端中的一行命令,我必须将所有内容重写为 JavaScript ????
是否可以切换到具有 .NET 编写的功能的 Linux 操作系统并使用通过npm install playwright 安装的浏览器? .NET 现在是跨平台的,所以它可以工作吗?
有人设法启动并运行它吗?
【问题讨论】:
-
@DeepDave-MT 谢谢,但我还没有找到解决方案。我还尝试了此处描述的解决方案mauricepeters.dev/2021/10/…,但它根本不起作用(未找到可执行文件),并且还尝试通过 FunctionContext
Path.GetDirectoryName(context.FunctionDefinition.PathToAssembly)传递绝对路径而不是相对路径,但它导致相同的spawn UNKNOWN错误。所以似乎找到了 chrome 可执行文件,但由于未知错误而执行失败。
标签: azure-functions playwright