From 201fad38296f9ea47ac1b1b59c160963dc7b2907 Mon Sep 17 00:00:00 2001 From: Jim Evans Date: Fri, 19 Nov 2021 15:15:38 -0500 Subject: [PATCH] [dotnet] Handle returning shadow roots from JavaScript --- common/src/web/shadowRootPage.html | 25 +++ dotnet/src/webdriver/ElementCoordinates.cs | 4 +- .../Interactions/PointerInputDevice.cs | 4 +- .../Interactions/WheelInputDevice.cs | 4 +- ...erence.cs => IWebDriverObjectReference.cs} | 8 +- dotnet/src/webdriver/ShadowRoot.cs | 33 +++- dotnet/src/webdriver/TargetLocator.cs | 6 +- dotnet/src/webdriver/WebDriver.cs | 16 +- dotnet/src/webdriver/WebElement.cs | 11 +- .../common/DevTools/DevToolsConsoleTest.cs | 4 +- .../test/common/DevTools/DevToolsLogTest.cs | 6 +- .../common/DevTools/DevToolsNetworkTest.cs | 144 +++++++++--------- .../DevTools/DevToolsPerformanceTest.cs | 30 ++-- .../common/DevTools/DevToolsProfilerTest.cs | 18 +-- .../common/DevTools/DevToolsSecurityTest.cs | 10 +- .../common/DevTools/DevToolsTargetTest.cs | 50 +++--- dotnet/test/common/DriverTestFixture.cs | 1 + dotnet/test/common/ShadowRootHandlingTest.cs | 58 +++++++ dotnet/test/common/appconfig.json | 2 +- 19 files changed, 277 insertions(+), 157 deletions(-) create mode 100644 common/src/web/shadowRootPage.html rename dotnet/src/webdriver/Internal/{IWebElementReference.cs => IWebDriverObjectReference.cs} (86%) create mode 100644 dotnet/test/common/ShadowRootHandlingTest.cs diff --git a/common/src/web/shadowRootPage.html b/common/src/web/shadowRootPage.html new file mode 100644 index 0000000000000..f832ac4ade6c8 --- /dev/null +++ b/common/src/web/shadowRootPage.html @@ -0,0 +1,25 @@ + + + +Shadow Root Page + + + +
+
+ + + diff --git a/dotnet/src/webdriver/ElementCoordinates.cs b/dotnet/src/webdriver/ElementCoordinates.cs index c71d18a4ce153..372f23c82c2fc 100644 --- a/dotnet/src/webdriver/ElementCoordinates.cs +++ b/dotnet/src/webdriver/ElementCoordinates.cs @@ -70,7 +70,7 @@ public object AuxiliaryLocator { get { - IWebElementReference elementReference = this.element as IWebElementReference; + IWebDriverObjectReference elementReference = this.element as IWebDriverObjectReference; if (elementReference == null) { return null; @@ -80,7 +80,7 @@ public object AuxiliaryLocator // uses the raw ID of the element, not an element reference. To use this, // extract the ID using the well-known key to the dictionary for element // references. - return elementReference.ElementReferenceId; + return elementReference.ObjectReferenceId; } } } diff --git a/dotnet/src/webdriver/Interactions/PointerInputDevice.cs b/dotnet/src/webdriver/Interactions/PointerInputDevice.cs index 3470a73788e83..f369913108688 100644 --- a/dotnet/src/webdriver/Interactions/PointerInputDevice.cs +++ b/dotnet/src/webdriver/Interactions/PointerInputDevice.cs @@ -521,13 +521,13 @@ public override string ToString() private Dictionary ConvertElement() { - IWebElementReference elementReference = this.target as IWebElementReference; + IWebDriverObjectReference elementReference = this.target as IWebDriverObjectReference; if (elementReference == null) { IWrapsElement elementWrapper = this.target as IWrapsElement; if (elementWrapper != null) { - elementReference = elementWrapper.WrappedElement as IWebElementReference; + elementReference = elementWrapper.WrappedElement as IWebDriverObjectReference; } } diff --git a/dotnet/src/webdriver/Interactions/WheelInputDevice.cs b/dotnet/src/webdriver/Interactions/WheelInputDevice.cs index 91fca0b0486ce..a4ab2ca067b39 100644 --- a/dotnet/src/webdriver/Interactions/WheelInputDevice.cs +++ b/dotnet/src/webdriver/Interactions/WheelInputDevice.cs @@ -178,13 +178,13 @@ public override Dictionary ToDictionary() private Dictionary ConvertElement() { - IWebElementReference elementReference = this.target as IWebElementReference; + IWebDriverObjectReference elementReference = this.target as IWebDriverObjectReference; if (elementReference == null) { IWrapsElement elementWrapper = this.target as IWrapsElement; if (elementWrapper != null) { - elementReference = elementWrapper.WrappedElement as IWebElementReference; + elementReference = elementWrapper.WrappedElement as IWebDriverObjectReference; } } diff --git a/dotnet/src/webdriver/Internal/IWebElementReference.cs b/dotnet/src/webdriver/Internal/IWebDriverObjectReference.cs similarity index 86% rename from dotnet/src/webdriver/Internal/IWebElementReference.cs rename to dotnet/src/webdriver/Internal/IWebDriverObjectReference.cs index 4ce603e32ab83..9bb2ba68a0f0c 100644 --- a/dotnet/src/webdriver/Internal/IWebElementReference.cs +++ b/dotnet/src/webdriver/Internal/IWebDriverObjectReference.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -26,12 +26,12 @@ namespace OpenQA.Selenium.Internal /// /// Defines the interface through which the framework can serialize an element to the wire protocol. /// - internal interface IWebElementReference + internal interface IWebDriverObjectReference { /// - /// Gets the internal ID of the element. + /// Gets the internal ID of the WebDriver object. /// - string ElementReferenceId { get; } + string ObjectReferenceId { get; } /// /// Converts an object into an object that represents an element for the wire protocol. diff --git a/dotnet/src/webdriver/ShadowRoot.cs b/dotnet/src/webdriver/ShadowRoot.cs index 9ec7f76ed3238..c0850b1b03307 100644 --- a/dotnet/src/webdriver/ShadowRoot.cs +++ b/dotnet/src/webdriver/ShadowRoot.cs @@ -19,13 +19,14 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using OpenQA.Selenium.Internal; namespace OpenQA.Selenium { /// /// Provides a representation of an element's shadow root. /// - public class ShadowRoot : ISearchContext, IWrapsDriver + public class ShadowRoot : ISearchContext, IWrapsDriver, IWebDriverObjectReference { /// /// The property name that represents an element shadow root in the wire protocol. @@ -54,6 +55,29 @@ public IWebDriver WrappedDriver get { return this.driver; } } + /// + /// Gets the internal ID for this ShadowRoot. + /// + string IWebDriverObjectReference.ObjectReferenceId + { + get { return this.shadowRootId; } + } + + internal static bool ContainsShadowRootReference(Dictionary shadowRootDictionary) + { + if (shadowRootDictionary == null) + { + throw new ArgumentNullException(nameof(shadowRootDictionary), "The dictionary containing the shadow root reference cannot be null"); + } + + return shadowRootDictionary.ContainsKey(ShadowRootReferencePropertyName); + } + + internal static ShadowRoot FromDictionary(WebDriver driver, Dictionary shadowRootDictionary) + { + return new ShadowRoot(driver, shadowRootDictionary[ShadowRoot.ShadowRootReferencePropertyName].ToString()); + } + /// /// Finds the first using the given method. /// @@ -96,5 +120,12 @@ public ReadOnlyCollection FindElements(By by) Response commandResponse = this.driver.InternalExecute(DriverCommand.FindShadowChildElements, parameters); return this.driver.GetElementsFromResponse(commandResponse); } + + Dictionary IWebDriverObjectReference.ToDictionary() + { + Dictionary shadowRootDictionary = new Dictionary(); + shadowRootDictionary.Add(ShadowRootReferencePropertyName, this.shadowRootId); + return shadowRootDictionary; + } } } diff --git a/dotnet/src/webdriver/TargetLocator.cs b/dotnet/src/webdriver/TargetLocator.cs index c63903866e61e..ed6e81e7df402 100644 --- a/dotnet/src/webdriver/TargetLocator.cs +++ b/dotnet/src/webdriver/TargetLocator.cs @@ -91,13 +91,13 @@ public IWebDriver Frame(IWebElement frameElement) throw new ArgumentNullException(nameof(frameElement), "Frame element cannot be null"); } - IWebElementReference elementReference = frameElement as IWebElementReference; + IWebDriverObjectReference elementReference = frameElement as IWebDriverObjectReference; if (elementReference == null) { IWrapsElement elementWrapper = frameElement as IWrapsElement; if (elementWrapper != null) { - elementReference = elementWrapper.WrappedElement as IWebElementReference; + elementReference = elementWrapper.WrappedElement as IWebDriverObjectReference; } } @@ -108,7 +108,7 @@ public IWebDriver Frame(IWebElement frameElement) // TODO: Remove "ELEMENT" addition when all remote ends are spec-compliant. Dictionary elementDictionary = elementReference.ToDictionary(); - elementDictionary.Add("ELEMENT", elementReference.ElementReferenceId); + elementDictionary.Add("ELEMENT", elementReference.ObjectReferenceId); Dictionary parameters = new Dictionary(); parameters.Add("id", elementDictionary); diff --git a/dotnet/src/webdriver/WebDriver.cs b/dotnet/src/webdriver/WebDriver.cs index 33e88d9969df5..140ba3ebbf39e 100644 --- a/dotnet/src/webdriver/WebDriver.cs +++ b/dotnet/src/webdriver/WebDriver.cs @@ -940,13 +940,13 @@ protected object ExecuteScriptCommand(string script, string commandName, params private static object ConvertObjectToJavaScriptObject(object arg) { IWrapsElement argAsWrapsElement = arg as IWrapsElement; - IWebElementReference argAsElementReference = arg as IWebElementReference; + IWebDriverObjectReference argAsObjectReference = arg as IWebDriverObjectReference; IEnumerable argAsEnumerable = arg as IEnumerable; IDictionary argAsDictionary = arg as IDictionary; - if (argAsElementReference == null && argAsWrapsElement != null) + if (argAsObjectReference == null && argAsWrapsElement != null) { - argAsElementReference = argAsWrapsElement.WrappedElement as IWebElementReference; + argAsObjectReference = argAsWrapsElement.WrappedElement as IWebDriverObjectReference; } object converted = null; @@ -955,11 +955,11 @@ private static object ConvertObjectToJavaScriptObject(object arg) { converted = arg; } - else if (argAsElementReference != null) + else if (argAsObjectReference != null) { // TODO: Remove "ELEMENT" addition when all remote ends are spec-compliant. - Dictionary elementDictionary = argAsElementReference.ToDictionary(); - converted = elementDictionary; + Dictionary webDriverObjectReferenceDictionary = argAsObjectReference.ToDictionary(); + converted = webDriverObjectReferenceDictionary; } else if (argAsDictionary != null) { @@ -1026,6 +1026,10 @@ private object ParseJavaScriptReturnValue(object responseValue) { returnValue = this.elementFactory.CreateElement(resultAsDictionary); } + else if (ShadowRoot.ContainsShadowRootReference(resultAsDictionary)) + { + returnValue = ShadowRoot.FromDictionary(this, resultAsDictionary); + } else { // Recurse through the dictionary, re-parsing each value. diff --git a/dotnet/src/webdriver/WebElement.cs b/dotnet/src/webdriver/WebElement.cs index 6b51907e62abb..fa8751e9b1fdb 100644 --- a/dotnet/src/webdriver/WebElement.cs +++ b/dotnet/src/webdriver/WebElement.cs @@ -29,7 +29,7 @@ namespace OpenQA.Selenium { - public class WebElement : IWebElement, IFindsElement, IWrapsDriver, ILocatable, ITakesScreenshot, IWebElementReference + public class WebElement : IWebElement, IFindsElement, IWrapsDriver, ILocatable, ITakesScreenshot, IWebDriverObjectReference { /// /// The property name that represents a web element in the wire protocol. @@ -250,7 +250,7 @@ public virtual ICoordinates Coordinates /// /// Gets the internal ID of the element. /// - string IWebElementReference.ElementReferenceId + string IWebDriverObjectReference.ObjectReferenceId { get { return this.elementId; } } @@ -695,7 +695,7 @@ public override bool Equals(object obj) return false; } - Dictionary IWebElementReference.ToDictionary() + Dictionary IWebDriverObjectReference.ToDictionary() { Dictionary elementDictionary = new Dictionary(); elementDictionary.Add(ElementReferencePropertyName, this.elementId); @@ -753,9 +753,10 @@ private string UploadFile(string localFile) throw new WebDriverException("Cannot upload " + localFile, e); } } - private IWebElementReference ToElementReference() + + private IWebDriverObjectReference ToElementReference() { - return this as IWebElementReference; + return this as IWebDriverObjectReference; } } } diff --git a/dotnet/test/common/DevTools/DevToolsConsoleTest.cs b/dotnet/test/common/DevTools/DevToolsConsoleTest.cs index 784c47305c5ca..5670a47c1453f 100644 --- a/dotnet/test/common/DevTools/DevToolsConsoleTest.cs +++ b/dotnet/test/common/DevTools/DevToolsConsoleTest.cs @@ -19,11 +19,11 @@ public class DevToolsConsoleTest : DevToolsTestFixture [IgnoreBrowser(Selenium.Browser.Safari, "Safari does not support Chrome DevTools Protocol")] public async Task VerifyMessageAdded() { - var domains = session.GetVersionSpecificDomains(); + var domains = session.GetVersionSpecificDomains(); string consoleMessage = "Hello Selenium"; ManualResetEventSlim sync = new ManualResetEventSlim(false); - EventHandler messageAddedHandler = (sender, e) => + EventHandler messageAddedHandler = (sender, e) => { Assert.That(e.Message.Text, Is.EqualTo(consoleMessage)); sync.Set(); diff --git a/dotnet/test/common/DevTools/DevToolsLogTest.cs b/dotnet/test/common/DevTools/DevToolsLogTest.cs index 502a2aa500bb1..e8ff93847db58 100644 --- a/dotnet/test/common/DevTools/DevToolsLogTest.cs +++ b/dotnet/test/common/DevTools/DevToolsLogTest.cs @@ -19,12 +19,12 @@ public class DevToolsLogTest : DevToolsTestFixture [IgnoreBrowser(Selenium.Browser.Safari, "Safari does not support Chrome DevTools Protocol")] public async Task VerifyEntryAddedAndClearLog() { - var domains = session.GetVersionSpecificDomains(); + var domains = session.GetVersionSpecificDomains(); ManualResetEventSlim sync = new ManualResetEventSlim(false); - EventHandler entryAddedHandler = (sender, e) => + EventHandler entryAddedHandler = (sender, e) => { Assert.That(e.Entry.Text.Contains("404")); - Assert.That(e.Entry.Level == V93.Log.LogEntryLevelValues.Error); + Assert.That(e.Entry.Level == V96.Log.LogEntryLevelValues.Error); sync.Set(); }; diff --git a/dotnet/test/common/DevTools/DevToolsNetworkTest.cs b/dotnet/test/common/DevTools/DevToolsNetworkTest.cs index f4d351d523a90..d10c77cce904c 100644 --- a/dotnet/test/common/DevTools/DevToolsNetworkTest.cs +++ b/dotnet/test/common/DevTools/DevToolsNetworkTest.cs @@ -21,8 +21,8 @@ public class DevToolsNetworkTest : DevToolsTestFixture [IgnoreBrowser(Selenium.Browser.Safari, "Safari does not support Chrome DevTools Protocol")] public void GetSetDeleteAndClearAllCookies() { - //var domains = session.GetVersionSpecificDomains(); - //await domains.Network.Enable(new V93.Network.EnableCommandSettings()); + //var domains = session.GetVersionSpecificDomains(); + //await domains.Network.Enable(new V96.Network.EnableCommandSettings()); //var allCookieResponse = await domains.Network.GetAllCookies(); //ReadOnlyCollection seleniumCookies = allCookieResponse.Cookies.ToSeleniumCookies(); @@ -37,11 +37,11 @@ public void GetSetDeleteAndClearAllCookies() //seleniumCookies = allCookieResponse.Cookies.ToSeleniumCookies(); //Assert.That(seleniumCookies.Count == 1); - //var cookieResponse = await domains.Network.GetCookies(new V93.Network.GetCookiesCommandSettings()); + //var cookieResponse = await domains.Network.GetCookies(new V96.Network.GetCookiesCommandSettings()); //seleniumCookies = cookieResponse.Cookies.ToSeleniumCookies(); //Assert.That(seleniumCookies.Count == 0); - //await domains.Network.DeleteCookies(new V93.Network.DeleteCookiesCommandSettings() + //await domains.Network.DeleteCookies(new V96.Network.DeleteCookiesCommandSettings() //{ // Name = "name", // Domain = EnvironmentManager.Instance.UrlBuilder.HostName, @@ -69,26 +69,26 @@ public void GetSetDeleteAndClearAllCookies() [IgnoreBrowser(Selenium.Browser.Safari, "Safari does not support Chrome DevTools Protocol")] public async Task SendRequestWithUrlFiltersAndExtraHeadersAndVerifyRequests() { - var domains = session.GetVersionSpecificDomains(); - await domains.Network.Enable(new V93.Network.EnableCommandSettings()); - await domains.Network.SetBlockedURLs(new V93.Network.SetBlockedURLsCommandSettings() + var domains = session.GetVersionSpecificDomains(); + await domains.Network.Enable(new V96.Network.EnableCommandSettings()); + await domains.Network.SetBlockedURLs(new V96.Network.SetBlockedURLsCommandSettings() { Urls = new string[] { "*://*/*.css" } }); - var additionalHeaders = new V93.Network.Headers(); + var additionalHeaders = new V96.Network.Headers(); additionalHeaders.Add("headerName", "headerValue"); - await domains.Network.SetExtraHTTPHeaders(new V93.Network.SetExtraHTTPHeadersCommandSettings() + await domains.Network.SetExtraHTTPHeaders(new V96.Network.SetExtraHTTPHeadersCommandSettings() { Headers = additionalHeaders }); ManualResetEventSlim loadingFailedSync = new ManualResetEventSlim(false); - EventHandler loadingFailedHandler = (sender, e) => + EventHandler loadingFailedHandler = (sender, e) => { - if (e.Type == V93.Network.ResourceType.Stylesheet) + if (e.Type == V96.Network.ResourceType.Stylesheet) { - Assert.That(e.BlockedReason == V93.Network.BlockedReason.Inspector); + Assert.That(e.BlockedReason == V96.Network.BlockedReason.Inspector); } loadingFailedSync.Set(); @@ -96,7 +96,7 @@ await domains.Network.SetExtraHTTPHeaders(new V93.Network.SetExtraHTTPHeadersCom domains.Network.LoadingFailed += loadingFailedHandler; ManualResetEventSlim requestSentSync = new ManualResetEventSlim(false); - EventHandler requestWillBeSentHandler = (sender, e) => + EventHandler requestWillBeSentHandler = (sender, e) => { Assert.That(e.Request.Headers.ContainsKey("headerName")); Assert.That(e.Request.Headers["headerName"] == "headerValue"); @@ -105,7 +105,7 @@ await domains.Network.SetExtraHTTPHeaders(new V93.Network.SetExtraHTTPHeadersCom domains.Network.RequestWillBeSent += requestWillBeSentHandler; ManualResetEventSlim dataSync = new ManualResetEventSlim(false); - EventHandler dataReceivedHandler = (sender, e) => + EventHandler dataReceivedHandler = (sender, e) => { Assert.That(e.RequestId, Is.Not.Null); dataSync.Set(); @@ -125,23 +125,23 @@ await domains.Network.SetExtraHTTPHeaders(new V93.Network.SetExtraHTTPHeadersCom [IgnoreBrowser(Selenium.Browser.Safari, "Safari does not support Chrome DevTools Protocol")] public async Task EmulateNetworkConditionOffline() { - var domains = session.GetVersionSpecificDomains(); - await domains.Network.Enable(new V93.Network.EnableCommandSettings() + var domains = session.GetVersionSpecificDomains(); + await domains.Network.Enable(new V96.Network.EnableCommandSettings() { MaxTotalBufferSize = 100000000 }); - await domains.Network.EmulateNetworkConditions(new V93.Network.EmulateNetworkConditionsCommandSettings() + await domains.Network.EmulateNetworkConditions(new V96.Network.EmulateNetworkConditionsCommandSettings() { Offline = true, Latency = 100, DownloadThroughput = 1000, UploadThroughput = 2000, - ConnectionType = V93.Network.ConnectionType.Cellular3g + ConnectionType = V96.Network.ConnectionType.Cellular3g }); ManualResetEventSlim loadingFailedSync = new ManualResetEventSlim(false); - EventHandler loadingFailedHandler = (sender, e) => + EventHandler loadingFailedHandler = (sender, e) => { Assert.That(e.ErrorText, Is.EqualTo("net::ERR_INTERNET_DISCONNECTED")); loadingFailedSync.Set(); @@ -159,16 +159,16 @@ await domains.Network.EmulateNetworkConditions(new V93.Network.EmulateNetworkCon [IgnoreBrowser(Selenium.Browser.Safari, "Safari does not support Chrome DevTools Protocol")] public async Task VerifyRequestReceivedFromCacheAndResponseBody() { - var domains = session.GetVersionSpecificDomains(); + var domains = session.GetVersionSpecificDomains(); string[] requestIdFromCache = new string[1]; - await domains.Network.Enable(new V93.Network.EnableCommandSettings() + await domains.Network.Enable(new V96.Network.EnableCommandSettings() { MaxResourceBufferSize = 100000000 }); ManualResetEventSlim servedFromCacheSync = new ManualResetEventSlim(false); - EventHandler requestServedFromCacheHandler = (sender, e) => + EventHandler requestServedFromCacheHandler = (sender, e) => { Assert.That(e.RequestId, Is.Not.Null); requestIdFromCache[0] = e.RequestId; @@ -177,7 +177,7 @@ await domains.Network.Enable(new V93.Network.EnableCommandSettings() domains.Network.RequestServedFromCache += requestServedFromCacheHandler; ManualResetEventSlim loadingFinishedSync = new ManualResetEventSlim(false); - EventHandler loadingFinishedHandler = (sender, e) => + EventHandler loadingFinishedHandler = (sender, e) => { Assert.That(e.RequestId, Is.Not.Null); loadingFinishedSync.Set(); @@ -189,7 +189,7 @@ await domains.Network.Enable(new V93.Network.EnableCommandSettings() loadingFinishedSync.Wait(TimeSpan.FromSeconds(5)); servedFromCacheSync.Wait(TimeSpan.FromSeconds(5)); - var responseBody = await domains.Network.GetResponseBody(new V93.Network.GetResponseBodyCommandSettings() + var responseBody = await domains.Network.GetResponseBody(new V96.Network.GetResponseBodyCommandSettings() { RequestId = requestIdFromCache[0] }); @@ -204,16 +204,16 @@ await domains.Network.Enable(new V93.Network.EnableCommandSettings() [IgnoreBrowser(Selenium.Browser.Safari, "Safari does not support Chrome DevTools Protocol")] public async Task VerifySearchInResponseBody() { - var domains = session.GetVersionSpecificDomains(); + var domains = session.GetVersionSpecificDomains(); string[] requestIds = new string[1]; - await domains.Network.Enable(new V93.Network.EnableCommandSettings() + await domains.Network.Enable(new V96.Network.EnableCommandSettings() { MaxResourceBufferSize = 100000000 }); ManualResetEventSlim responseSync = new ManualResetEventSlim(false); - EventHandler responseReceivedHandler = (sender, e) => + EventHandler responseReceivedHandler = (sender, e) => { Assert.That(e, Is.Not.Null); requestIds[0] = e.RequestId; @@ -224,7 +224,7 @@ await domains.Network.Enable(new V93.Network.EnableCommandSettings() driver.Url = simpleTestPage; responseSync.Wait(TimeSpan.FromSeconds(5)); - var searchResponse = await domains.Network.SearchInResponseBody(new V93.Network.SearchInResponseBodyCommandSettings() + var searchResponse = await domains.Network.SearchInResponseBody(new V96.Network.SearchInResponseBodyCommandSettings() { RequestId = requestIds[0], Query = "/", @@ -240,14 +240,14 @@ await domains.Network.Enable(new V93.Network.EnableCommandSettings() [IgnoreBrowser(Selenium.Browser.Safari, "Safari does not support Chrome DevTools Protocol")] public async Task VerifyCacheDisabledAndClearCache() { - var domains = session.GetVersionSpecificDomains(); - await domains.Network.Enable(new V93.Network.EnableCommandSettings() + var domains = session.GetVersionSpecificDomains(); + await domains.Network.Enable(new V96.Network.EnableCommandSettings() { MaxPostDataSize = 100000000 }); ManualResetEventSlim responseSync = new ManualResetEventSlim(false); - EventHandler responseReceivedHandler = (sender, e) => + EventHandler responseReceivedHandler = (sender, e) => { Assert.That(e.Response.FromDiskCache, Is.False); responseSync.Set(); @@ -257,7 +257,7 @@ await domains.Network.Enable(new V93.Network.EnableCommandSettings() driver.Url = simpleTestPage; responseSync.Wait(TimeSpan.FromSeconds(5)); - await domains.Network.SetCacheDisabled(new V93.Network.SetCacheDisabledCommandSettings() + await domains.Network.SetCacheDisabled(new V96.Network.SetCacheDisabledCommandSettings() { CacheDisabled = true }); @@ -273,16 +273,16 @@ await domains.Network.SetCacheDisabled(new V93.Network.SetCacheDisabledCommandSe [IgnoreBrowser(Selenium.Browser.Safari, "Safari does not support Chrome DevTools Protocol")] public async Task VerifyCertificatesAndOverrideUserAgent() { - var domains = session.GetVersionSpecificDomains(); - await domains.Network.Enable(new V93.Network.EnableCommandSettings()); + var domains = session.GetVersionSpecificDomains(); + await domains.Network.Enable(new V96.Network.EnableCommandSettings()); - await domains.Network.SetUserAgentOverride(new V93.Network.SetUserAgentOverrideCommandSettings() + await domains.Network.SetUserAgentOverride(new V96.Network.SetUserAgentOverrideCommandSettings() { UserAgent = "userAgent" }); ManualResetEventSlim requestSync = new ManualResetEventSlim(false); - EventHandler requestWillBeSentHandler = (sender, e) => + EventHandler requestWillBeSentHandler = (sender, e) => { Assert.That(e.Request.Headers["User-Agent"], Is.EqualTo("userAgent")); requestSync.Set(); @@ -293,7 +293,7 @@ await domains.Network.SetUserAgentOverride(new V93.Network.SetUserAgentOverrideC driver.Url = origin; requestSync.Wait(TimeSpan.FromSeconds(5)); - var result = await domains.Network.GetCertificate(new V93.Network.GetCertificateCommandSettings() + var result = await domains.Network.GetCertificate(new V96.Network.GetCertificateCommandSettings() { Origin = origin }); @@ -308,10 +308,10 @@ await domains.Network.SetUserAgentOverride(new V93.Network.SetUserAgentOverrideC [IgnoreBrowser(Selenium.Browser.Safari, "Safari does not support Chrome DevTools Protocol")] public async Task VerifyResponseReceivedEventAndNetworkDisable() { - var domains = session.GetVersionSpecificDomains(); - await domains.Network.Enable(new V93.Network.EnableCommandSettings()); + var domains = session.GetVersionSpecificDomains(); + await domains.Network.Enable(new V96.Network.EnableCommandSettings()); ManualResetEventSlim responseSync = new ManualResetEventSlim(false); - EventHandler responseReceivedHandler = (sender, e) => + EventHandler responseReceivedHandler = (sender, e) => { Assert.That(e, Is.Not.Null); responseSync.Set(); @@ -330,34 +330,34 @@ public async Task VerifyResponseReceivedEventAndNetworkDisable() [IgnoreBrowser(Selenium.Browser.Safari, "Safari does not support Chrome DevTools Protocol")] public async Task VerifyWebSocketOperations() { - var domains = session.GetVersionSpecificDomains(); - await domains.Network.Enable(new V93.Network.EnableCommandSettings()); + var domains = session.GetVersionSpecificDomains(); + await domains.Network.Enable(new V96.Network.EnableCommandSettings()); - EventHandler webSocketCreatedHandler = (sender, e) => + EventHandler webSocketCreatedHandler = (sender, e) => { Assert.That(e, Is.Not.Null); }; domains.Network.WebSocketCreated += webSocketCreatedHandler; - EventHandler webSocketFrameReceivedHandler = (sender, e) => + EventHandler webSocketFrameReceivedHandler = (sender, e) => { Assert.That(e, Is.Not.Null); }; domains.Network.WebSocketFrameReceived += webSocketFrameReceivedHandler; - EventHandlerwebSocketFrameErrorHandler = (sender, e) => + EventHandlerwebSocketFrameErrorHandler = (sender, e) => { Assert.That(e, Is.Not.Null); }; domains.Network.WebSocketFrameError += webSocketFrameErrorHandler; - EventHandler webSocketFrameSentHandler = (sender, e) => + EventHandler webSocketFrameSentHandler = (sender, e) => { Assert.That(e, Is.Not.Null); }; domains.Network.WebSocketFrameSent += webSocketFrameSentHandler; - EventHandler webSocketClosedHandler = (sender, e) => + EventHandler webSocketClosedHandler = (sender, e) => { Assert.That(e, Is.Not.Null); }; @@ -373,13 +373,13 @@ public async Task VerifyWebSocketOperations() [IgnoreBrowser(Selenium.Browser.Safari, "Safari does not support Chrome DevTools Protocol")] public async Task VerifyRequestPostData() { - var domains = session.GetVersionSpecificDomains(); - await domains.Network.Enable(new V93.Network.EnableCommandSettings()); + var domains = session.GetVersionSpecificDomains(); + await domains.Network.Enable(new V96.Network.EnableCommandSettings()); string[] requestIds = new string[1]; ManualResetEventSlim requestSync = new ManualResetEventSlim(false); - EventHandler requestWillBeSentHandler = (sender, e) => + EventHandler requestWillBeSentHandler = (sender, e) => { Assert.That(e, Is.Not.Null); if (string.Compare(e.Request.Method, "post", StringComparison.OrdinalIgnoreCase) == 0) @@ -394,7 +394,7 @@ public async Task VerifyRequestPostData() driver.FindElement(By.XPath("//form/input")).Click(); requestSync.Wait(TimeSpan.FromSeconds(5)); - var response = await domains.Network.GetRequestPostData(new V93.Network.GetRequestPostDataCommandSettings() + var response = await domains.Network.GetRequestPostData(new V96.Network.GetRequestPostDataCommandSettings() { RequestId = requestIds[0] }); @@ -409,9 +409,9 @@ public async Task VerifyRequestPostData() [IgnoreBrowser(Selenium.Browser.Safari, "Safari does not support Chrome DevTools Protocol")] public async Task ByPassServiceWorker() { - var domains = session.GetVersionSpecificDomains(); - await domains.Network.Enable(new V93.Network.EnableCommandSettings()); - await domains.Network.SetBypassServiceWorker(new V93.Network.SetBypassServiceWorkerCommandSettings() + var domains = session.GetVersionSpecificDomains(); + await domains.Network.Enable(new V96.Network.EnableCommandSettings()); + await domains.Network.SetBypassServiceWorker(new V96.Network.SetBypassServiceWorkerCommandSettings() { Bypass = true }); @@ -424,11 +424,11 @@ await domains.Network.SetBypassServiceWorker(new V93.Network.SetBypassServiceWor [IgnoreBrowser(Selenium.Browser.Safari, "Safari does not support Chrome DevTools Protocol")] public async Task VerifyEventSourceMessage() { - var domains = session.GetVersionSpecificDomains(); - await domains.Network.Enable(new V93.Network.EnableCommandSettings()); + var domains = session.GetVersionSpecificDomains(); + await domains.Network.Enable(new V96.Network.EnableCommandSettings()); ManualResetEventSlim requestSync = new ManualResetEventSlim(false); - EventHandler eventSourceMessageReceivedHandler = (sender, e) => + EventHandler eventSourceMessageReceivedHandler = (sender, e) => { Assert.That(e, Is.Not.Null); requestSync.Set(); @@ -446,11 +446,11 @@ public async Task VerifyEventSourceMessage() [IgnoreBrowser(Selenium.Browser.Safari, "Safari does not support Chrome DevTools Protocol")] public async Task VerifySignedExchangeReceived() { - var domains = session.GetVersionSpecificDomains(); - await domains.Network.Enable(new V93.Network.EnableCommandSettings()); + var domains = session.GetVersionSpecificDomains(); + await domains.Network.Enable(new V96.Network.EnableCommandSettings()); ManualResetEventSlim requestSync = new ManualResetEventSlim(false); - EventHandler signedExchangeReceivedHandler = (sender, e) => + EventHandler signedExchangeReceivedHandler = (sender, e) => { Assert.That(e, Is.Not.Null); requestSync.Set(); @@ -468,11 +468,11 @@ public async Task VerifySignedExchangeReceived() [IgnoreBrowser(Selenium.Browser.Safari, "Safari does not support Chrome DevTools Protocol")] public async Task VerifyResourceChangedPriority() { - var domains = session.GetVersionSpecificDomains(); - await domains.Network.Enable(new V93.Network.EnableCommandSettings()); + var domains = session.GetVersionSpecificDomains(); + await domains.Network.Enable(new V96.Network.EnableCommandSettings()); ManualResetEventSlim requestSync = new ManualResetEventSlim(false); - EventHandler resourceChangedPriorityHandler = (sender, e) => + EventHandler resourceChangedPriorityHandler = (sender, e) => { Assert.That(e, Is.Not.Null); requestSync.Set(); @@ -490,13 +490,13 @@ public async Task VerifyResourceChangedPriority() [IgnoreBrowser(Selenium.Browser.Safari, "Safari does not support Chrome DevTools Protocol")] public async Task InterceptRequestAndContinue() { - var domains = session.GetVersionSpecificDomains(); - await domains.Network.Enable(new V93.Network.EnableCommandSettings()); + var domains = session.GetVersionSpecificDomains(); + await domains.Network.Enable(new V96.Network.EnableCommandSettings()); ManualResetEventSlim requestSync = new ManualResetEventSlim(false); - EventHandler requestInterceptedHandler = (async (sender, e) => + EventHandler requestInterceptedHandler = (async (sender, e) => { - await domains.Network.ContinueInterceptedRequest(new V93.Network.ContinueInterceptedRequestCommandSettings() + await domains.Network.ContinueInterceptedRequest(new V96.Network.ContinueInterceptedRequestCommandSettings() { InterceptionId = e.InterceptionId }); @@ -504,16 +504,16 @@ await domains.Network.ContinueInterceptedRequest(new V93.Network.ContinueInterce }); domains.Network.RequestIntercepted += requestInterceptedHandler; - var pattern = new V93.Network.RequestPattern() + var pattern = new V96.Network.RequestPattern() { UrlPattern = "*.css", - ResourceType = V93.Network.ResourceType.Stylesheet, - InterceptionStage = V93.Network.InterceptionStage.HeadersReceived + ResourceType = V96.Network.ResourceType.Stylesheet, + InterceptionStage = V96.Network.InterceptionStage.HeadersReceived }; - await domains.Network.SetRequestInterception(new V93.Network.SetRequestInterceptionCommandSettings() + await domains.Network.SetRequestInterception(new V96.Network.SetRequestInterceptionCommandSettings() { - Patterns = new V93.Network.RequestPattern[] { pattern } + Patterns = new V96.Network.RequestPattern[] { pattern } }); driver.Url = EnvironmentManager.Instance.UrlBuilder.WhereIs("js/skins/lightgray/content.min.css"); diff --git a/dotnet/test/common/DevTools/DevToolsPerformanceTest.cs b/dotnet/test/common/DevTools/DevToolsPerformanceTest.cs index b37b2c44008fe..44e2a0489a650 100644 --- a/dotnet/test/common/DevTools/DevToolsPerformanceTest.cs +++ b/dotnet/test/common/DevTools/DevToolsPerformanceTest.cs @@ -18,8 +18,8 @@ public class DevToolsPerformanceTest : DevToolsTestFixture [IgnoreBrowser(Selenium.Browser.Safari, "Safari does not support Chrome DevTools Protocol")] public async Task EnableAndDisablePerformance() { - var domains = session.GetVersionSpecificDomains(); - await domains.Performance.Enable(new V93.Performance.EnableCommandSettings()); + var domains = session.GetVersionSpecificDomains(); + await domains.Performance.Enable(new V96.Performance.EnableCommandSettings()); driver.Url = simpleTestPage; await domains.Performance.Disable(); } @@ -31,7 +31,7 @@ public async Task EnableAndDisablePerformance() [IgnoreBrowser(Selenium.Browser.Safari, "Safari does not support Chrome DevTools Protocol")] public async Task DisablePerformance() { - var domains = session.GetVersionSpecificDomains(); + var domains = session.GetVersionSpecificDomains(); await domains.Performance.Disable(); driver.Url = simpleTestPage; await domains.Performance.Disable(); @@ -44,13 +44,13 @@ public async Task DisablePerformance() [IgnoreBrowser(Selenium.Browser.Safari, "Safari does not support Chrome DevTools Protocol")] public async Task SetTimeDomainTimeTickPerformance() { - var domains = session.GetVersionSpecificDomains(); + var domains = session.GetVersionSpecificDomains(); await domains.Performance.Disable(); - await domains.Performance.SetTimeDomain(new V93.Performance.SetTimeDomainCommandSettings() + await domains.Performance.SetTimeDomain(new V96.Performance.SetTimeDomainCommandSettings() { TimeDomain = "timeTicks" }); - await domains.Performance.Enable(new V93.Performance.EnableCommandSettings()); + await domains.Performance.Enable(new V96.Performance.EnableCommandSettings()); driver.Url = simpleTestPage; await domains.Performance.Disable(); } @@ -62,13 +62,13 @@ await domains.Performance.SetTimeDomain(new V93.Performance.SetTimeDomainCommand [IgnoreBrowser(Selenium.Browser.Safari, "Safari does not support Chrome DevTools Protocol")] public async Task SetTimeDomainsThreadTicksPerformance() { - var domains = session.GetVersionSpecificDomains(); + var domains = session.GetVersionSpecificDomains(); await domains.Performance.Disable(); - await domains.Performance.SetTimeDomain(new V93.Performance.SetTimeDomainCommandSettings() + await domains.Performance.SetTimeDomain(new V96.Performance.SetTimeDomainCommandSettings() { TimeDomain = "threadTicks" }); - await domains.Performance.Enable(new V93.Performance.EnableCommandSettings()); + await domains.Performance.Enable(new V96.Performance.EnableCommandSettings()); driver.Url = simpleTestPage; await domains.Performance.Disable(); } @@ -80,12 +80,12 @@ await domains.Performance.SetTimeDomain(new V93.Performance.SetTimeDomainCommand [IgnoreBrowser(Selenium.Browser.Safari, "Safari does not support Chrome DevTools Protocol")] public async Task GetMetricsByTimeTicks() { - var domains = session.GetVersionSpecificDomains(); - await domains.Performance.SetTimeDomain(new V93.Performance.SetTimeDomainCommandSettings() + var domains = session.GetVersionSpecificDomains(); + await domains.Performance.SetTimeDomain(new V96.Performance.SetTimeDomainCommandSettings() { TimeDomain = "timeTicks" }); - await domains.Performance.Enable(new V93.Performance.EnableCommandSettings()); + await domains.Performance.Enable(new V96.Performance.EnableCommandSettings()); driver.Url = simpleTestPage; var response = await domains.Performance.GetMetrics(); var metrics = response.Metrics; @@ -101,12 +101,12 @@ await domains.Performance.SetTimeDomain(new V93.Performance.SetTimeDomainCommand [IgnoreBrowser(Selenium.Browser.Safari, "Safari does not support Chrome DevTools Protocol")] public async Task GetMetricsByThreadTicks() { - var domains = session.GetVersionSpecificDomains(); - await domains.Performance.SetTimeDomain(new V93.Performance.SetTimeDomainCommandSettings() + var domains = session.GetVersionSpecificDomains(); + await domains.Performance.SetTimeDomain(new V96.Performance.SetTimeDomainCommandSettings() { TimeDomain = "threadTicks" }); - await domains.Performance.Enable(new V93.Performance.EnableCommandSettings()); + await domains.Performance.Enable(new V96.Performance.EnableCommandSettings()); driver.Url = simpleTestPage; var response = await domains.Performance.GetMetrics(); var metrics = response.Metrics; diff --git a/dotnet/test/common/DevTools/DevToolsProfilerTest.cs b/dotnet/test/common/DevTools/DevToolsProfilerTest.cs index cf2ad8d3ca9a7..583a99c9f0892 100644 --- a/dotnet/test/common/DevTools/DevToolsProfilerTest.cs +++ b/dotnet/test/common/DevTools/DevToolsProfilerTest.cs @@ -18,7 +18,7 @@ public class DevToolsProfilerTest : DevToolsTestFixture [IgnoreBrowser(Selenium.Browser.Safari, "Safari does not support Chrome DevTools Protocol")] public async Task SimpleStartStopAndGetProfilerTest() { - var domains = session.GetVersionSpecificDomains(); + var domains = session.GetVersionSpecificDomains(); await domains.Profiler.Enable(); await domains.Profiler.Start(); var response = await domains.Profiler.Stop(); @@ -34,10 +34,10 @@ public async Task SimpleStartStopAndGetProfilerTest() [IgnoreBrowser(Selenium.Browser.Safari, "Safari does not support Chrome DevTools Protocol")] public async Task SampleGetBestEffortProfilerTest() { - var domains = session.GetVersionSpecificDomains(); + var domains = session.GetVersionSpecificDomains(); await domains.Profiler.Enable(); driver.Url = simpleTestPage; - await domains.Profiler.SetSamplingInterval(new V93.Profiler.SetSamplingIntervalCommandSettings() + await domains.Profiler.SetSamplingInterval(new V96.Profiler.SetSamplingIntervalCommandSettings() { Interval = 30 }); @@ -56,10 +56,10 @@ await domains.Profiler.SetSamplingInterval(new V93.Profiler.SetSamplingIntervalC [IgnoreBrowser(Selenium.Browser.Safari, "Safari does not support Chrome DevTools Protocol")] public async Task SampleSetStartPreciseCoverageTest() { - var domains = session.GetVersionSpecificDomains(); + var domains = session.GetVersionSpecificDomains(); await domains.Profiler.Enable(); driver.Url = simpleTestPage; - await domains.Profiler.StartPreciseCoverage(new V93.Profiler.StartPreciseCoverageCommandSettings() + await domains.Profiler.StartPreciseCoverage(new V96.Profiler.StartPreciseCoverageCommandSettings() { CallCount = true, Detailed = true @@ -82,11 +82,11 @@ await domains.Profiler.StartPreciseCoverage(new V93.Profiler.StartPreciseCoverag [IgnoreBrowser(Selenium.Browser.Safari, "Safari does not support Chrome DevTools Protocol")] public async Task SampleProfileEvents() { - var domains = session.GetVersionSpecificDomains(); + var domains = session.GetVersionSpecificDomains(); await domains.Profiler.Enable(); driver.Url = simpleTestPage; ManualResetEventSlim startSync = new ManualResetEventSlim(false); - EventHandler consoleProfileStartedHandler = (sender, e) => + EventHandler consoleProfileStartedHandler = (sender, e) => { Assert.That(e, Is.Not.Null); startSync.Set(); @@ -99,7 +99,7 @@ public async Task SampleProfileEvents() driver.Navigate().Refresh(); ManualResetEventSlim finishSync = new ManualResetEventSlim(false); - EventHandler consoleProfileFinishedHandler = (sender, e) => + EventHandler consoleProfileFinishedHandler = (sender, e) => { Assert.That(e, Is.Not.Null); finishSync.Set(); @@ -115,7 +115,7 @@ public async Task SampleProfileEvents() await domains.Profiler.Disable(); } - private void ValidateProfile(V93.Profiler.Profile profiler) + private void ValidateProfile(V96.Profiler.Profile profiler) { Assert.That(profiler, Is.Not.Null); Assert.That(profiler.Nodes, Is.Not.Null); diff --git a/dotnet/test/common/DevTools/DevToolsSecurityTest.cs b/dotnet/test/common/DevTools/DevToolsSecurityTest.cs index 981c63296f176..15ebc112fc29a 100644 --- a/dotnet/test/common/DevTools/DevToolsSecurityTest.cs +++ b/dotnet/test/common/DevTools/DevToolsSecurityTest.cs @@ -19,17 +19,17 @@ public class DevToolsSecurityTest : DevToolsTestFixture [IgnoreBrowser(Selenium.Browser.Safari, "Safari does not support Chrome DevTools Protocol")] public async Task LoadInsecureWebsite() { - var domains = session.GetVersionSpecificDomains(); + var domains = session.GetVersionSpecificDomains(); await domains.Security.Enable(); - await domains.Security.SetIgnoreCertificateErrors(new V93.Security.SetIgnoreCertificateErrorsCommandSettings() + await domains.Security.SetIgnoreCertificateErrors(new V96.Security.SetIgnoreCertificateErrorsCommandSettings() { Ignore = false }); string summary = null; ManualResetEventSlim sync = new ManualResetEventSlim(false); - EventHandler securityStateChangedHandler = (sender, e) => + EventHandler securityStateChangedHandler = (sender, e) => { summary = e.Summary; sync.Set(); @@ -52,10 +52,10 @@ await domains.Security.SetIgnoreCertificateErrors(new V93.Security.SetIgnoreCert [IgnoreBrowser(Selenium.Browser.Safari, "Safari does not support Chrome DevTools Protocol")] public async Task LoadSecureWebsite() { - var domains = session.GetVersionSpecificDomains(); + var domains = session.GetVersionSpecificDomains(); await domains.Security.Enable(); - await domains.Security.SetIgnoreCertificateErrors(new V93.Security.SetIgnoreCertificateErrorsCommandSettings() + await domains.Security.SetIgnoreCertificateErrors(new V96.Security.SetIgnoreCertificateErrorsCommandSettings() { Ignore = true }); diff --git a/dotnet/test/common/DevTools/DevToolsTargetTest.cs b/dotnet/test/common/DevTools/DevToolsTargetTest.cs index e4cbb383b4e1a..4618a8dcba2aa 100644 --- a/dotnet/test/common/DevTools/DevToolsTargetTest.cs +++ b/dotnet/test/common/DevTools/DevToolsTargetTest.cs @@ -21,24 +21,24 @@ public class DevToolsTargetTest : DevToolsTestFixture [IgnoreBrowser(Selenium.Browser.Safari, "Safari does not support Chrome DevTools Protocol")] public async Task GetTargetActivateAndAttach() { - var domains = session.GetVersionSpecificDomains(); + var domains = session.GetVersionSpecificDomains(); driver.Url = EnvironmentManager.Instance.UrlBuilder.WhereIs("devToolsConsoleTest.html"); var response = await domains.Target.GetTargets(); - V93.Target.TargetInfo[] allTargets = response.TargetInfos; - foreach (V93.Target.TargetInfo targetInfo in allTargets) + V96.Target.TargetInfo[] allTargets = response.TargetInfos; + foreach (V96.Target.TargetInfo targetInfo in allTargets) { ValidateTarget(targetInfo); - await domains.Target.ActivateTarget(new V93.Target.ActivateTargetCommandSettings() + await domains.Target.ActivateTarget(new V96.Target.ActivateTargetCommandSettings() { TargetId = targetInfo.TargetId }); - var attachResponse = await domains.Target.AttachToTarget(new V93.Target.AttachToTargetCommandSettings() + var attachResponse = await domains.Target.AttachToTarget(new V96.Target.AttachToTargetCommandSettings() { TargetId = targetInfo.TargetId, Flatten = true }); ValidateSession(attachResponse.SessionId); - var getInfoResponse = await domains.Target.GetTargetInfo(new V93.Target.GetTargetInfoCommandSettings() + var getInfoResponse = await domains.Target.GetTargetInfo(new V96.Target.GetTargetInfoCommandSettings() { TargetId = targetInfo.TargetId }); @@ -53,10 +53,10 @@ await domains.Target.ActivateTarget(new V93.Target.ActivateTargetCommandSettings [IgnoreBrowser(Selenium.Browser.Safari, "Safari does not support Chrome DevTools Protocol")] public async Task GetTargetAndSendMessageToTarget() { - var domains = session.GetVersionSpecificDomains(); - V93.Target.TargetInfo[] allTargets = null; + var domains = session.GetVersionSpecificDomains(); + V96.Target.TargetInfo[] allTargets = null; string sessionId = null; - V93.Target.TargetInfo targetInfo = null; + V96.Target.TargetInfo targetInfo = null; driver.Url = EnvironmentManager.Instance.UrlBuilder.WhereIs("devToolsConsoleTest.html"); ManualResetEventSlim sync = new ManualResetEventSlim(false); domains.Target.ReceivedMessageFromTarget += (sender, e) => @@ -69,19 +69,19 @@ public async Task GetTargetAndSendMessageToTarget() ValidateTargetsInfos(allTargets); ValidateTarget(allTargets[0]); targetInfo = allTargets[0]; - await domains.Target.ActivateTarget(new V93.Target.ActivateTargetCommandSettings() + await domains.Target.ActivateTarget(new V96.Target.ActivateTargetCommandSettings() { TargetId = targetInfo.TargetId }); - var attachResponse = await domains.Target.AttachToTarget(new V93.Target.AttachToTargetCommandSettings() + var attachResponse = await domains.Target.AttachToTarget(new V96.Target.AttachToTargetCommandSettings() { TargetId = targetInfo.TargetId, Flatten = false }); sessionId = attachResponse.SessionId; ValidateSession(sessionId); - await domains.Target.SendMessageToTarget(new V93.Target.SendMessageToTargetCommandSettings() + await domains.Target.SendMessageToTarget(new V96.Target.SendMessageToTargetCommandSettings() { Message = "{\"id\":" + id + ",\"method\":\"Page.bringToFront\"}", SessionId = sessionId, @@ -97,32 +97,32 @@ await domains.Target.SendMessageToTarget(new V93.Target.SendMessageToTargetComma [IgnoreBrowser(Selenium.Browser.Safari, "Safari does not support Chrome DevTools Protocol")] public async Task CreateAndContentLifeCycle() { - var domains = session.GetVersionSpecificDomains(); - EventHandler targetCreatedHandler = (sender, e) => + var domains = session.GetVersionSpecificDomains(); + EventHandler targetCreatedHandler = (sender, e) => { ValidateTargetInfo(e.TargetInfo); }; domains.Target.TargetCreated += targetCreatedHandler; - EventHandler targetCrashedHandler = (sender, e) => + EventHandler targetCrashedHandler = (sender, e) => { ValidateTargetCrashed(e); }; domains.Target.TargetCrashed += targetCrashedHandler; - EventHandler targetDestroyedHandler = (sender, e) => + EventHandler targetDestroyedHandler = (sender, e) => { ValidateTargetId(e.TargetId); }; domains.Target.TargetDestroyed += targetDestroyedHandler; - EventHandler targetInfoChangedHandler = (sender, e) => + EventHandler targetInfoChangedHandler = (sender, e) => { ValidateTargetInfo(e.TargetInfo); }; domains.Target.TargetInfoChanged += targetInfoChangedHandler; - var response = await domains.Target.CreateTarget(new V93.Target.CreateTargetCommandSettings() + var response = await domains.Target.CreateTarget(new V96.Target.CreateTargetCommandSettings() { Url = EnvironmentManager.Instance.UrlBuilder.WhereIs("devToolsConsoleTest.html"), NewWindow = true, @@ -130,12 +130,12 @@ public async Task CreateAndContentLifeCycle() }); ValidateTargetId(response.TargetId); - await domains.Target.SetDiscoverTargets(new V93.Target.SetDiscoverTargetsCommandSettings() + await domains.Target.SetDiscoverTargets(new V96.Target.SetDiscoverTargetsCommandSettings() { Discover = true }); - var closeResponse = await domains.Target.CloseTarget(new V93.Target.CloseTargetCommandSettings() + var closeResponse = await domains.Target.CloseTarget(new V96.Target.CloseTargetCommandSettings() { TargetId = response.TargetId }); @@ -144,7 +144,7 @@ await domains.Target.SetDiscoverTargets(new V93.Target.SetDiscoverTargetsCommand Assert.That(closeResponse.Success, Is.True); } - private void ValidateTargetCrashed(V93.Target.TargetCrashedEventArgs targetCrashed) + private void ValidateTargetCrashed(V96.Target.TargetCrashedEventArgs targetCrashed) { Assert.That(targetCrashed, Is.Not.Null); Assert.That(targetCrashed.ErrorCode, Is.Not.Null); @@ -157,7 +157,7 @@ private void ValidateTargetId(string targetId) Assert.That(targetId, Is.Not.Null); } - private void ValidateMessage(V93.Target.ReceivedMessageFromTargetEventArgs messageFromTarget) + private void ValidateMessage(V96.Target.ReceivedMessageFromTargetEventArgs messageFromTarget) { Assert.That(messageFromTarget, Is.Not.Null); Assert.That(messageFromTarget.Message, Is.Not.Null); @@ -165,7 +165,7 @@ private void ValidateMessage(V93.Target.ReceivedMessageFromTargetEventArgs messa Assert.That(messageFromTarget.Message, Is.EqualTo("{\"id\":" + id + ",\"result\":{}}")); } - private void ValidateTargetInfo(V93.Target.TargetInfo targetInfo) + private void ValidateTargetInfo(V96.Target.TargetInfo targetInfo) { Assert.That(targetInfo, Is.Not.Null); Assert.That(targetInfo.TargetId, Is.Not.Null); @@ -174,13 +174,13 @@ private void ValidateTargetInfo(V93.Target.TargetInfo targetInfo) Assert.That(targetInfo.Url, Is.Not.Null); } - private void ValidateTargetsInfos(V93.Target.TargetInfo[] targets) + private void ValidateTargetsInfos(V96.Target.TargetInfo[] targets) { Assert.That(targets, Is.Not.Null); Assert.That(targets.Length, Is.GreaterThan(0)); } - private void ValidateTarget(V93.Target.TargetInfo targetInfo) + private void ValidateTarget(V96.Target.TargetInfo targetInfo) { Assert.That(targetInfo, Is.Not.Null); Assert.That(targetInfo.TargetId, Is.Not.Null); diff --git a/dotnet/test/common/DriverTestFixture.cs b/dotnet/test/common/DriverTestFixture.cs index 94a8965134722..dbcb6d2c86d12 100644 --- a/dotnet/test/common/DriverTestFixture.cs +++ b/dotnet/test/common/DriverTestFixture.cs @@ -80,6 +80,7 @@ public abstract class DriverTestFixture public string missedJsReferencePage = EnvironmentManager.Instance.UrlBuilder.WhereIs("missedJsReference.html"); public string authenticationPage = EnvironmentManager.Instance.UrlBuilder.WhereIs("basicAuth"); public string html5Page = EnvironmentManager.Instance.UrlBuilder.WhereIs("html5Page.html"); + public string shadowRootPage = EnvironmentManager.Instance.UrlBuilder.WhereIs("shadowRootPage.html"); protected IWebDriver driver; diff --git a/dotnet/test/common/ShadowRootHandlingTest.cs b/dotnet/test/common/ShadowRootHandlingTest.cs new file mode 100644 index 0000000000000..efd610e20c6de --- /dev/null +++ b/dotnet/test/common/ShadowRootHandlingTest.cs @@ -0,0 +1,58 @@ +using System.Collections.Generic; +using NUnit.Framework; +using System.Collections.ObjectModel; + +namespace OpenQA.Selenium +{ + [IgnoreBrowser(Browser.IE, "IE does not support Shadow DOM natively")] + [IgnoreBrowser(Browser.Safari, "Safari driver does not support Shadow DOM end points")] + [TestFixture] + public class ShadowRootHandlingTest : DriverTestFixture + { + [Test] + public void ShouldReturnShadowRoot() + { + driver.Url = shadowRootPage; + IWebElement element = driver.FindElement(By.CssSelector("custom-checkbox-element")); + ISearchContext shadowRoot = element.GetShadowRoot(); + Assert.That(shadowRoot, Is.Not.Null, "Did not find shadow root"); + } + + [Test] + public void ShouldFindElementUnderShadowRoot() + { + driver.Url = shadowRootPage; + IWebElement element = driver.FindElement(By.CssSelector("custom-checkbox-element")); + ISearchContext shadowRoot = element.GetShadowRoot(); + IWebElement elementInShadow = shadowRoot.FindElement(By.CssSelector("input")); + Assert.That(elementInShadow.GetAttribute("type"), Is.EqualTo("checkbox"), "Did not find element in shadow root"); + } + + [Test] + public void ShouldThrowGettingShadowRootWithElementNotHavingShadowRoot() + { + driver.Url = shadowRootPage; + IWebElement element = driver.FindElement(By.CssSelector("#noShadowRoot")); + Assert.That(() => element.GetShadowRoot(), Throws.InstanceOf(typeof(NoSuchShadowRootException))); + } + + [Test] + public void ShouldGetShadowRootReferenceFromJavaScript() + { + driver.Url = shadowRootPage; + IWebElement element = driver.FindElement(By.CssSelector("custom-checkbox-element")); + object shadowRoot = ((IJavaScriptExecutor)driver).ExecuteScript("return arguments[0].shadowRoot;", element); + Assert.That(shadowRoot, Is.InstanceOf(), "Did not find shadow root"); + } + + [Test] + public void ShouldAllowShadowRootReferenceAsArgumentToJavaScript() + { + driver.Url = shadowRootPage; + IWebElement element = driver.FindElement(By.CssSelector("custom-checkbox-element")); + ISearchContext shadowRoot = element.GetShadowRoot(); + object elementInShadow = ((IJavaScriptExecutor)driver).ExecuteScript("return arguments[0].querySelector('input');", shadowRoot); + Assert.That(elementInShadow, Is.InstanceOf(), "Did not find shadow root"); + } + } +} diff --git a/dotnet/test/common/appconfig.json b/dotnet/test/common/appconfig.json index 6e496f87e4ccf..728b1da44b514 100644 --- a/dotnet/test/common/appconfig.json +++ b/dotnet/test/common/appconfig.json @@ -1,5 +1,5 @@ { - "DriverServiceLocation": "", + "DriverServiceLocation": "C:\\Projects\\WebDriverServers", "ActiveDriverConfig": "Chrome", "ActiveWebsiteConfig": "Default", "TestWebServerConfig": {