Skip to content
Permalink
Browse files

New Feature Page.BringToFrontAsync (#1235)

* New Feature Page.BringToFrontAsync

* Add test for BringToFrontAsync and fix summary
  • Loading branch information...
LucasMetal authored and kblok committed Jul 31, 2019
1 parent f59bb62 commit a9828a287a4e6c2cb4606f7e317282626530d54b
Showing with 31 additions and 0 deletions.
  1. +24 −0 lib/PuppeteerSharp.Tests/PuppeteerTests/HeadfulTests.cs
  2. +7 −0 lib/PuppeteerSharp/Page.cs
@@ -121,6 +121,30 @@ public async Task ShouldCloseBrowserWithBeforeunloadPage()
} }
} }


[Fact]
public async Task BringToFrontShouldWork()
{
using (var browserWithExtension = await Puppeteer.LaunchAsync(
TestConstants.BrowserWithExtensionOptions(),
TestConstants.LoggerFactory))
using (var page = await browserWithExtension.NewPageAsync())
{
await page.GoToAsync(TestConstants.EmptyPage);
Assert.Equal("visible", await page.EvaluateExpressionAsync<string>("document.visibilityState"));

var newPage = await browserWithExtension.NewPageAsync();
await newPage.GoToAsync(TestConstants.EmptyPage);
Assert.Equal("hidden", await page.EvaluateExpressionAsync<string>("document.visibilityState"));
Assert.Equal("visible", await newPage.EvaluateExpressionAsync<string>("document.visibilityState"));

await page.BringToFrontAsync();
Assert.Equal("visible", await page.EvaluateExpressionAsync<string>("document.visibilityState"));
Assert.Equal("hidden", await newPage.EvaluateExpressionAsync<string>("document.visibilityState"));

await newPage.CloseAsync();
}
}

private Task<Target> WaitForBackgroundPageTargetAsync(Browser browser) private Task<Target> WaitForBackgroundPageTargetAsync(Browser browser)
{ {
var target = browser.Targets().FirstOrDefault(t => t.Type == TargetType.BackgroundPage); var target = browser.Targets().FirstOrDefault(t => t.Type == TargetType.BackgroundPage);
@@ -1603,6 +1603,13 @@ public Task SetBurstModeOffAsync()


return Task.CompletedTask; return Task.CompletedTask;
} }

/// <summary>
/// Brings page to front (activates tab).
/// </summary>
/// <returns>A task that resolves when the message has been sent to Chromium.</returns>
public Task BringToFrontAsync() => Client.SendAsync("Page.bringToFront");

#endregion #endregion


internal void OnPopup(Page popupPage) => Popup?.Invoke(this, new PopupEventArgs { PopupPage = popupPage }); internal void OnPopup(Page popupPage) => Popup?.Invoke(this, new PopupEventArgs { PopupPage = popupPage });

0 comments on commit a9828a2

Please sign in to comment.
You can’t perform that action at this time.