Skip to content

Commit 48df933

Browse files
kblokMeir017
authored andcommitted
New Browser.Target property (#702)
1 parent f764ff3 commit 48df933

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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 TargetTests : PuppeteerBrowserBaseTest
9+
{
10+
public TargetTests(ITestOutputHelper output) : base(output)
11+
{
12+
}
13+
14+
[Fact]
15+
public void ShouldReturnBrowserTarget()
16+
=> Assert.Equal(TargetType.Browser, Browser.Target.Type);
17+
}
18+
}

lib/PuppeteerSharp/Browser.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@ public Browser(
164164
/// <returns>An Array of all active targets</returns>
165165
public Target[] Targets() => TargetsMap.Values.Where(target => target.IsInitialized).ToArray();
166166

167+
/// <summary>
168+
/// A target associated with the browser.
169+
/// </summary>
170+
public Target Target => Targets().FirstOrDefault(t => t.Type == TargetType.Browser);
171+
167172
/// <summary>
168173
/// Creates a new incognito browser context. This won't share cookies/cache with other browser contexts.
169174
/// </summary>

0 commit comments

Comments
 (0)