Skip to content

Commit 12f9167

Browse files
committed
BiDi is exposed from browsing context
1 parent adda703 commit 12f9167

File tree

6 files changed

+12
-21
lines changed

6 files changed

+12
-21
lines changed
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using Microsoft.VisualStudio.TestTools.UnitTesting;
22
using OpenQA.Selenium.BiDi;
3-
using OpenQA.Selenium.BiDi.Modules.BrowsingContext;
43
using System.Threading.Tasks;
54

65
namespace SeleniumDocs.BiDi.BrowsingContext;
@@ -10,10 +9,8 @@ partial class BrowsingContextTest
109
[TestMethod]
1110
public async Task Activate()
1211
{
13-
await using var bidi = await driver.AsBidirectionalAsync();
12+
var context = await driver.AsBidirectionalContextAsync();
1413

15-
var tab = await bidi.CreateContextAsync(ContextType.Tab);
16-
17-
await tab.ActivateAsync();
14+
await context.ActivateAsync();
1815
}
1916
}

examples/dotnet/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.Create.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,19 @@ public async Task OpenNewWindow()
3030
[TestMethod]
3131
public async Task OpenTabWithReferenceBrowsingContext()
3232
{
33-
await using var bidi = await driver.AsBidirectionalAsync();
34-
3533
var context1 = await driver.AsBidirectionalContextAsync();
3634

37-
var context2 = await bidi.CreateContextAsync(ContextType.Tab, new() { ReferenceContext = context1 });
35+
var context2 = await context1.BiDi.CreateContextAsync(ContextType.Tab, new() { ReferenceContext = context1 });
3836

3937
Assert.IsNotNull(context2);
4038
}
4139

4240
[TestMethod]
4341
public async Task OpenWindowWithReferenceBrowsingContext()
4442
{
45-
await using var bidi = await driver.AsBidirectionalAsync();
46-
4743
var context1 = await driver.AsBidirectionalContextAsync();
4844

49-
var context2 = await bidi.CreateContextAsync(ContextType.Window, new() { ReferenceContext = context1 });
45+
var context2 = await context1.BiDi.CreateContextAsync(ContextType.Window, new() { ReferenceContext = context1 });
5046

5147
Assert.IsNotNull(context2);
5248
}

examples/dotnet/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.Event.UserPrompt.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@ partial class BrowsingContextTest
1212
[TestMethod]
1313
public async Task UserPromptOpenedEvent()
1414
{
15-
await using var bidi = await driver.AsBidirectionalAsync();
16-
1715
var context = await driver.AsBidirectionalContextAsync();
1816

1917
TaskCompletionSource<UserPromptOpenedEventArgs> tcs = new();
2018

2119
await context.NavigateAsync("https://www.selenium.dev/selenium/web/alerts.html", new() { Wait = ReadinessState.Complete });
2220

23-
await bidi.OnUserPromptOpenedAsync(tcs.SetResult);
21+
//TODO; THhis event can be a part of context
22+
await context.BiDi.OnUserPromptOpenedAsync(tcs.SetResult);
2423

2524
driver.FindElement(By.Id("prompt")).Click();
2625

@@ -33,15 +32,14 @@ public async Task UserPromptOpenedEvent()
3332
[TestMethod]
3433
public async Task UserPromptClosedEvent()
3534
{
36-
await using var bidi = await driver.AsBidirectionalAsync();
37-
3835
var context = await driver.AsBidirectionalContextAsync();
3936

4037
TaskCompletionSource<UserPromptClosedEventArgs> tcs = new();
4138

4239
await context.NavigateAsync("https://www.selenium.dev/selenium/web/alerts.html", new() { Wait = ReadinessState.Complete });
4340

44-
await bidi.OnUserPromptClosedAsync(tcs.SetResult);
41+
//TODO; THhis event can be a part of context
42+
await context.BiDi.OnUserPromptClosedAsync(tcs.SetResult);
4543

4644
driver.FindElement(By.Id("prompt")).Click();
4745

examples/dotnet/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.GetTree.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ public async Task GetAllTopLevelBrowingContexts()
3939
{
4040
await using var bidi = await driver.AsBidirectionalAsync();
4141

42-
var window2 = await bidi.CreateContextAsync(ContextType.Window);
42+
var window = await bidi.CreateContextAsync(ContextType.Window);
4343

4444
var contexts = await bidi.GetTreeAsync();
4545

4646
Assert.AreEqual(2, contexts.Count);
47-
Assert.AreEqual(contexts[1].Context, window2);
47+
Assert.AreEqual(contexts[1].Context, window);
4848
}
4949
}

examples/dotnet/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.SetViewport.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ public async Task SetViewport()
1111
{
1212
var context = await driver.AsBidirectionalContextAsync();
1313

14-
await context.SetViewportAsync(new() { Viewport = new(250, 300), DevicePixelRatio = 5 });
14+
await context.SetViewportAsync(new() { Viewport = new(Width: 250, Height: 300), DevicePixelRatio = 5 });
1515
}
1616
}

examples/dotnet/SeleniumDocs/SeleniumDocs.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<PackageReference Include="MSTest.TestAdapter" Version="3.5.2" />
1212
<PackageReference Include="MSTest.TestFramework" Version="3.5.2" />
1313
<PackageReference Include="Selenium.Support" Version="4.25.0-nightly202409150847" />
14-
<PackageReference Include="Selenium.WebDriver" Version="4.25.0-nightly202409150847" />
14+
<PackageReference Include="Selenium.WebDriver" Version="4.25.0-nightly202409150848" />
1515
</ItemGroup>
1616

1717
<ItemGroup>

0 commit comments

Comments
 (0)