Skip to content

Commit

Permalink
More examples
Browse files Browse the repository at this point in the history
  • Loading branch information
nvborisenko committed Sep 10, 2024
1 parent 7d92ca5 commit 34a0c78
Show file tree
Hide file tree
Showing 7 changed files with 215 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
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()
{
await using var bidi = await driver.AsBidirectionalAsync();

BrowsingContextInfo info = null;

await bidi.OnBrowsingContextCreatedAsync(e => info = e);

driver.SwitchTo().NewWindow(OpenQA.Selenium.WindowType.Window);

Assert.IsNotNull(info);
Console.WriteLine(info);
}
}
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()
{
await using var bidi = await driver.AsBidirectionalAsync();

var browsingContext = await driver.AsBidirectionalContextAsync();

TaskCompletionSource<BrowsingContextInfo> tcs = new();

await bidi.OnBrowsingContextDestroyedAsync(tcs.SetResult);

await browsingContext.CloseAsync();

var browsingContextInfo = await tcs.Task.WaitAsync(TimeSpan.FromSeconds(5));

Assert.IsNotNull(browsingContextInfo);
Assert.AreEqual(browsingContext, browsingContextInfo.Context);
Console.WriteLine(browsingContextInfo);
}
}
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 browsingContext = await driver.AsBidirectionalContextAsync();

TaskCompletionSource<NavigationInfo> tcs = new();

await browsingContext.OnLoadAsync(tcs.SetResult);

await browsingContext.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);
}
}
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 browsingContext = await driver.AsBidirectionalContextAsync();

TaskCompletionSource<NavigationInfo> tcs = new();

await browsingContext.OnDomContentLoadedAsync(tcs.SetResult);

await browsingContext.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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium.BiDi;
using OpenQA.Selenium.BiDi.Modules.BrowsingContext;
using System;
using System.Threading;
using System.Threading.Tasks;

namespace SeleniumDocs.BiDi.BrowsingContext;

partial class BrowsingContextTest
{
[TestMethod]
public async Task FragmentNavigatedEvent()
{
var browsingContext = await driver.AsBidirectionalContextAsync();

TaskCompletionSource<NavigationInfo> tcs = new();

await browsingContext.OnFragmentNavigatedAsync(tcs.SetResult);

await browsingContext.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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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 NavigationStartedEvent()
{
var browsingContext = await driver.AsBidirectionalContextAsync();

NavigationInfo info = null;

await browsingContext.OnNavigationStartedAsync(e => info = e);

await browsingContext.NavigateAsync("https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html", new() { Wait = ReadinessState.Complete });

Assert.IsNotNull(info);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
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()
{
await using var bidi = await driver.AsBidirectionalAsync();

var browsingContext = await driver.AsBidirectionalContextAsync();

TaskCompletionSource<UserPromptOpenedEventArgs> tcs = new();

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

await bidi.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()
{
await using var bidi = await driver.AsBidirectionalAsync();

var browsingContext = await driver.AsBidirectionalContextAsync();

TaskCompletionSource<UserPromptClosedEventArgs> tcs = new();

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

await bidi.OnUserPromptClosedAsync(tcs.SetResult);

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

//await browsingContext.HandleUserPromptAsync();

var userPromptClosedEventArgs = await tcs.Task.WaitAsync(TimeSpan.FromSeconds(5));

Assert.IsNotNull(userPromptClosedEventArgs);
Console.WriteLine(userPromptClosedEventArgs);
}
}

0 comments on commit 34a0c78

Please sign in to comment.