From 34a0c787f022270b0ef2b96b48ce74df53713e16 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Tue, 10 Sep 2024 18:45:36 +0300 Subject: [PATCH] More examples --- ...ContextTest.BrowsingContextCreatedEvent.cs | 25 +++++++++ ...ntextTest.BrowsingContextDestroyedEvent.cs | 30 ++++++++++ ...gContextTest.BrowsingContextLoadedEvent.cs | 27 +++++++++ ...owsingContextTest.DomContentLoadedEvent.cs | 27 +++++++++ ...wsingContextTest.FragmentNavigatedEvent.cs | 28 ++++++++++ ...wsingContextTest.NavigationStartedEvent.cs | 23 ++++++++ .../BrowsingContextTest.UserPromptEvent.cs | 55 +++++++++++++++++++ 7 files changed, 215 insertions(+) create mode 100644 examples/dotnet/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.BrowsingContextCreatedEvent.cs create mode 100644 examples/dotnet/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.BrowsingContextDestroyedEvent.cs create mode 100644 examples/dotnet/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.BrowsingContextLoadedEvent.cs create mode 100644 examples/dotnet/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.DomContentLoadedEvent.cs create mode 100644 examples/dotnet/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.FragmentNavigatedEvent.cs create mode 100644 examples/dotnet/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.NavigationStartedEvent.cs create mode 100644 examples/dotnet/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.UserPromptEvent.cs diff --git a/examples/dotnet/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.BrowsingContextCreatedEvent.cs b/examples/dotnet/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.BrowsingContextCreatedEvent.cs new file mode 100644 index 000000000000..b46b1c3f3461 --- /dev/null +++ b/examples/dotnet/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.BrowsingContextCreatedEvent.cs @@ -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); + } +} diff --git a/examples/dotnet/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.BrowsingContextDestroyedEvent.cs b/examples/dotnet/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.BrowsingContextDestroyedEvent.cs new file mode 100644 index 000000000000..133abf6e8a64 --- /dev/null +++ b/examples/dotnet/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.BrowsingContextDestroyedEvent.cs @@ -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 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); + } +} diff --git a/examples/dotnet/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.BrowsingContextLoadedEvent.cs b/examples/dotnet/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.BrowsingContextLoadedEvent.cs new file mode 100644 index 000000000000..3d7ec3b0a56b --- /dev/null +++ b/examples/dotnet/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.BrowsingContextLoadedEvent.cs @@ -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 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); + } +} diff --git a/examples/dotnet/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.DomContentLoadedEvent.cs b/examples/dotnet/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.DomContentLoadedEvent.cs new file mode 100644 index 000000000000..b11770925e18 --- /dev/null +++ b/examples/dotnet/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.DomContentLoadedEvent.cs @@ -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 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); + } +} diff --git a/examples/dotnet/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.FragmentNavigatedEvent.cs b/examples/dotnet/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.FragmentNavigatedEvent.cs new file mode 100644 index 000000000000..2d3dc7b35213 --- /dev/null +++ b/examples/dotnet/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.FragmentNavigatedEvent.cs @@ -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 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); + } +} diff --git a/examples/dotnet/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.NavigationStartedEvent.cs b/examples/dotnet/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.NavigationStartedEvent.cs new file mode 100644 index 000000000000..e5233824973f --- /dev/null +++ b/examples/dotnet/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.NavigationStartedEvent.cs @@ -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); + } +} diff --git a/examples/dotnet/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.UserPromptEvent.cs b/examples/dotnet/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.UserPromptEvent.cs new file mode 100644 index 000000000000..71fe4b13d4b3 --- /dev/null +++ b/examples/dotnet/SeleniumDocs/BiDi/BrowsingContext/BrowsingContextTest.UserPromptEvent.cs @@ -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 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 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); + } +}