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
// The below is pseudocode. | |
// mapperTab.js is the output of the build process from | |
// https://github.com/GoogleChromeLabs/chromium-bidi | |
string bidiMapperTabContent = getFileContent("/path/to/mapperTab.js"); | |
// WebSocket address is found by monitoring console output of | |
// executing Chrome, and parsing the "DevTools listening on ws://xxx" | |
string webSocketUrl = launchChrome(); |
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
namespace WebDriverBiDi.Client; | |
using System.Reflection; | |
/// <summary> | |
/// Delegate for asynchronously handling events. | |
/// </summary> | |
/// <typeparam name="T">The type of <see cref="EventArgs"/> object containing information about the event.</typeparam> | |
/// <param name="sender">The sender of the event. This argument is optional and may be <see langword="null"/>.</param> | |
/// <param name="eventArgs">The <see cref="EventArgs"/> object containing information about the event.</param> |
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
// Assume driver and element are properly defined and assigned elsewhere. | |
PointerInputDevice mouse = new PointerInputDevice(); | |
ActionBuilder builder = new ActionBuilder(); | |
builder.AddActions( | |
mouse.CreatePointerMove(element, 0, 0, TimeSpan.FromMilliseconds(100), | |
mouse.CreatePointerDown(MouseButton.Left), | |
mouse.CreatePointerMove(element, 100, 100, TimeSpan.FromMilliseconds(100), | |
mouse.CreatePointerUp(MouseButton.Left) | |
); | |
((IActionExecutor)driver).PerformActions(builder.ToActionSequence()); |
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
// N.B., this example is far more verbose than required to showcase | |
// the full statements required. Production code would not need to be | |
// this verbose. Execution of custom commands is usually accomplished | |
// by subclassing the base class and having custom methods to use | |
// the executor to call the custom commands. | |
// The name of the command should be unique among command names. | |
string commandName = "someArbitraryUniqueCommandName"; | |
// HttpCommandInfo can use either Get, Post, or Delete commands. The |
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
IWebDriver driver = new RemoteWebDriver(new Uri("http://localhost:4444"), new ChromeOptions()); | |
ICustomDriverCommandExecutor customCommandDriver = driver as ICustomDriverCommandExecutor; | |
customCommandDriver.RegisterCustomDriverCommands(ChromeDriver.CustomCommandDefinitions); | |
ChromiumNetworkConditions networkConditions = new ChromiumNetworkConditions(); | |
networkConditions.IsOffline = true; | |
Dictionary<string, Object> parameters = new Dictionary<string, object>(); | |
parameters.Add("network_conditions", networkConditions); | |
customCommandDriver.ExecuteCustomDriverCommand(ChromeDriver.SetNetworkConditionsCommand, parameters); |
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
public async Task LogNetworkRequests(IWebDriver driver) | |
{ | |
INetwork interceptor = driver.Manage().Network; | |
interceptor.NetworkRequestSent += OnNetworkRequestSent; | |
interceptor.NetworkResponseReceived += OnNetworkResponseReceived; | |
await interceptor.StartMonitoring(); | |
driver.Url = "http://the-internet.herokuapp.com/redirect"; | |
await interceptor.StopMonitoring(); | |
} |
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
List<DomMutationData> attributeValueChanges = new List<DomMutationData>(); | |
DefaultWait<List<DomMutationData>> wait = new DefaultWait<List<DomMutationData>>(attributeValueChanges); | |
wait.Timeout = TimeSpan.FromSeconds(3); | |
IJavaScriptEngine monitor = new JavaScriptEngine(driver); | |
monitor.DomMutated += (sender, e) => | |
{ | |
attributeValueChanges.Add(e.AttributeData); | |
}; | |
await monitor.StartEventMonitoring(); |
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
// File must contain the following using statements | |
using OpenQA.Selenium; | |
using OpenQA.Selenium.Chrome; | |
using OpenQA.Selenium.DevTools; | |
// We must use a version-specific set of domains | |
using OpenQA.Selenium.DevTools.V94.Performance; | |
public async Task PerformanceMetricsExample() | |
{ |
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
List<string> exceptionMessages = new List<string>(); | |
IJavaScriptEngine monitor = new JavaScriptEngine(driver); | |
monitor.JavaScriptExceptionThrown += (sender, e) => | |
{ | |
exceptionMessages.Add(e.Message); | |
}; | |
await monitor.StartEventMonitoring(); | |
driver.Navigate.GoToUrl("<your site url>"); |
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
IJavaScriptEngine monitor = new JavaScriptEngine(driver); | |
List<string> consoleMessages = new List<string>(); | |
monitor.JavaScriptConsoleApiCalled += (sender, e) => | |
{ | |
Console.WriteLine("Log: {0}", e.MessageContent); | |
}; | |
await monitor.StartEventMonitoring(); |
NewerOlder