-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[dotnet] Add examples for BiDi W3C Browsing Context #2735
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e5fdba8
[dotnet] Add examples for BiDi W3C Browsing Context
diemol 2cdf2b0
[dotnet] Reference BiDi Browsing Context C# examples in docs (all loc…
diemol 550631c
[dotnet] Address Qodo review findings on PR 2735
diemol 1d4d679
[dotnet] Clarify why UserPromptClosedEvent needs no explicit close
diemol 5976832
[dotnet] Make UserPromptClosedEvent's prompt close deterministic
diemol cb2c9ee
Merge branch 'trunk' into dotnet-bidi-browsingcontext-fixed
diemol cd561d6
[dotnet] Use a fresh subdirectory for FirefoxTest.SetProfileLocation
diemol 39ff8cb
[dotnet] Drop trailing separator from ProfileRoot, verify by director…
diemol File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
13 changes: 13 additions & 0 deletions
13
examples/dotnet/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.Activate.cs
This file contains hidden or 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,13 @@ | ||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace SeleniumDocs.BiDi.BrowsingContext; | ||
|
|
||
| partial class BrowsingContextTest | ||
|
diemol marked this conversation as resolved.
|
||
| { | ||
| [TestMethod] | ||
| public async Task Activate() | ||
| { | ||
| await context.ActivateAsync(); | ||
| } | ||
| } | ||
42 changes: 42 additions & 0 deletions
42
examples/dotnet/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.CaptureScreenshot.cs
This file contains hidden or 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,42 @@ | ||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
| using OpenQA.Selenium.BiDi.BrowsingContext; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace SeleniumDocs.BiDi.BrowsingContext; | ||
|
|
||
| partial class BrowsingContextTest | ||
| { | ||
| [TestMethod] | ||
| public async Task CaptureScreenshot() | ||
| { | ||
| var screenshot = await context.CaptureScreenshotAsync(); | ||
|
|
||
| Assert.IsNotNull(screenshot); | ||
| Assert.IsNotNull(screenshot.Data); | ||
| Assert.IsNotNull(screenshot.ToByteArray()); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public async Task CaptureViewportScreenshot() | ||
| { | ||
| var screenshot = await context.CaptureScreenshotAsync(new() { Clip = new BoxClipRectangle(5, 5, 10, 10) }); | ||
|
|
||
| Assert.IsNotNull(screenshot); | ||
| Assert.IsNotNull(screenshot.Data); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public async Task CaptureElementScreenshot() | ||
| { | ||
| driver.Url = "https://www.selenium.dev/selenium/web/formPage.html"; | ||
|
qodo-code-review[bot] marked this conversation as resolved.
|
||
|
|
||
| var nodes = (await context.LocateNodesAsync(new CssLocator("#checky"))).Nodes; | ||
|
|
||
| Assert.IsTrue(nodes.Length > 0, "Expected to locate #checky"); | ||
|
|
||
| var screenshot = await context.CaptureScreenshotAsync(new() { Clip = new ElementClipRectangle(nodes[0]) }); | ||
|
|
||
| Assert.IsNotNull(screenshot); | ||
| Assert.IsNotNull(screenshot.Data); | ||
| } | ||
| } | ||
24 changes: 24 additions & 0 deletions
24
examples/dotnet/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.Close.cs
This file contains hidden or 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,24 @@ | ||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
| using OpenQA.Selenium.BiDi.BrowsingContext; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace SeleniumDocs.BiDi.BrowsingContext; | ||
|
|
||
| partial class BrowsingContextTest | ||
| { | ||
| [TestMethod] | ||
| public async Task CloseTab() | ||
| { | ||
| var context = (await bidi.BrowsingContext.CreateAsync(ContextType.Tab)).Context; | ||
|
|
||
| await context.CloseAsync(); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public async Task CloseWindow() | ||
| { | ||
| var context = (await bidi.BrowsingContext.CreateAsync(ContextType.Window)).Context; | ||
|
|
||
| await context.CloseAsync(); | ||
| } | ||
| } |
57 changes: 57 additions & 0 deletions
57
examples/dotnet/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.Create.cs
This file contains hidden or 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,57 @@ | ||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
| using OpenQA.Selenium.BiDi; | ||
| using OpenQA.Selenium.BiDi.BrowsingContext; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace SeleniumDocs.BiDi.BrowsingContext; | ||
|
|
||
| partial class BrowsingContextTest | ||
| { | ||
| [TestMethod] | ||
| public async Task OpenNewTab() | ||
| { | ||
| var bidi = await driver.AsBiDiAsync(); | ||
|
|
||
| var context = (await bidi.BrowsingContext.CreateAsync(ContextType.Tab)).Context; | ||
|
|
||
| Assert.IsNotNull(context); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public async Task OpenNewWindow() | ||
| { | ||
| var bidi = await driver.AsBiDiAsync(); | ||
|
|
||
| var context = (await bidi.BrowsingContext.CreateAsync(ContextType.Window)).Context; | ||
|
|
||
| Assert.IsNotNull(context); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public async Task OpenTabWithReferenceBrowsingContext() | ||
| { | ||
| var context1 = context; | ||
|
|
||
| var context2 = (await context1.BiDi.BrowsingContext.CreateAsync(ContextType.Tab, new() { ReferenceContext = context1 })).Context; | ||
|
|
||
| Assert.IsNotNull(context2); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public async Task OpenWindowWithReferenceBrowsingContext() | ||
| { | ||
| var context1 = context; | ||
|
|
||
| var context2 = (await context1.BiDi.BrowsingContext.CreateAsync(ContextType.Window, new() { ReferenceContext = context1 })).Context; | ||
|
|
||
| Assert.IsNotNull(context2); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public async Task UseExistingWindowHandle() | ||
| { | ||
| var context = (await bidi.BrowsingContext.GetTreeAsync()).Contexts[0].Context; | ||
|
|
||
| Assert.IsNotNull(context); | ||
| } | ||
| } |
24 changes: 24 additions & 0 deletions
24
...net/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.Event.BrowsingContextCreated.cs
This file contains hidden or 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,24 @@ | ||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
| using OpenQA.Selenium.BiDi.BrowsingContext; | ||
| using System; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace SeleniumDocs.BiDi.BrowsingContext; | ||
|
|
||
| partial class BrowsingContextTest | ||
| { | ||
| [TestMethod] | ||
| public async Task BrowsingContextCreatedEvent() | ||
| { | ||
| TaskCompletionSource<ContextCreatedEventArgs> tcs = new(); | ||
|
|
||
| await bidi.BrowsingContext.ContextCreated.SubscribeAsync(args => tcs.TrySetResult(args)); | ||
|
|
||
| driver.SwitchTo().NewWindow(OpenQA.Selenium.WindowType.Window); | ||
|
|
||
| var info = await tcs.Task.WaitAsync(TimeSpan.FromSeconds(5)); | ||
|
|
||
| Assert.IsNotNull(info); | ||
| Console.WriteLine(info); | ||
| } | ||
| } |
25 changes: 25 additions & 0 deletions
25
...t/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.Event.BrowsingContextDestroyed.cs
This file contains hidden or 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,25 @@ | ||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
| using OpenQA.Selenium.BiDi.BrowsingContext; | ||
| using System; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace SeleniumDocs.BiDi.BrowsingContext; | ||
|
|
||
| partial class BrowsingContextTest | ||
| { | ||
| [TestMethod] | ||
| public async Task BrowsingContextDestroyedEvent() | ||
| { | ||
| TaskCompletionSource<ContextDestroyedEventArgs> tcs = new(); | ||
|
|
||
| await bidi.BrowsingContext.ContextDestroyed.SubscribeAsync(args => tcs.TrySetResult(args)); | ||
|
diemol marked this conversation as resolved.
|
||
|
|
||
| await context.CloseAsync(); | ||
|
|
||
| var contextInfo = await tcs.Task.WaitAsync(TimeSpan.FromSeconds(5)); | ||
|
|
||
| Assert.IsNotNull(contextInfo); | ||
| Assert.AreEqual(context, contextInfo.Context); | ||
| Console.WriteLine(contextInfo); | ||
| } | ||
| } | ||
24 changes: 24 additions & 0 deletions
24
...tnet/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.Event.BrowsingContextLoaded.cs
This file contains hidden or 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,24 @@ | ||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
| using OpenQA.Selenium.BiDi.BrowsingContext; | ||
| using System; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace SeleniumDocs.BiDi.BrowsingContext; | ||
|
|
||
| partial class BrowsingContextTest | ||
| { | ||
| [TestMethod] | ||
| public async Task BrowsingContextLoadedEvent() | ||
| { | ||
| TaskCompletionSource<LoadEventArgs> tcs = new(); | ||
|
|
||
| await context.Load.SubscribeAsync(args => tcs.TrySetResult(args)); | ||
|
|
||
| await context.NavigateAsync("https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html", new() { Wait = ReadinessState.Complete }); | ||
|
|
||
| var navigationInfo = await tcs.Task.WaitAsync(TimeSpan.FromSeconds(5)); | ||
|
|
||
| Assert.IsNotNull(navigationInfo); | ||
| Console.WriteLine(navigationInfo); | ||
| } | ||
| } |
24 changes: 24 additions & 0 deletions
24
...es/dotnet/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.Event.DomContentLoaded.cs
This file contains hidden or 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,24 @@ | ||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
| using OpenQA.Selenium.BiDi.BrowsingContext; | ||
| using System; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace SeleniumDocs.BiDi.BrowsingContext; | ||
|
|
||
| partial class BrowsingContextTest | ||
| { | ||
| [TestMethod] | ||
| public async Task DomContentLoadedEvent() | ||
| { | ||
| TaskCompletionSource<DomContentLoadedEventArgs> tcs = new(); | ||
|
|
||
| await context.DomContentLoaded.SubscribeAsync(args => tcs.TrySetResult(args)); | ||
|
|
||
| await context.NavigateAsync("https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html", new() { Wait = ReadinessState.Complete }); | ||
|
|
||
| var navigationInfo = await tcs.Task.WaitAsync(TimeSpan.FromSeconds(5)); | ||
|
|
||
| Assert.IsNotNull(navigationInfo); | ||
| Console.WriteLine(navigationInfo); | ||
| } | ||
| } |
26 changes: 26 additions & 0 deletions
26
...s/dotnet/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.Event.FragmentNavigated.cs
This file contains hidden or 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,26 @@ | ||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
| using OpenQA.Selenium.BiDi.BrowsingContext; | ||
| using System; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace SeleniumDocs.BiDi.BrowsingContext; | ||
|
|
||
| partial class BrowsingContextTest | ||
| { | ||
| [TestMethod] | ||
| public async Task FragmentNavigatedEvent() | ||
| { | ||
| await context.NavigateAsync("https://www.selenium.dev/selenium/web/linked_image.html", new() { Wait = ReadinessState.Complete }); | ||
|
|
||
| TaskCompletionSource<FragmentNavigatedEventArgs> tcs = new(); | ||
|
|
||
| await context.FragmentNavigated.SubscribeAsync(args => tcs.TrySetResult(args)); | ||
|
|
||
| await context.NavigateAsync("https://www.selenium.dev/selenium/web/linked_image.html#linkToAnchorOnThisPage", new() { Wait = ReadinessState.Complete }); | ||
|
|
||
| var navigationInfo = await tcs.Task.WaitAsync(TimeSpan.FromSeconds(5)); | ||
|
|
||
| Assert.IsNotNull(navigationInfo); | ||
| Console.WriteLine(navigationInfo); | ||
| } | ||
| } |
23 changes: 23 additions & 0 deletions
23
...s/dotnet/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.Event.NavigationStarted.cs
This file contains hidden or 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,23 @@ | ||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
| using OpenQA.Selenium.BiDi.BrowsingContext; | ||
| using System; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace SeleniumDocs.BiDi.BrowsingContext; | ||
|
|
||
| partial class BrowsingContextTest | ||
| { | ||
| [TestMethod] | ||
| public async Task NavigationStartedEvent() | ||
| { | ||
| TaskCompletionSource<NavigationStartedEventArgs> tcs = new(); | ||
|
qodo-code-review[bot] marked this conversation as resolved.
|
||
|
|
||
| await context.NavigationStarted.SubscribeAsync(args => tcs.TrySetResult(args)); | ||
|
|
||
| await context.NavigateAsync("https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html", new() { Wait = ReadinessState.Complete }); | ||
|
|
||
| var info = await tcs.Task.WaitAsync(TimeSpan.FromSeconds(5)); | ||
|
|
||
| Assert.IsNotNull(info); | ||
| } | ||
| } | ||
61 changes: 61 additions & 0 deletions
61
examples/dotnet/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.Event.UserPrompt.cs
This file contains hidden or 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,61 @@ | ||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
| using OpenQA.Selenium; | ||
| using OpenQA.Selenium.BiDi; | ||
| using OpenQA.Selenium.BiDi.BrowsingContext; | ||
| using System; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace SeleniumDocs.BiDi.BrowsingContext; | ||
|
|
||
| partial class BrowsingContextTest | ||
| { | ||
| [TestMethod] | ||
| public async Task UserPromptOpenedEvent() | ||
| { | ||
| TaskCompletionSource<UserPromptOpenedEventArgs> tcs = new(); | ||
|
|
||
| await context.NavigateAsync("https://www.selenium.dev/selenium/web/alerts.html", new() { Wait = ReadinessState.Complete }); | ||
|
|
||
| // TODO: this event can be a part of context | ||
| await bidi.BrowsingContext.UserPromptOpened.SubscribeAsync(args => tcs.TrySetResult(args)); | ||
|
|
||
| driver.FindElement(By.Id("prompt")).Click(); | ||
|
|
||
| var userPromptOpenedEventArgs = await tcs.Task.WaitAsync(TimeSpan.FromSeconds(5)); | ||
|
|
||
| Assert.IsNotNull(userPromptOpenedEventArgs); | ||
| Console.WriteLine(userPromptOpenedEventArgs); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public async Task UserPromptClosedEvent() | ||
|
qodo-code-review[bot] marked this conversation as resolved.
|
||
| { | ||
| TaskCompletionSource<UserPromptOpenedEventArgs> opened = new(); | ||
| TaskCompletionSource<UserPromptClosedEventArgs> closed = new(); | ||
|
|
||
| await context.NavigateAsync("https://www.selenium.dev/selenium/web/alerts.html", new() { Wait = ReadinessState.Complete }); | ||
|
|
||
| // TODO: these events can be a part of context | ||
| await bidi.BrowsingContext.UserPromptOpened.SubscribeAsync(args => opened.TrySetResult(args)); | ||
| await bidi.BrowsingContext.UserPromptClosed.SubscribeAsync(args => closed.TrySetResult(args)); | ||
|
|
||
| driver.FindElement(By.Id("prompt")).Click(); | ||
|
|
||
| await opened.Task.WaitAsync(TimeSpan.FromSeconds(5)); | ||
|
|
||
| try | ||
| { | ||
| // Chrome's default unhandled prompt behavior may already have closed the | ||
| // prompt by this point; tolerate that instead of treating it as a failure. | ||
| await context.HandleUserPromptAsync(new() { Accept = true }); | ||
| } | ||
| catch (BiDiException ex) when (ex.Message.Contains("no such alert")) | ||
| { | ||
| } | ||
|
|
||
| var userPromptClosedEventArgs = await closed.Task.WaitAsync(TimeSpan.FromSeconds(5)); | ||
|
|
||
| Assert.IsNotNull(userPromptClosedEventArgs); | ||
| Console.WriteLine(userPromptClosedEventArgs); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.