-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[dotnet] Add examples for BiDi W3C Browsing Context #1940
Draft
nvborisenko
wants to merge
18
commits into
SeleniumHQ:trunk
Choose a base branch
from
nvborisenko:dotnet-bidi-browsingcontext
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
7d92ca5
Some tests for browsing context
nvborisenko 34a0c78
More examples
nvborisenko 2b3816b
Update BrowsingContextTest.FragmentNavigatedEvent.cs
nvborisenko d23ff62
Task completion source for events
nvborisenko a6b1e44
Add more
nvborisenko 2a8aa0b
Get tree
nvborisenko 1ba4589
Group events
nvborisenko 2e02cc2
Finish examples
nvborisenko cf93f36
Simplify browsing context
nvborisenko a108d99
Add example how to print 7.. pages
nvborisenko adda703
Simplify browsing context type
nvborisenko 12f9167
BiDi is exposed from browsing context
nvborisenko 0cd9dc3
Consistent AsBiDirectional naming
nvborisenko c3d85b9
Make it even shorter
nvborisenko 0e4bd13
Use stable selenium
nvborisenko 04704a1
Do no show that BiDi object is disposable
nvborisenko a5bf483
No sandbox to be able to print a page
nvborisenko 90aa4c1
Upgrade
nvborisenko 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 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
16 changes: 16 additions & 0 deletions
16
examples/dotnet/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.Activate.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,16 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using OpenQA.Selenium.BiDi; | ||
using System.Threading.Tasks; | ||
|
||
namespace SeleniumDocs.BiDi.BrowsingContext; | ||
|
||
partial class BrowsingContextTest | ||
{ | ||
[TestMethod] | ||
public async Task Activate() | ||
{ | ||
var context = await driver.AsBiDiContextAsync(); | ||
|
||
await context.ActivateAsync(); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
examples/dotnet/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.CaptureScreenshot.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,48 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using OpenQA.Selenium.BiDi; | ||
using OpenQA.Selenium.BiDi.Modules.BrowsingContext; | ||
using System.Threading.Tasks; | ||
|
||
namespace SeleniumDocs.BiDi.BrowsingContext; | ||
|
||
partial class BrowsingContextTest | ||
{ | ||
[TestMethod] | ||
public async Task CaptureScreenshot() | ||
{ | ||
var context = await driver.AsBiDiContextAsync(); | ||
|
||
var screenshot = await context.CaptureScreenshotAsync(); | ||
|
||
Assert.IsNotNull(screenshot); | ||
Assert.IsNotNull(screenshot.Data); | ||
Assert.IsNotNull(screenshot.ToByteArray()); | ||
} | ||
|
||
[TestMethod] | ||
public async Task CaptureViewportScreenshot() | ||
{ | ||
var context = await driver.AsBiDiContextAsync(); | ||
|
||
var screenshot = await context.CaptureScreenshotAsync(new() { Clip = new ClipRectangle.Box(5, 5, 10, 10) }); | ||
|
||
Assert.IsNotNull(screenshot); | ||
Assert.IsNotNull(screenshot.Data); | ||
} | ||
|
||
[TestMethod] | ||
public async Task CaptureElementScreenshot() | ||
{ | ||
var context = await driver.AsBiDiContextAsync(); | ||
|
||
driver.Url = "https://www.selenium.dev/selenium/web/formPage.html"; | ||
|
||
var element = (await context.LocateNodesAsync(new Locator.Css("#checky")))[0]; | ||
|
||
//TODO: ShareId is a type, not string | ||
var screenshot = await context.CaptureScreenshotAsync(new() { Clip = new ClipRectangle.Element(new(element.SharedId)) }); | ||
|
||
Assert.IsNotNull(screenshot); | ||
Assert.IsNotNull(screenshot.Data); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
examples/dotnet/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.Close.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,29 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using OpenQA.Selenium.BiDi; | ||
using OpenQA.Selenium.BiDi.Modules.BrowsingContext; | ||
using System.Threading.Tasks; | ||
|
||
namespace SeleniumDocs.BiDi.BrowsingContext; | ||
|
||
partial class BrowsingContextTest | ||
{ | ||
[TestMethod] | ||
public async Task CloseTab() | ||
{ | ||
var bidi = await driver.AsBiDiAsync(); | ||
|
||
var context = await bidi.BrowsingContext.CreateAsync(ContextType.Tab); | ||
|
||
await context.CloseAsync(); | ||
} | ||
|
||
[TestMethod] | ||
public async Task CloseWindow() | ||
{ | ||
var bidi = await driver.AsBiDiAsync(); | ||
|
||
var context = await bidi.BrowsingContext.CreateAsync(ContextType.Window); | ||
|
||
await context.CloseAsync(); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
examples/dotnet/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.Create.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,57 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using OpenQA.Selenium.BiDi; | ||
using OpenQA.Selenium.BiDi.Modules.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); | ||
|
||
Assert.IsNotNull(context); | ||
} | ||
|
||
[TestMethod] | ||
public async Task OpenNewWindow() | ||
{ | ||
var bidi = await driver.AsBiDiAsync(); | ||
|
||
var context = await bidi.BrowsingContext.CreateAsync(ContextType.Window); | ||
|
||
Assert.IsNotNull(context); | ||
} | ||
|
||
[TestMethod] | ||
public async Task OpenTabWithReferenceBrowsingContext() | ||
{ | ||
var context1 = await driver.AsBiDiContextAsync(); | ||
|
||
var context2 = await context1.BiDi.BrowsingContext.CreateAsync(ContextType.Tab, new() { ReferenceContext = context1 }); | ||
|
||
Assert.IsNotNull(context2); | ||
} | ||
|
||
[TestMethod] | ||
public async Task OpenWindowWithReferenceBrowsingContext() | ||
{ | ||
var context1 = await driver.AsBiDiContextAsync(); | ||
|
||
var context2 = await context1.BiDi.BrowsingContext.CreateAsync(ContextType.Window, new() { ReferenceContext = context1 }); | ||
|
||
Assert.IsNotNull(context2); | ||
} | ||
|
||
[TestMethod] | ||
public async Task UseExistingWindowHandle() | ||
{ | ||
var context = await driver.AsBiDiContextAsync(); | ||
|
||
Assert.IsNotNull(context); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...net/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.Event.BrowsingContextCreated.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,27 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using OpenQA.Selenium.BiDi; | ||
using OpenQA.Selenium.BiDi.Modules.BrowsingContext; | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace SeleniumDocs.BiDi.BrowsingContext; | ||
|
||
partial class BrowsingContextTest | ||
{ | ||
[TestMethod] | ||
public async Task BrowsingContextCreatedEvent() | ||
{ | ||
var bidi = await driver.AsBiDiAsync(); | ||
|
||
TaskCompletionSource<BrowsingContextInfo> tcs = new(); | ||
|
||
await bidi.BrowsingContext.OnContextCreatedAsync(tcs.SetResult); | ||
|
||
driver.SwitchTo().NewWindow(OpenQA.Selenium.WindowType.Window); | ||
|
||
var info = await tcs.Task.WaitAsync(TimeSpan.FromSeconds(5)); | ||
|
||
Assert.IsNotNull(info); | ||
Console.WriteLine(info); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...t/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.Event.BrowsingContextDestroyed.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,30 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using OpenQA.Selenium.BiDi; | ||
using OpenQA.Selenium.BiDi.Modules.BrowsingContext; | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace SeleniumDocs.BiDi.BrowsingContext; | ||
|
||
partial class BrowsingContextTest | ||
{ | ||
[TestMethod] | ||
public async Task BrowsingContextDestroyedEvent() | ||
{ | ||
var bidi = await driver.AsBiDiAsync(); | ||
|
||
var context = await driver.AsBiDiContextAsync(); | ||
|
||
TaskCompletionSource<BrowsingContextInfo> tcs = new(); | ||
|
||
await bidi.BrowsingContext.OnContextDestroyedAsync(tcs.SetResult); | ||
|
||
await context.CloseAsync(); | ||
|
||
var contextInfo = await tcs.Task.WaitAsync(TimeSpan.FromSeconds(5)); | ||
|
||
Assert.IsNotNull(contextInfo); | ||
Assert.AreEqual(context, contextInfo.Context); | ||
Console.WriteLine(contextInfo); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...tnet/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.Event.BrowsingContextLoaded.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,27 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using OpenQA.Selenium.BiDi; | ||
using OpenQA.Selenium.BiDi.Modules.BrowsingContext; | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace SeleniumDocs.BiDi.BrowsingContext; | ||
|
||
partial class BrowsingContextTest | ||
{ | ||
[TestMethod] | ||
public async Task BrowsingContextLoadedEvent() | ||
{ | ||
var context = await driver.AsBiDiContextAsync(); | ||
|
||
TaskCompletionSource<NavigationInfo> tcs = new(); | ||
|
||
await context.OnLoadAsync(tcs.SetResult); | ||
|
||
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); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...es/dotnet/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.Event.DomContentLoaded.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,27 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using OpenQA.Selenium.BiDi; | ||
using OpenQA.Selenium.BiDi.Modules.BrowsingContext; | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace SeleniumDocs.BiDi.BrowsingContext; | ||
|
||
partial class BrowsingContextTest | ||
{ | ||
[TestMethod] | ||
public async Task DomContentLoadedEvent() | ||
{ | ||
var context = await driver.AsBiDiContextAsync(); | ||
|
||
TaskCompletionSource<NavigationInfo> tcs = new(); | ||
|
||
await context.OnDomContentLoadedAsync(tcs.SetResult); | ||
|
||
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); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...s/dotnet/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.Event.FragmentNavigated.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,29 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using OpenQA.Selenium.BiDi; | ||
using OpenQA.Selenium.BiDi.Modules.BrowsingContext; | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace SeleniumDocs.BiDi.BrowsingContext; | ||
|
||
partial class BrowsingContextTest | ||
{ | ||
[TestMethod] | ||
public async Task FragmentNavigatedEvent() | ||
{ | ||
var context = await driver.AsBiDiContextAsync(); | ||
|
||
await context.NavigateAsync("https://www.selenium.dev/selenium/web/linked_image.html", new() { Wait = ReadinessState.Complete }); | ||
|
||
TaskCompletionSource<NavigationInfo> tcs = new(); | ||
|
||
await context.OnFragmentNavigatedAsync(tcs.SetResult); | ||
|
||
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); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...s/dotnet/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.Event.NavigationStarted.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,26 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using OpenQA.Selenium.BiDi; | ||
using OpenQA.Selenium.BiDi.Modules.BrowsingContext; | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace SeleniumDocs.BiDi.BrowsingContext; | ||
|
||
partial class BrowsingContextTest | ||
{ | ||
[TestMethod] | ||
public async Task NavigationStartedEvent() | ||
{ | ||
var context = await driver.AsBiDiContextAsync(); | ||
|
||
TaskCompletionSource<NavigationInfo> tcs = new(); | ||
|
||
await context.OnNavigationStartedAsync(tcs.SetResult); | ||
|
||
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); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
examples/dotnet/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.Event.UserPrompt.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,53 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using OpenQA.Selenium; | ||
using OpenQA.Selenium.BiDi; | ||
using OpenQA.Selenium.BiDi.Modules.BrowsingContext; | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace SeleniumDocs.BiDi.BrowsingContext; | ||
|
||
partial class BrowsingContextTest | ||
{ | ||
[TestMethod] | ||
public async Task UserPromptOpenedEvent() | ||
{ | ||
var context = await driver.AsBiDiContextAsync(); | ||
|
||
TaskCompletionSource<UserPromptOpenedEventArgs> tcs = new(); | ||
|
||
await context.NavigateAsync("https://www.selenium.dev/selenium/web/alerts.html", new() { Wait = ReadinessState.Complete }); | ||
|
||
//TODO; THhis event can be a part of context | ||
await context.BiDi.BrowsingContext.OnUserPromptOpenedAsync(tcs.SetResult); | ||
|
||
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() | ||
{ | ||
var context = await driver.AsBiDiContextAsync(); | ||
|
||
TaskCompletionSource<UserPromptClosedEventArgs> tcs = new(); | ||
|
||
await context.NavigateAsync("https://www.selenium.dev/selenium/web/alerts.html", new() { Wait = ReadinessState.Complete }); | ||
|
||
//TODO; THhis event can be a part of context | ||
await context.BiDi.BrowsingContext.OnUserPromptClosedAsync(tcs.SetResult); | ||
|
||
driver.FindElement(By.Id("prompt")).Click(); | ||
|
||
//await context.HandleUserPromptAsync(); | ||
|
||
var userPromptClosedEventArgs = await tcs.Task.WaitAsync(TimeSpan.FromSeconds(5)); | ||
|
||
Assert.IsNotNull(userPromptClosedEventArgs); | ||
Console.WriteLine(userPromptClosedEventArgs); | ||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then we can implicitly convert
RemoteNodeValue
(if I remember correctly) toSharedId
.And moving forfard: