I'm using Playwright 1.25.0 with Visual Studio Enterprise 2022 on Win 10 x64 to run the following test:
[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"));
}
This throws the following exception:
Test method PlaywrightTests.PlaywrightTests.LoadPlaywrightPage threw exception: Microsoft.Playwright.PlaywrightException: Browser closed. ==================== Browser output: ==================== 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-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] Opening in existing browser session. =========================== logs =========================== 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-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] Opening in existing browser session. ============================================================ at Microsoft.Playwright.Transport.Connection.InnerSendMessageToServerAsync[T](String guid, String method, Object args) in //src/Playwright/Transport/Connection.cs:line 167 at Microsoft.Playwright.Transport.Connection.WrapApiCallAsync[T](Func`1 action, Boolean isInternal) at Microsoft.Playwright.Core.BrowserType.LaunchAsync(BrowserTypeLaunchOptions options) in //src/Playwright/Core/BrowserType.cs:line 61 at PlaywrightTests.PlaywrightTests.LoadPlaywrightPage() in C:\MyProjects\PlaywrightPlayground\PlaywrightTests\PlaywrightTests.cs:line 115 at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.ThreadOperations.ExecuteWithAbortSafety(Action action)
It also throws the above error when trying to use any "stock browser" (browsers on my pc, not the binaries provided with Playwright). I'm following the guidance provided on the Playwright site to use the Channel
setting to indicate which browser to launch.
What am I doing wrong? Thanks.
CodePudding user response:
Found the issue: I was running Visual Studio without admin privileges. Once I chose, "Run as administrator", the local MS Edge launched and the test succeeded. Apparently, Playwright needs elevated rights to launch the Channel
local browsers vs. its own binaries, at least on some setups.
I wish, though, that Playwright could launch the stock browsers without having to have elevated privs.