Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
148 changes: 148 additions & 0 deletions examples/dotnet/SeleniumDocs/BiDi/BrowsingContextTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.BiDi;
using OpenQA.Selenium.BiDi.Modules;

Check failure on line 7 in examples/dotnet/SeleniumDocs/BiDi/BrowsingContextTest.cs

View workflow job for this annotation

GitHub Actions / tests (macos, stable)

The type or namespace name 'Modules' does not exist in the namespace 'OpenQA.Selenium.BiDi' (are you missing an assembly reference?)

Check failure on line 7 in examples/dotnet/SeleniumDocs/BiDi/BrowsingContextTest.cs

View workflow job for this annotation

GitHub Actions / tests (macos, stable)

The type or namespace name 'Modules' does not exist in the namespace 'OpenQA.Selenium.BiDi' (are you missing an assembly reference?)

Check failure on line 7 in examples/dotnet/SeleniumDocs/BiDi/BrowsingContextTest.cs

View workflow job for this annotation

GitHub Actions / tests (ubuntu, stable)

The type or namespace name 'Modules' does not exist in the namespace 'OpenQA.Selenium.BiDi' (are you missing an assembly reference?)

Check failure on line 7 in examples/dotnet/SeleniumDocs/BiDi/BrowsingContextTest.cs

View workflow job for this annotation

GitHub Actions / tests (ubuntu, stable)

The type or namespace name 'Modules' does not exist in the namespace 'OpenQA.Selenium.BiDi' (are you missing an assembly reference?)

Check failure on line 7 in examples/dotnet/SeleniumDocs/BiDi/BrowsingContextTest.cs

View workflow job for this annotation

GitHub Actions / tests (ubuntu, nightly)

The type or namespace name 'Modules' does not exist in the namespace 'OpenQA.Selenium.BiDi' (are you missing an assembly reference?)

Check failure on line 7 in examples/dotnet/SeleniumDocs/BiDi/BrowsingContextTest.cs

View workflow job for this annotation

GitHub Actions / tests (ubuntu, nightly)

The type or namespace name 'Modules' does not exist in the namespace 'OpenQA.Selenium.BiDi' (are you missing an assembly reference?)

Check failure on line 7 in examples/dotnet/SeleniumDocs/BiDi/BrowsingContextTest.cs

View workflow job for this annotation

GitHub Actions / tests (windows, stable)

The type or namespace name 'Modules' does not exist in the namespace 'OpenQA.Selenium.BiDi' (are you missing an assembly reference?)

Check failure on line 7 in examples/dotnet/SeleniumDocs/BiDi/BrowsingContextTest.cs

View workflow job for this annotation

GitHub Actions / tests (windows, stable)

The type or namespace name 'Modules' does not exist in the namespace 'OpenQA.Selenium.BiDi' (are you missing an assembly reference?)

Check failure on line 7 in examples/dotnet/SeleniumDocs/BiDi/BrowsingContextTest.cs

View workflow job for this annotation

GitHub Actions / tests (windows, nightly)

The type or namespace name 'Modules' does not exist in the namespace 'OpenQA.Selenium.BiDi' (are you missing an assembly reference?)

Check failure on line 7 in examples/dotnet/SeleniumDocs/BiDi/BrowsingContextTest.cs

View workflow job for this annotation

GitHub Actions / tests (windows, nightly)

The type or namespace name 'Modules' does not exist in the namespace 'OpenQA.Selenium.BiDi' (are you missing an assembly reference?)

Check failure on line 7 in examples/dotnet/SeleniumDocs/BiDi/BrowsingContextTest.cs

View workflow job for this annotation

GitHub Actions / tests (macos, nightly)

The type or namespace name 'Modules' does not exist in the namespace 'OpenQA.Selenium.BiDi' (are you missing an assembly reference?)

Check failure on line 7 in examples/dotnet/SeleniumDocs/BiDi/BrowsingContextTest.cs

View workflow job for this annotation

GitHub Actions / tests (macos, nightly)

