我在 Win 10 x64 上使用 Playwright 1.25.0 和 Visual Studio Enterprise 2022 來運行以下測驗:
[TestMethod]
public async Task LoadPlaywrightPage()
{
var playwright = await Playwright.CreateAsync();
var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions
{
Headless = false,
Channel = "msedge"
});
var context = await browser.NewContextAsync();
var page = await context.NewPageAsync();
await page.GotoAsync("https://playwright.dev/dotnet/");
Assert.IsTrue((await page.TitleAsync()).Contains("Playwright .NET"));
}
這會引發以下例外:
測驗方法 PlaywrightTests.PlaywrightTests.LoadPlaywrightPage 拋出例外:Microsoft.Playwright.PlaywrightException:瀏覽器關閉。==================== 瀏覽器輸出:==================== C:\Program Files (x86 )\Microsoft\Edge\Application\msedge.exe --disable-field-trial-config --disable-background-networking --enable-features=NetworkService,NetworkServiceInProcess --disable-background-timer-throttling --disable-backgrounding -occluded-windows --disable-back-forward-cache --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,DialMediaRouteProvider,AcceptCHFrame,AutoExpandDetailsElement, CertificateTransparencyComponentUpdater,AvoidUnnecessaryBeforeUnloadCheckSync,Translate --allow-pre-commit-input --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-渲染器背景 --disable-sync --force-color-profile=srgb --metrics-recording-only --no-first-run --enable-automation --password-store=basic --use-mock-keychain --no-service-autorun --export-tagged-pdf --no-sandbox --user-data-dir=C:\Users\MyUserId\AppData\Local\Temp\1\playwright_chromiumdev_profile-XJmwuh --remote-debugging -pipe --no-startup-window pid=35316 [pid=35316][out] 在現有瀏覽器會話中打開。============================日志====================== ===== C:\Program Files (x86)\Microsoft\Edge\Application\msedge. 翻譯 --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 --export-tagged-pdf --no-sandbox --user-data-dir=C:\Users\MyUserId\AppData\Local\Temp\1\playwright_chromiumdev_profile-XJmwuh --remote-debugging-pipe -- no-startup-window pid=35316 [pid=35316][out] 在現有瀏覽器會話中打開。==================================================== ========== 在 Microsoft.Playwright.Transport.Connection.InnerSendMessageToServerAsync[T](String guid, String method, Object args) in / \Users\MyUserId\AppData\Local\Temp\1\playwright_chromiumdev_profile-XJmwuh --remote-debugging-pipe --no-startup-window pid=35316 [pid=35316][out] 在現有瀏覽器會話中打開。==================================================== ========== 在 Microsoft.Playwright.Transport.Connection.InnerSendMessageToServerAsync[T](String guid, String method, Object args) in / \Users\MyUserId\AppData\Local\Temp\1\playwright_chromiumdev_profile-XJmwuh --remote-debugging-pipe --no-startup-window pid=35316 [pid=35316][out] 在現有瀏覽器會話中打開。==================================================== ========== 在 Microsoft.Playwright.Transport.Connection.InnerSendMessageToServerAsync[T](String guid, String method, Object args) in //src/Playwright/Transport/Connection.cs:第 167 行 Microsoft.Playwright.Transport.Connection.WrapApiCallAsync[T](Func`1 action, Boolean isInternal) 在 Microsoft.Playwright.Core.BrowserType.LaunchAsync(BrowserTypeLaunchOptions options) / /src/Playwright/Core/BrowserType.cs:C:\MyProjects\PlaywrightPlayground\PlaywrightTests\PlaywrightTests.cs 中 PlaywrightTests.PlaywrightTests.LoadPlaywrightPage() 的第 61 行:Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.ThreadOperations 的第 115 行.ExecuteWithAbortSafety(動作動作)
嘗試使用任何“股票瀏覽器”(我電腦上的瀏覽器,而不是 Playwright 提供的二進制檔案)時,它也會引發上述錯誤。我按照Playwright 網站上提供的指南使用該Channel設定來指示要啟動的瀏覽器。
我究竟做錯了什么?謝謝。
uj5u.com熱心網友回復:
發現問題:我在沒有管理員權限的情況下運行 Visual Studio。一旦我選擇“以管理員身份運行”,本地 MS Edge 就會啟動并且測驗成功。顯然,Playwright 需要提升權限來啟動Channel本地瀏覽器而不是它自己的二進制檔案,至少在某些設定上是這樣。
不過,我希望 Playwright 可以在無需提升權限的情況下啟動股票瀏覽器。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/508660.html
上一篇:無法在設計器視圖中拖放或編輯VisualStudioCommunityEdition2022forASP.NETWebForms(C#)中的工具箱元素
