Skip to content

Commit d109124

Browse files
authored
Add Browser.IsConnected (#1131)
* Add Browser.IsConnected * Remove await
1 parent e215805 commit d109124

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System.Threading.Tasks;
2+
using Xunit;
3+
using Xunit.Abstractions;
4+
5+
namespace PuppeteerSharp.Tests.BrowserTests
6+
{
7+
[Collection("PuppeteerLoaderFixture collection")]
8+
public class IsConnectedTests : PuppeteerBrowserBaseTest
9+
{
10+
public IsConnectedTests(ITestOutputHelper output) : base(output)
11+
{
12+
}
13+
14+
[Fact]
15+
public async Task ShouldSetTheBrowserConnectedState()
16+
{
17+
var newBrowser = await Puppeteer.ConnectAsync(new ConnectOptions
18+
{
19+
BrowserWSEndpoint = Browser.WebSocketEndpoint
20+
});
21+
Assert.True(newBrowser.IsConnected);
22+
newBrowser.Disconnect();
23+
Assert.False(newBrowser.IsConnected);
24+
}
25+
}
26+
}

lib/PuppeteerSharp/Browser.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,10 @@ public bool IsClosed
165165
/// Dafault wait time in milliseconds. Defaults to 30 seconds.
166166
/// </summary>
167167
public int DefaultWaitForTimeout { get; set; } = Puppeteer.DefaultTimeout;
168-
168+
/// <summary>
169+
/// Indicates that the browser is connected.
170+
/// </summary>
171+
public bool IsConnected => !Connection.IsClosed;
169172
#endregion
170173

171174
#region Public Methods

0 commit comments

Comments
 (0)