The type or namespace name 'Modules' does not exist in the namespace 'OpenQA.Selenium.BiDi' (are you missing an assembly reference?)
using OpenQA.Selenium.Support.UI;

namespace SeleniumDocs.BiDi.W3C
{
[TestClass]
public class BrowsingContextTest : BaseFirefoxTest
{
[TestMethod]
public void CreateBrowsingContextForGivenId()
{
string id = driver.CurrentWindowHandle;
var browsingContext = new BrowsingContext(driver, id);
Assert.AreEqual(id, browsingContext.Id);
}

[TestMethod]
public void CreateWindow()
{
var browsingContext = new BrowsingContext(driver, WindowType.Window);
Assert.IsNotNull(browsingContext.Id);
}

[TestMethod]
public void CreateTab()
{
var browsingContext = new BrowsingContext(driver, WindowType.Tab);
Assert.IsNotNull(browsingContext.Id);
}

[TestMethod]
public void NavigateToUrl()
{
var browsingContext = new BrowsingContext(driver, WindowType.Tab);

var navigationInfo = browsingContext.Navigate("https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html");

Assert.IsNotNull(browsingContext.Id);
Assert.IsNotNull(navigationInfo.NavigationId);
Assert.IsTrue(navigationInfo.Url.Contains("/bidi/logEntryAdded.html"));
}

[TestMethod]
public void NavigateToUrlWithReadinessState()
{
var browsingContext = new BrowsingContext(driver, WindowType.Tab);

var navigationInfo = browsingContext.Navigate(
"https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html",
ReadinessState.Complete
);

Assert.IsNotNull(browsingContext.Id);
Assert.IsNotNull(navigationInfo.NavigationId);
}

[TestMethod]
public void GetTreeWithChildren()
{
string referenceContextId = driver.CurrentWindowHandle;
var browsingContext = new BrowsingContext(driver, referenceContextId);

browsingContext.Navigate("https://www.selenium.dev/selenium/web/iframes.html");

var tree = browsingContext.GetTree();

Assert.IsNotNull(tree);
Assert.IsTrue(tree.Count > 0);
}

[TestMethod]
public void GetTreeWithDepth()
{
string referenceContextId = driver.CurrentWindowHandle;
var browsingContext = new BrowsingContext(driver, referenceContextId);

browsingContext.Navigate("https://www.selenium.dev/selenium/web/iframes.html");

var tree = browsingContext.GetTree(maxDepth: 1);

Assert.IsNotNull(tree);
}

[TestMethod]
public void GetAllTopLevelContexts()
{
var contexts = BrowsingContext.GetAllTopLevelContexts(driver);

Assert.IsTrue(contexts.Count > 0);
}

[TestMethod]
public void CloseWindow()
{
var browsingContext = new BrowsingContext(driver, WindowType.Window);

browsingContext.Close();
// If no exception, close was successful
}

[TestMethod]
public void CloseTab()
{
var browsingContext = new BrowsingContext(driver, WindowType.Tab);

browsingContext.Close();
// If no exception, close was successful
}

[TestMethod]
public void ActivateBrowsingContext()
{
var browsingContext = new BrowsingContext(driver, WindowType.Tab);

browsingContext.Activate();
// If no exception, activate was successful
}

[TestMethod]
public void ReloadBrowsingContext()
{
var browsingContext = new BrowsingContext(driver, WindowType.Tab);
browsingContext.Navigate("https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html");

var navigationInfo = browsingContext.Reload();

Assert.IsNotNull(navigationInfo);
}

[TestMethod]
public void PrintToPdf()
{
var browsingContext = new BrowsingContext(driver, driver.CurrentWindowHandle);
browsingContext.Navigate("https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html");

var pdfData = browsingContext.Print();

Assert.IsNotNull(pdfData);
Assert.IsTrue(pdfData.Length > 0);
}
}
}
97 changes: 97 additions & 0 deletions examples/dotnet/SeleniumDocs/BiDi/InputTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;

