-
-
Notifications
You must be signed in to change notification settings - Fork 447
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
159 additions
and
43 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
lib/PuppeteerSharp.Tests/BrowserTests/Events/DisconnectedTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace PuppeteerSharp.Tests.BrowserTests.Events | ||
{ | ||
[Collection("PuppeteerLoaderFixture collection")] | ||
public class DisconnectedTests : PuppeteerBaseTest | ||
{ | ||
[Fact] | ||
public async Task ShouldEmittedWhenBrowserGetsClosedDisconnectedOrUnderlyingWebsocketGetsClosed() | ||
{ | ||
var originalBrowser = await PuppeteerSharp.Puppeteer.LaunchAsync(TestConstants.DefaultBrowserOptions(), TestConstants.ChromiumRevision); | ||
var connectOptions = new ConnectOptions { BrowserWSEndpoint = originalBrowser.WebSocketEndpoint }; | ||
var remoteBrowser1 = await PuppeteerSharp.Puppeteer.ConnectAsync(connectOptions); | ||
var remoteBrowser2 = await PuppeteerSharp.Puppeteer.ConnectAsync(connectOptions); | ||
|
||
var disconnectedOriginal = 0; | ||
var disconnectedRemote1 = 0; | ||
var disconnectedRemote2 = 0; | ||
originalBrowser.Disconnected += (sender, e) => ++disconnectedOriginal; | ||
remoteBrowser1.Disconnected += (sender, e) => ++disconnectedRemote1; | ||
remoteBrowser2.Disconnected += (sender, e) => ++disconnectedRemote2; | ||
|
||
remoteBrowser2.Disconnect(); | ||
Assert.Equal(0, disconnectedOriginal); | ||
Assert.Equal(0, disconnectedRemote1); | ||
Assert.Equal(1, disconnectedRemote2); | ||
|
||
await originalBrowser.CloseAsync(); | ||
Assert.Equal(1, disconnectedOriginal); | ||
Assert.Equal(1, disconnectedRemote1); | ||
Assert.Equal(1, disconnectedRemote2); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace PuppeteerSharp.Tests.BrowserTests | ||
{ | ||
[Collection("PuppeteerLoaderFixture collection")] | ||
public class ProcessTests : PuppeteerBaseTest | ||
{ | ||
[Fact] | ||
public async Task ShouldReturnProcessInstance() | ||
{ | ||
var process = Browser.Process; | ||
Assert.True(process.Id > 0); | ||
var browserWSEndpoint = Browser.WebSocketEndpoint; | ||
var remoteBrowser = await PuppeteerSharp.Puppeteer.ConnectAsync( | ||
new ConnectOptions { BrowserWSEndpoint = browserWSEndpoint }); | ||
Assert.Null(remoteBrowser.Process); | ||
remoteBrowser.Disconnect(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace PuppeteerSharp.Tests.BrowserTests | ||
{ | ||
[Collection("PuppeteerLoaderFixture collection")] | ||
public class UserAgentTests : PuppeteerBaseTest | ||
{ | ||
[Fact] | ||
public async Task ShouldIncludeWebKit() | ||
{ | ||
var userAgent = await Browser.GetUserAgentAsync(); | ||
Assert.NotEmpty(userAgent); | ||
Assert.Contains("WebKit", userAgent); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace PuppeteerSharp.Tests.BrowserTests | ||
{ | ||
[Collection("PuppeteerLoaderFixture collection")] | ||
public class VersionTests : PuppeteerBaseTest | ||
{ | ||
[Fact] | ||
public async Task ShouldReturnWhetherWeAreInHeadless() | ||
{ | ||
var version = await Browser.GetVersionAsync(); | ||
Assert.NotEmpty(version); | ||
Assert.Equal(TestConstants.DefaultBrowserOptions().Headless, version.StartsWith("Headless")); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters