public async Task ShouldBeAbleToReconnectToADisconnectedBrowser() { using var browserApp = await Playwright.LaunchBrowserAppAsync(TestConstants.GetDefaultBrowserOptions()); using var browser = await Playwright.ConnectAsync(browserApp.ConnectOptions); string url = TestConstants.ServerUrl + "/frames/nested-frames.html"; var page = await browser.DefaultContext.NewPageAsync(); await page.GoToAsync(url); await browser.DisconnectAsync(); using var remote = await Playwright.ConnectAsync(browserApp.ConnectOptions); var pages = (await remote.DefaultContext.GetPagesAsync()).ToList(); var restoredPage = pages.FirstOrDefault(x => x.Url == url); Assert.NotNull(restoredPage); var frameDump = FrameUtils.DumpFrames(restoredPage.MainFrame); Assert.Equal(TestConstants.NestedFramesDumpResult, frameDump); int response = await restoredPage.EvaluateAsync <int>("7 * 8"); Assert.Equal(56, response); await remote.DisconnectAsync(); }
public async Task ShouldBeAbleToCloseRemoteBrowser() { using var browserApp = await Playwright.LaunchBrowserAppAsync(TestConstants.GetDefaultBrowserOptions()); using var remote = await Playwright.ConnectAsync(browserApp.ConnectOptions); var closeTask = new TaskCompletionSource <bool>(); browserApp.Closed += (sender, e) => closeTask.TrySetResult(true); await Task.WhenAll(remote.CloseAsync(), closeTask.Task); }
/// <inheritdoc cref="IAsyncLifetime.InitializeAsync"/> public override async Task InitializeAsync() { await base.InitializeAsync(); _controlledBrowser = await Playwright.LaunchBrowserAppAsync(TestConstants.GetDefaultBrowserOptions()); await Page.GoToAsync(TestConstants.ServerUrl + "/test/assets/playwrightweb.html"); await Page.EvaluateAsync( "(product, connectOptions) => setup(product, connectOptions)", TestConstants.Product.ToLower(), _controlledBrowser.ConnectOptions); }
public async Task ShouldSetTheBrowserConnectedState() { var browserApp = await Playwright.LaunchBrowserAppAsync(TestConstants.GetDefaultBrowserOptions()); var remote = await Playwright.ConnectAsync(new ConnectOptions { BrowserWSEndpoint = browserApp.WebSocketEndpoint }); Assert.True(remote.IsConnected); await remote.DisconnectAsync(); Assert.False(remote.IsConnected); }
public async Task ShouldFireDisconnectedWhenClosingWithWebSocket() { var options = TestConstants.GetDefaultBrowserOptions(); using var browserApp = await Playwright.LaunchBrowserAppAsync(options); using var browser = await Playwright.ConnectAsync(browserApp.ConnectOptions); var disconnectedTask = new TaskCompletionSource <bool>(); browser.Disconnected += (sender, e) => disconnectedTask.TrySetResult(true); browserApp.Kill(); await disconnectedTask.Task; }
public async Task ShouldThrowWhenTryingToConnectToNonExistingBrowser() { var options = TestConstants.DefaultBrowserOptions; var browserApp = await Playwright.LaunchBrowserAppAsync(options); var browserURL = GetBrowserUrl(browserApp.WebSocketEndpoint); await Assert.ThrowsAsync <PlaywrightSharpException>(() => Playwright.ConnectAsync(new ConnectOptions { BrowserURL = browserURL })); await browserApp.CloseAsync(); }
public async Task ShouldThrowIfUsedAfterDisconnect() { using var browserApp = await Playwright.LaunchBrowserAppAsync(TestConstants.GetDefaultBrowserOptions()); var remote = await Playwright.ConnectAsync(browserApp.ConnectOptions); var page = await remote.DefaultContext.NewPageAsync(); await remote.DisconnectAsync(); var exception = await Assert.ThrowsAnyAsync <PlaywrightSharpException>(() => page.EvaluateAsync("1 + 1")); Assert.Contains("has been closed", exception.Message); }
public async Task ShouldSupportTheWebSocketOption() { var options = TestConstants.GetDefaultBrowserOptions(); using var browserApp = await Playwright.LaunchBrowserAppAsync(options); using var browser = await Playwright.ConnectAsync(browserApp.ConnectOptions); Assert.Single(await browser.DefaultContext.GetPagesAsync()); Assert.NotNull(browserApp.WebSocketEndpoint); var page = await browser.DefaultContext.NewPageAsync(); Assert.Equal(121, await page.EvaluateAsync <int>("11 * 11")); }
public async Task ShouldThrowWhenUsingBothBrowserWSEndpointAndBrowserURL() { var options = TestConstants.GetDefaultBrowserOptions(); var browserApp = await Playwright.LaunchBrowserAppAsync(options); string browserURL = GetBrowserUrl(browserApp.WebSocketEndpoint); await Assert.ThrowsAsync <PlaywrightSharpException>(() => Playwright.ConnectAsync(new ConnectOptions { BrowserURL = browserURL, BrowserWSEndpoint = browserApp.WebSocketEndpoint })); await browserApp.CloseAsync(); }
public async Task ShouldSupportTheRemoteDebuggingPortArgument() { var options = TestConstants.GetDefaultBrowserOptions(); options.Args = new[] { "--remote-debugging-port=0" }; var browserApp = await Playwright.LaunchBrowserAppAsync(options); var browser = await Playwright.ConnectAsync(browserApp.ConnectOptions); Assert.NotNull(browserApp.WebSocketEndpoint); var page = await browser.DefaultContext.NewPageAsync(); Assert.Equal(121, await page.EvaluateAsync <int>("11 * 11")); await page.CloseAsync(); await browserApp.CloseAsync(); }
public async Task ShouldFilterOutIgnoredDefaultArguments() { string[] defaultArgsWithoutUserDataDir = Playwright.GetDefaultArgs(TestConstants.GetDefaultBrowserOptions()); var withUserDataDirOptions = TestConstants.GetDefaultBrowserOptions(); withUserDataDirOptions.UserDataDir = "fake-profile"; string[] defaultArgsWithUserDataDir = Playwright.GetDefaultArgs(withUserDataDirOptions); var launchOptions = TestConstants.GetDefaultBrowserOptions(); launchOptions.UserDataDir = "fake-profile"; launchOptions.IgnoreDefaultArgs = true; launchOptions.IgnoredDefaultArgs = defaultArgsWithUserDataDir.Where(x => !defaultArgsWithoutUserDataDir.Contains(x)).ToArray(); using var browserApp = await Playwright.LaunchBrowserAppAsync(launchOptions); Assert.DoesNotContain("fake-profile", browserApp.Process.StartInfo.Arguments); }
public async Task ShouldRejectWaitForSelectorWhenBrowserCloses() { Server.SetRoute("/empty.html", context => Task.Delay(10000)); using var browserApp = await Playwright.LaunchBrowserAppAsync(TestConstants.GetDefaultBrowserOptions()); var remote = await Playwright.ConnectAsync(browserApp.ConnectOptions); var page = await remote.DefaultContext.NewPageAsync(); var watchdog = page.WaitForSelectorAsync("div", new WaitForSelectorOptions { Timeout = 60000 }); await page.WaitForSelectorAsync("body"); await remote.DisconnectAsync(); await Assert.ThrowsAsync <TargetClosedException>(() => watchdog); }
public async Task ShouldRejectNavigationWhenBrowserCloses() { Server.SetRoute("/one-style.css", context => Task.Delay(10000)); using var browserApp = await Playwright.LaunchBrowserAppAsync(TestConstants.GetDefaultBrowserOptions()); var remote = await Playwright.ConnectAsync(browserApp.ConnectOptions); var page = await remote.DefaultContext.NewPageAsync(); var navigationTask = page.GoToAsync(TestConstants.ServerUrl + "/one-style.html", new GoToOptions { Timeout = 60000 }); await Server.WaitForRequest("/one-style.css"); await remote.DisconnectAsync(); await Assert.ThrowsAsync <NavigationException>(() => navigationTask); }
public async Task ShouldBeAbleToConnectUsingBrowserURLWithAndWithoutTrailingSlash() { var options = TestConstants.DefaultBrowserOptions; var browserApp = await Playwright.LaunchBrowserAppAsync(options); var browserURL = GetBrowserUrl(browserApp.WebSocketEndpoint); var browser1 = await Playwright.ConnectAsync(new ConnectOptions { BrowserURL = browserURL }); var page1 = await browser1.DefaultContext.NewPageAsync(); Assert.Equal(56, await page1.EvaluateAsync <int>("7 * 8")); await browser1.DisconnectAsync(); var browser2 = await Playwright.ConnectAsync(new ConnectOptions { BrowserURL = browserURL + "/" }); var page2 = await browser2.DefaultContext.NewPageAsync(); Assert.Equal(56, await page2.EvaluateAsync <int>("7 * 8")); await browser2.DisconnectAsync(); await browserApp.CloseAsync(); }
public async Task ShouldTerminateNetworkWaiters() { using var browserApp = await Playwright.LaunchBrowserAppAsync(TestConstants.GetDefaultBrowserOptions()); await using var remote = await Playwright.ConnectAsync(browserApp.ConnectOptions); var newPage = await remote.DefaultContext.NewPageAsync(); var requestTask = newPage.WaitForRequestAsync(TestConstants.EmptyPage); var responseTask = newPage.WaitForResponseAsync(TestConstants.EmptyPage); await browserApp.CloseAsync(); var exception = await Assert.ThrowsAsync <TargetClosedException>(() => requestTask); Assert.Contains("Target closed", exception.Message); Assert.DoesNotContain("Timeout", exception.Message); exception = await Assert.ThrowsAsync <TargetClosedException>(() => responseTask); Assert.Contains("Target closed", exception.Message); Assert.DoesNotContain("Timeout", exception.Message); }
public async Task ShouldThrowWhenUsedAfterIsConnectedReturnsFalse() { var browserApp = await Playwright.LaunchBrowserAppAsync(TestConstants.GetDefaultBrowserOptions()); var remote = await Playwright.ConnectAsync(new ConnectOptions { BrowserWSEndpoint = browserApp.WebSocketEndpoint }); var page = await remote.DefaultContext.NewPageAsync(); var disconnectedTask = new TaskCompletionSource <bool>(); remote.Disconnected += (sender, e) => disconnectedTask.TrySetResult(true); await Task.WhenAll(browserApp.CloseAsync(), disconnectedTask.Task); Assert.False(remote.IsConnected); var exception = await Assert.ThrowsAnyAsync <PlaywrightSharpException>(() => page.EvaluateAsync("1 + 1")); Assert.Contains("has been closed", exception.Message); }
private async Task <IBrowserApp> TestSignal(Action <Process> killAction) { var browserClosedTcs = new TaskCompletionSource <bool>(); var processExitedTcs = new TaskCompletionSource <bool>(); var browserApp = await Playwright.LaunchBrowserAppAsync(); browserApp.Process.Exited += (sender, e) => processExitedTcs.TrySetResult(true); var browser = await Playwright.ConnectAsync(new ConnectOptions { BrowserWSEndpoint = browserApp.WebSocketEndpoint }); browser.Disconnected += (sender, e) => { browserClosedTcs.SetResult(true); }; killAction(browserApp.Process); await Task.WhenAll(browserClosedTcs.Task, processExitedTcs.Task); return(browserApp); }
public async Task ShouldReturnChildProcessInstance() { using var browserApp = await Playwright.LaunchBrowserAppAsync(TestConstants.GetDefaultBrowserOptions()); Assert.True(browserApp.Process.Id > 0); }