namespace SeleniumDocs.BiDi.W3C
{
[TestClass]
public class InputTest : BaseFirefoxTest
{
[TestMethod]
public void PerformKeyActions()
{
driver.Url = "https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html";

var input = driver.FindElement(By.Id("textInput"));

input.SendKeys("Hello World");

Assert.AreEqual("Hello World", input.GetAttribute("value"));
}

[TestMethod]
public void PerformMouseActions()
{
driver.Url = "https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html";

var button = driver.FindElement(By.Id("consoleLog"));

button.Click();

// Verify action occurred
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
Assert.IsNotNull(button);
}

[TestMethod]
public void DispatchKeyboardEvents()
{
driver.Url = "https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html";

var element = driver.FindElement(By.TagName("body"));

driver.ExecuteScript(@"
document.addEventListener('keydown', function(e) {
console.log('Key pressed: ' + e.key);
});
");

element.SendKeys("a");
}

[TestMethod]
public void DispatchMouseEvents()
{
driver.Url = "https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html";

var button = driver.FindElement(By.Id("consoleLog"));

driver.ExecuteScript(@"
arguments[0].addEventListener('mouseover', function(e) {
console.log('Mouse over');
});
", button);

button.Click();
}

[TestMethod]
public void DispatchTouchEvents()
{
driver.Url = "https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html";

var element = driver.FindElement(By.TagName("body"));

driver.ExecuteScript(@"
document.addEventListener('touchstart', function(e) {
console.log('Touch started');
});
");
}

[TestMethod]
public void DispatchWheelEvents()
{
driver.Url = "https://www.selenium.dev/selenium/web/iframes.html";

driver.ExecuteScript(@"
window.addEventListener('wheel', function(e) {
console.log('Wheel event');
});
");
}
}
}
108 changes: 108 additions & 0 deletions examples/dotnet/SeleniumDocs/BiDi/NetworkTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.BiDi;
using OpenQA.Selenium.Support.UI;

namespace SeleniumDocs.BiDi.W3C
{
[TestClass]
public class NetworkTest : BaseFirefoxTest
{
[TestMethod]
public void InterceptNetworkRequest()
{
driver.Url = "https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html";

// Network interception would require BiDi module subscription
// This demonstrates the concept
var requestsIntercepted = 0;

// Simulate network request
driver.Url = "https://www.selenium.dev/selenium/web/iframes.html";

Assert.IsTrue(requestsIntercepted >= 0);
}

[TestMethod]
public void InterceptNetworkResponse()
{
driver.Url = "https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html";

var responsesCaptured = new List<string>();

// Navigate to trigger responses
driver.Url = "https://www.selenium.dev/selenium/web/iframes.html";

// Verify navigation occurred
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
Assert.IsTrue(driver.Url.Contains("iframes.html"));
}

[TestMethod]
public void ContinueNetworkRequest()
{
driver.Url = "https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html";

// Continue request logic would be handled by BiDi module
driver.Url = "https://www.selenium.dev/selenium/web/iframes.html";
}

[TestMethod]
public void ProvideAuthCredentials()
{
driver.Url = "https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html";

// Auth handling would require BiDi module
// This is a conceptual example
var username = "user";
var password = "pass";

Assert.IsNotNull(username);
Assert.IsNotNull(password);
}

[TestMethod]
public void FailNetworkRequest()
{
driver.Url = "https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html";

// Request failure handling via BiDi
driver.Url = "https://www.selenium.dev/selenium/web/iframes.html";
}

[TestMethod]
public void InterceptFetchRequests()
{
driver.Url = "https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html";

var fetchCalls = 0;

driver.ExecuteAsyncScript(@"
var callback = arguments[arguments.length - 1];
fetch('https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html')
.then(() => callback(1))
.catch(() => callback(0));
");

Assert.IsTrue(fetchCalls >= 0);
}

[TestMethod]
public void InterceptXhrRequests()
{
driver.Url = "https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html";

driver.ExecuteAsyncScript(@"
var callback = arguments[arguments.length - 1];
var xhr = new XMLHttpRequest();
xhr.open('GET', 'https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html');
xhr.onload = function() { callback(1); };
xhr.onerror = function() { callback(0); };
xhr.send();
");
}
}
}
Loading
Loading