diff --git a/examples/dotnet/SeleniumDocs/BiDi/CDP/CDPTest.cs b/examples/dotnet/SeleniumDocs/BiDi/CDP/CDPTest.cs new file mode 100644 index 000000000000..3188d183d748 --- /dev/null +++ b/examples/dotnet/SeleniumDocs/BiDi/CDP/CDPTest.cs @@ -0,0 +1,29 @@ +using System.Collections.Generic; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using OpenQA.Selenium; +using OpenQA.Selenium.Chrome; + +namespace SeleniumDocs.BiDi.CDP +{ + [TestClass] + public class CDPTest : BaseChromeTest + { + [TestMethod] + public void SetCookie() + { + var cookie = new Dictionary + { + { "name", "cheese" }, + { "value", "gouda" }, + { "domain", "www.selenium.dev" }, + { "secure", true } + }; + ((ChromeDriver)driver).ExecuteCdpCommand("Network.setCookie", cookie); + + driver.Url = "https://www.selenium.dev"; + Cookie cheese = driver.Manage().Cookies.GetCookieNamed("cheese"); + Assert.AreEqual("gouda", cheese.Value); + + } + } +} \ No newline at end of file diff --git a/examples/dotnet/SeleniumDocs/BiDi/CDP/LoggingTest.cs b/examples/dotnet/SeleniumDocs/BiDi/CDP/LoggingTest.cs new file mode 100644 index 000000000000..c7f912be43da --- /dev/null +++ b/examples/dotnet/SeleniumDocs/BiDi/CDP/LoggingTest.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Microsoft.IdentityModel.Tokens; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using OpenQA.Selenium; +using OpenQA.Selenium.Support.UI; + +namespace SeleniumDocs.BiDi.CDP +{ + [TestClass] + public class LoggingTest : BaseChromeTest + { + [TestMethod] + public async Task ConsoleLogs() + { + driver.Url = "https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html"; + + using IJavaScriptEngine monitor = new JavaScriptEngine(driver); + var messages = new List(); + monitor.JavaScriptConsoleApiCalled += (_, e) => + { + messages.Add(e.MessageContent); + }; + await monitor.StartEventMonitoring(); + + driver.FindElement(By.Id("consoleLog")).Click(); + driver.FindElement(By.Id("consoleError")).Click(); + new WebDriverWait(driver, TimeSpan.FromSeconds(5)).Until(_ => messages.Count > 1); + monitor.StopEventMonitoring(); + + Assert.IsTrue(messages.Contains("Hello, world!")); + Assert.IsTrue(messages.Contains("I am console error")); + } + + [TestMethod] + public async Task JsErrors() + { + driver.Url = "https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html"; + + using IJavaScriptEngine monitor = new JavaScriptEngine(driver); + var messages = new List(); + monitor.JavaScriptExceptionThrown += (_, e) => + { + messages.Add(e.Message); + }; + await monitor.StartEventMonitoring(); + + driver.FindElement(By.Id("jsException")).Click(); + new WebDriverWait(driver, TimeSpan.FromSeconds(5)).Until(_ => !messages.IsNullOrEmpty()); + monitor.StopEventMonitoring(); + + Assert.IsTrue(messages.Contains("Uncaught")); + } + } +} \ No newline at end of file diff --git a/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/BidiApiTest.cs b/examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs similarity index 52% rename from examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/BidiApiTest.cs rename to examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs index f088fb915cab..03226fcaf9a4 100644 --- a/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/BidiApiTest.cs +++ b/examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs @@ -1,17 +1,24 @@ -using System; -using System.Collections; using System.Collections.Generic; using System.Threading.Tasks; -using Microsoft.IdentityModel.Tokens; using Microsoft.VisualStudio.TestTools.UnitTesting; using OpenQA.Selenium; -using OpenQA.Selenium.Support.UI; +using OpenQA.Selenium.DevTools; +using System.Linq; +using OpenQA.Selenium.DevTools.V126.Network; +using OpenQA.Selenium.DevTools.V126.Performance; -namespace SeleniumDocs.Bidirectional.ChromeDevTools + +namespace SeleniumDocs.BiDi.CDP { [TestClass] - public class BidiApiTest : BaseChromeTest + public class NetworkTest : BaseTest { + [TestInitialize] + public void Startup() + { + StartDriver("126"); + } + [TestMethod] public async Task BasicAuthentication() { @@ -20,104 +27,16 @@ public async Task BasicAuthentication() UriMatcher = uri => uri.AbsoluteUri.Contains("herokuapp"), Credentials = new PasswordCredentials("admin", "admin") }; - var networkInterceptor = driver.Manage().Network; networkInterceptor.AddAuthenticationHandler(handler); - await networkInterceptor.StartMonitoring(); + driver.Navigate().GoToUrl("https://the-internet.herokuapp.com/basic_auth"); await networkInterceptor.StopMonitoring(); Assert.AreEqual("Congratulations! You must have the proper credentials.", driver.FindElement(By.TagName("p")).Text); } - - [TestMethod] - public async Task PinScript() - { - driver.Url = "https://www.selenium.dev/selenium/web/xhtmlTest.html"; - var element = driver.FindElement(By.Id("id1")); - - var key = await new JavaScriptEngine(driver).PinScript("return arguments;"); - - var arguments = ((WebDriver)driver).ExecuteScript(key, 1, true, element); - - var expected = new List - { - 1L, - true, - element - }; - CollectionAssert.AreEqual(expected, (ICollection)arguments); - } - - [TestMethod] - public async Task MutatedElements() - { - driver.Url = "https://www.selenium.dev/selenium/web/dynamic.html"; - - var mutations = new List(); - using IJavaScriptEngine monitor = new JavaScriptEngine(driver); - monitor.DomMutated += (_, e) => - { - var locator = By.CssSelector($"*[data-__webdriver_id='{e.AttributeData.TargetId}']"); - mutations.Add(driver.FindElement(locator)); - }; - - await monitor.StartEventMonitoring(); - await monitor.EnableDomMutationMonitoring(); - - driver.FindElement(By.Id("reveal")).Click(); - - new WebDriverWait(driver, TimeSpan.FromSeconds(5)).Until(_ => !mutations.IsNullOrEmpty()); - await monitor.DisableDomMutationMonitoring(); - monitor.StopEventMonitoring(); - - var revealed = driver.FindElement(By.Id("revealed")); - Assert.AreEqual(revealed, mutations[0]); - } - - [TestMethod] - public async Task ConsoleLogs() - { - driver.Url = "https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html"; - - using IJavaScriptEngine monitor = new JavaScriptEngine(driver); - var messages = new List(); - monitor.JavaScriptConsoleApiCalled += (_, e) => - { - messages.Add(e.MessageContent); - }; - - await monitor.StartEventMonitoring(); - driver.FindElement(By.Id("consoleLog")).Click(); - driver.FindElement(By.Id("consoleError")).Click(); - new WebDriverWait(driver, TimeSpan.FromSeconds(5)).Until(_ => messages.Count > 1); - monitor.StopEventMonitoring(); - - Assert.IsTrue(messages.Contains("Hello, world!")); - Assert.IsTrue(messages.Contains("I am console error")); - } - - [TestMethod] - public async Task JsErrors() - { - driver.Url = "https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html"; - - using IJavaScriptEngine monitor = new JavaScriptEngine(driver); - var messages = new List(); - monitor.JavaScriptExceptionThrown += (_, e) => - { - messages.Add(e.Message); - }; - - await monitor.StartEventMonitoring(); - driver.FindElement(By.Id("jsException")).Click(); - new WebDriverWait(driver, TimeSpan.FromSeconds(5)).Until(_ => !messages.IsNullOrEmpty()); - monitor.StopEventMonitoring(); - - Assert.IsTrue(messages.Contains("Uncaught")); - } [TestMethod] public async Task RecordNetworkResponse() @@ -129,8 +48,8 @@ public async Task RecordNetworkResponse() { contentType.Add(e.ResponseHeaders["content-type"]); }; - await networkInterceptor.StartMonitoring(); + driver.Navigate().GoToUrl("https://www.selenium.dev/selenium/web/blank.html"); await networkInterceptor.StopMonitoring(); @@ -149,11 +68,10 @@ public async Task TransformNetworkResponse() Body = "Creamy, delicious cheese!" } }; - INetwork networkInterceptor = driver.Manage().Network; networkInterceptor.AddResponseHandler(handler); - await networkInterceptor.StartMonitoring(); + driver.Navigate().GoToUrl("https://www.selenium.dev"); await networkInterceptor.StopMonitoring(); @@ -174,16 +92,60 @@ public async Task TransformNetworkRequest() return request; } }; - INetwork networkInterceptor = driver.Manage().Network; networkInterceptor.AddRequestHandler(handler); - await networkInterceptor.StartMonitoring(); + driver.Url = "https://www.selenium.dev/selenium/web/devToolsRequestInterceptionTest.html"; driver.FindElement(By.TagName("button")).Click(); await networkInterceptor.StopMonitoring(); Assert.AreEqual("two", driver.FindElement(By.Id("result")).Text); } + + [TestMethod] + public async Task PerformanceMetrics() + { + driver.Url = "https://www.selenium.dev/selenium/web/frameset.html"; + + var session = ((IDevTools)driver).GetDevToolsSession(); + var domains = session.GetVersionSpecificDomains(); + + await domains.Performance.Enable(new OpenQA.Selenium.DevTools.V126.Performance.EnableCommandSettings()); + var metricsResponse = + await session.SendCommand( + new GetMetricsCommandSettings() + ); + + var metrics = metricsResponse.Metrics.ToDictionary( + dict => dict.Name, + dict => dict.Value + ); + + Assert.IsTrue(metrics["DevToolsCommandDuration"] > 0); + Assert.AreEqual(12, metrics["Frames"]); + } + + [TestMethod] + public async Task SetCookie() + { + var session = ((IDevTools)driver).GetDevToolsSession(); + var domains = session.GetVersionSpecificDomains(); + await domains.Network.Enable(new OpenQA.Selenium.DevTools.V126.Network.EnableCommandSettings()); + + var cookieCommandSettings = new SetCookieCommandSettings + { + Name = "cheese", + Value = "gouda", + Domain = "www.selenium.dev", + Secure = true + }; + await domains.Network.SetCookie(cookieCommandSettings); + + driver.Url = "https://www.selenium.dev"; + OpenQA.Selenium.Cookie cheese = driver.Manage().Cookies.GetCookieNamed("cheese"); + Assert.AreEqual("gouda", cheese.Value); + } + } } \ No newline at end of file diff --git a/examples/dotnet/SeleniumDocs/BiDi/CDP/ScriptTest.cs b/examples/dotnet/SeleniumDocs/BiDi/CDP/ScriptTest.cs new file mode 100644 index 000000000000..b3b92ee2cd35 --- /dev/null +++ b/examples/dotnet/SeleniumDocs/BiDi/CDP/ScriptTest.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Threading.Tasks; +using Microsoft.IdentityModel.Tokens; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using OpenQA.Selenium; +using OpenQA.Selenium.Support.UI; + +namespace SeleniumDocs.BiDi.CDP +{ + [TestClass] + public class ScriptTest : BaseChromeTest + { + [TestMethod] + public async Task PinScript() + { + driver.Url = "https://www.selenium.dev/selenium/web/xhtmlTest.html"; + var element = driver.FindElement(By.Id("id1")); + + var key = await new JavaScriptEngine(driver).PinScript("return arguments;"); + var arguments = ((WebDriver)driver).ExecuteScript(key, 1, true, element); + + var expected = new List + { + 1L, + true, + element + }; + CollectionAssert.AreEqual(expected, (ICollection)arguments); + } + + [TestMethod] + public async Task MutatedElements() + { + driver.Url = "https://www.selenium.dev/selenium/web/dynamic.html"; + var mutations = new List(); + + using IJavaScriptEngine monitor = new JavaScriptEngine(driver); + monitor.DomMutated += (_, e) => + { + var locator = By.CssSelector($"*[data-__webdriver_id='{e.AttributeData.TargetId}']"); + mutations.Add(driver.FindElement(locator)); + }; + await monitor.StartEventMonitoring(); + await monitor.EnableDomMutationMonitoring(); + + driver.FindElement(By.Id("reveal")).Click(); + + new WebDriverWait(driver, TimeSpan.FromSeconds(5)).Until(_ => !mutations.IsNullOrEmpty()); + await monitor.DisableDomMutationMonitoring(); + monitor.StopEventMonitoring(); + + var revealed = driver.FindElement(By.Id("revealed")); + Assert.AreEqual(revealed, mutations[0]); + } + } +} \ No newline at end of file diff --git a/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/CdpApiTest.cs b/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/CdpApiTest.cs deleted file mode 100644 index f5e5b88fd90b..000000000000 --- a/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/CdpApiTest.cs +++ /dev/null @@ -1,91 +0,0 @@ -using System; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using OpenQA.Selenium; -using OpenQA.Selenium.DevTools; -using OpenQA.Selenium.DevTools.V124.Network; -using OpenQA.Selenium.DevTools.V124.Performance; - -namespace SeleniumDocs.Bidirectional.ChromeDevtools -{ - [TestClass] - public class CdpApiTest : BaseTest - { - [TestInitialize] - public void Startup() - { - StartDriver("124"); - } - - [TestMethod] - public async Task SetCookie() - { - var session = ((IDevTools)driver).GetDevToolsSession(); - var domains = session.GetVersionSpecificDomains(); - await domains.Network.Enable(new OpenQA.Selenium.DevTools.V124.Network.EnableCommandSettings()); - - var cookieCommandSettings = new SetCookieCommandSettings - { - Name = "cheese", - Value = "gouda", - Domain = "www.selenium.dev", - Secure = true - }; - - await domains.Network.SetCookie(cookieCommandSettings); - - driver.Url = "https://www.selenium.dev"; - OpenQA.Selenium.Cookie cheese = driver.Manage().Cookies.GetCookieNamed("cheese"); - Assert.AreEqual("gouda", cheese.Value); - } - - [TestMethod] - public async Task PerformanceMetrics() - { - driver.Url = "https://www.selenium.dev/selenium/web/frameset.html"; - - var session = ((IDevTools)driver).GetDevToolsSession(); - var domains = session.GetVersionSpecificDomains(); - await domains.Performance.Enable(new OpenQA.Selenium.DevTools.V124.Performance.EnableCommandSettings()); - - var metricsResponse = - await session.SendCommand( - new GetMetricsCommandSettings() - ); - - var metrics = metricsResponse.Metrics.ToDictionary( - dict => dict.Name, - dict => dict.Value - ); - - Assert.IsTrue(metrics["DevToolsCommandDuration"] > 0); - Assert.AreEqual(12, metrics["Frames"]); - } - - [TestMethod] - public async Task BasicAuth() - { - var session = ((IDevTools)driver).GetDevToolsSession(); - var domains = session.GetVersionSpecificDomains(); - await domains.Network.Enable(new OpenQA.Selenium.DevTools.V124.Network.EnableCommandSettings()); - - var encodedAuth = Convert.ToBase64String(Encoding.Default.GetBytes("admin:admin")); - var headerSettings = new SetExtraHTTPHeadersCommandSettings - { - Headers = new Headers() - { - { "authorization", "Basic " + encodedAuth } - } - }; - - await domains.Network.SetExtraHTTPHeaders(headerSettings); - - driver.Url = "https://the-internet.herokuapp.com/basic_auth"; - - var element = driver.FindElement(By.TagName("p")); - Assert.AreEqual("Congratulations! You must have the proper credentials.", element.Text); - } - } -} \ No newline at end of file diff --git a/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/CdpEndpointTest.cs b/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/CdpEndpointTest.cs deleted file mode 100644 index ff4c4d089c3c..000000000000 --- a/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/CdpEndpointTest.cs +++ /dev/null @@ -1,81 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using OpenQA.Selenium; -using OpenQA.Selenium.Chrome; - -namespace SeleniumDocs.Bidirectional.ChromeDevtools -{ - [TestClass] - public class CdpEndpointTest : BaseTest - { - private readonly Dictionary emptyDictionary = new(); - - [TestInitialize] - public void Startup() - { - StartDriver(); - } - - [TestMethod] - public void SetCookie() - { - var cookie = new Dictionary - { - { "name", "cheese" }, - { "value", "gouda" }, - { "domain", "www.selenium.dev" }, - { "secure", true } - }; - - ((ChromeDriver)driver).ExecuteCdpCommand("Network.setCookie", cookie); - - driver.Url = "https://www.selenium.dev"; - Cookie cheese = driver.Manage().Cookies.GetCookieNamed("cheese"); - Assert.AreEqual("gouda", cheese.Value); - - } - - [TestMethod] - public void PerformanceMetrics() - { - driver.Url = "https://www.selenium.dev/selenium/web/frameset.html"; - - ((ChromeDriver)driver).ExecuteCdpCommand("Performance.enable", emptyDictionary); - - Dictionary response = (Dictionary)((ChromeDriver)driver) - .ExecuteCdpCommand("Performance.getMetrics", emptyDictionary); - - Object[] metricList = (object[])response["metrics"]; - var metrics = metricList.OfType>() - .ToDictionary( - dict => (string)dict["name"], - dict => dict["value"] - ); - - Assert.IsTrue((double)metrics["DevToolsCommandDuration"] > 0); - Assert.AreEqual((long)12, metrics["Frames"]); - } - - [TestMethod] - public void BasicAuth() - { - ((ChromeDriver)driver).ExecuteCdpCommand("Network.enable", emptyDictionary); - - string encodedAuth = Convert.ToBase64String(Encoding.Default.GetBytes("admin:admin")); - var headers = new Dictionary - { - { "headers", new Dictionary { { "authorization", "Basic " + encodedAuth } } } - }; - - ((ChromeDriver)driver).ExecuteCdpCommand("Network.setExtraHTTPHeaders", headers); - - driver.Url = "https://the-internet.herokuapp.com/basic_auth"; - - var element = driver.FindElement(By.TagName("p")); - Assert.AreEqual("Congratulations! You must have the proper credentials.", element.Text); - } - } -} \ No newline at end of file diff --git a/examples/dotnet/SeleniumDocs/Bidirectional/WebDriverBiDi/BrowsingContextTest.cs b/examples/dotnet/SeleniumDocs/Bidirectional/WebDriverBiDi/BrowsingContextTest.cs deleted file mode 100644 index 7de31af093f6..000000000000 --- a/examples/dotnet/SeleniumDocs/Bidirectional/WebDriverBiDi/BrowsingContextTest.cs +++ /dev/null @@ -1,10 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace SeleniumDocs.Bidirectional.WebDriverBiDi -{ - [TestClass] - public class BrowsingContextTest : BaseTest - { - - } -} \ No newline at end of file diff --git a/examples/dotnet/SeleniumDocs/Bidirectional/WebDriverBiDi/LogTest.cs b/examples/dotnet/SeleniumDocs/Bidirectional/WebDriverBiDi/LogTest.cs deleted file mode 100644 index 54e3f92884b2..000000000000 --- a/examples/dotnet/SeleniumDocs/Bidirectional/WebDriverBiDi/LogTest.cs +++ /dev/null @@ -1,10 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace SeleniumDocs.Bidirectional.WebDriverBiDi -{ - [TestClass] - public class LogTest : BaseTest - { - - } -} \ No newline at end of file diff --git a/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/CdpApiTest.java b/examples/java/src/test/java/dev/selenium/bidi/cdp/CdpApiTest.java similarity index 52% rename from examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/CdpApiTest.java rename to examples/java/src/test/java/dev/selenium/bidi/cdp/CdpApiTest.java index b10941ecda9a..1b501ea2a185 100644 --- a/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/CdpApiTest.java +++ b/examples/java/src/test/java/dev/selenium/bidi/cdp/CdpApiTest.java @@ -1,4 +1,4 @@ -package dev.selenium.bidirectional.chrome_devtools; +package dev.selenium.bidi.cdp; import com.google.common.collect.ImmutableMap; import dev.selenium.BaseTest; @@ -42,53 +42,6 @@ public void createSession() { wait = new WebDriverWait(driver, Duration.ofSeconds(10)); } - @Test - public void setCookie() { - devTools = ((HasDevTools) driver).getDevTools(); - devTools.createSession(); - - devTools.send( - Network.setCookie( - "cheese", - "gouda", - Optional.empty(), - Optional.of("www.selenium.dev"), - Optional.empty(), - Optional.of(true), - Optional.empty(), - Optional.empty(), - Optional.empty(), - Optional.empty(), - Optional.empty(), - Optional.empty(), - Optional.empty(), - Optional.empty())); - - driver.get("https://www.selenium.dev"); - Cookie cheese = driver.manage().getCookieNamed("cheese"); - Assertions.assertEquals("gouda", cheese.getValue()); - } - - @Test - @Disabled("4.15 broke the casting") - public void performanceMetrics() { - driver.get("https://www.selenium.dev/selenium/web/frameset.html"); - - devTools = ((HasDevTools) driver).getDevTools(); - devTools.createSession(); - devTools.send(Performance.enable(Optional.empty())); - - List metricList = devTools.send(Performance.getMetrics()); - - Map metrics = new HashMap<>(); - for (Metric metric : metricList) { - metrics.put(metric.getName(), metric.getValue()); - } - - Assertions.assertTrue(metrics.get("DevToolsCommandDuration").doubleValue() > 0); - Assertions.assertEquals(12, metrics.get("Frames").intValue()); - } - @Test public void basicAuth() { devTools = ((HasDevTools) driver).getDevTools(); @@ -107,42 +60,6 @@ public void basicAuth() { driver.findElement(By.tagName("p")).getText()); } - @Test - public void consoleLogs() { - driver.get("https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html"); - - DevTools devTools = ((HasDevTools) driver).getDevTools(); - devTools.createSession(); - devTools.send(Runtime.enable()); - - CopyOnWriteArrayList logs = new CopyOnWriteArrayList<>(); - devTools.addListener( - Runtime.consoleAPICalled(), - event -> logs.add((String) event.getArgs().get(0).getValue().orElse(""))); - - driver.findElement(By.id("consoleLog")).click(); - - wait.until(_d -> !logs.isEmpty()); - Assertions.assertEquals("Hello, world!", logs.get(0)); - } - - @Test - public void jsErrors() { - driver.get("https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html"); - - DevTools devTools = ((HasDevTools) driver).getDevTools(); - devTools.createSession(); - devTools.send(Runtime.enable()); - - CopyOnWriteArrayList errors = new CopyOnWriteArrayList<>(); - devTools.getDomains().events().addJavascriptExceptionListener(errors::add); - - driver.findElement(By.id("jsException")).click(); - - wait.until(_d -> !errors.isEmpty()); - Assertions.assertTrue(errors.get(0).getMessage().contains("Error: Not working")); - } - @Test public void waitForDownload() { driver.get("https://www.selenium.dev/selenium/web/downloads/download.html"); diff --git a/examples/java/src/test/java/dev/selenium/bidi/cdp/CdpTest.java b/examples/java/src/test/java/dev/selenium/bidi/cdp/CdpTest.java new file mode 100644 index 000000000000..f83c18832d95 --- /dev/null +++ b/examples/java/src/test/java/dev/selenium/bidi/cdp/CdpTest.java @@ -0,0 +1,33 @@ +package dev.selenium.bidi.cdp; + +import dev.selenium.BaseTest; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.openqa.selenium.Cookie; +import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.chromium.HasCdp; + +import java.util.HashMap; +import java.util.Map; + +public class CdpTest extends BaseTest { + @BeforeEach + public void createSession() { + driver = new ChromeDriver(); + } + + @Test + public void setCookie() { + Map cookie = new HashMap<>(); + cookie.put("name", "cheese"); + cookie.put("value", "gouda"); + cookie.put("domain", "www.selenium.dev"); + cookie.put("secure", true); + ((HasCdp) driver).executeCdpCommand("Network.setCookie", cookie); + + driver.get("https://www.selenium.dev"); + Cookie cheese = driver.manage().getCookieNamed("cheese"); + Assertions.assertEquals("gouda", cheese.getValue()); + } +} diff --git a/examples/java/src/test/java/dev/selenium/bidi/cdp/LoggingTest.java b/examples/java/src/test/java/dev/selenium/bidi/cdp/LoggingTest.java new file mode 100644 index 000000000000..01a0cfa09333 --- /dev/null +++ b/examples/java/src/test/java/dev/selenium/bidi/cdp/LoggingTest.java @@ -0,0 +1,40 @@ +package dev.selenium.bidi.cdp; + +import static org.openqa.selenium.devtools.events.CdpEventTypes.consoleEvent; + +import dev.selenium.BaseTest; + +import java.time.Duration; +import java.util.concurrent.CopyOnWriteArrayList; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.openqa.selenium.*; +import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.logging.HasLogEvents; +import org.openqa.selenium.support.ui.WebDriverWait; + +public class LoggingTest extends BaseTest { + + @BeforeEach + public void createSession() { + driver = new ChromeDriver(); + wait = new WebDriverWait(driver, Duration.ofSeconds(10)); + } + + @Test + public void consoleLogs() { + driver.get("https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html"); + CopyOnWriteArrayList messages = new CopyOnWriteArrayList<>(); + + ((HasLogEvents) driver).onLogEvent(consoleEvent(e -> messages.add(e.getMessages().get(0)))); + + driver.findElement(By.id("consoleLog")).click(); + driver.findElement(By.id("consoleError")).click(); + + wait.until(_d -> messages.size() > 1); + Assertions.assertTrue(messages.contains("Hello, world!")); + Assertions.assertTrue(messages.contains("I am console error")); + } +} diff --git a/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/BidiApiTest.java b/examples/java/src/test/java/dev/selenium/bidi/cdp/NetworkTest.java similarity index 57% rename from examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/BidiApiTest.java rename to examples/java/src/test/java/dev/selenium/bidi/cdp/NetworkTest.java index cb657347d34c..f97b84709044 100644 --- a/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/BidiApiTest.java +++ b/examples/java/src/test/java/dev/selenium/bidi/cdp/NetworkTest.java @@ -1,29 +1,34 @@ -package dev.selenium.bidirectional.chrome_devtools; - -import static org.openqa.selenium.devtools.events.CdpEventTypes.consoleEvent; -import static org.openqa.selenium.devtools.events.CdpEventTypes.domMutation; +package dev.selenium.bidi.cdp; import com.google.common.net.MediaType; import dev.selenium.BaseTest; import java.net.*; import java.time.Duration; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Predicate; import java.util.function.Supplier; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.openqa.selenium.*; import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.devtools.DevTools; +import org.openqa.selenium.devtools.HasDevTools; import org.openqa.selenium.devtools.NetworkInterceptor; -import org.openqa.selenium.logging.HasLogEvents; +import org.openqa.selenium.devtools.v124.browser.Browser; +import org.openqa.selenium.devtools.v124.network.Network; +import org.openqa.selenium.devtools.v124.performance.Performance; +import org.openqa.selenium.devtools.v124.performance.model.Metric; import org.openqa.selenium.remote.http.*; import org.openqa.selenium.support.ui.WebDriverWait; -public class BidiApiTest extends BaseTest { +public class NetworkTest extends BaseTest { @BeforeEach public void createSession() { @@ -35,7 +40,6 @@ public void createSession() { public void basicAuthentication() { Predicate uriPredicate = uri -> uri.toString().contains("herokuapp.com"); Supplier authentication = UsernameAndPassword.of("admin", "admin"); - ((HasAuthentication) driver).register(uriPredicate, authentication); driver.get("https://the-internet.herokuapp.com/basic_auth"); @@ -45,46 +49,6 @@ public void basicAuthentication() { Assertions.assertEquals(successMessage, elementMessage.getText()); } - @Test - public void pinScript() { - driver.get("https://www.selenium.dev/selenium/web/xhtmlTest.html"); - WebElement element = driver.findElement(By.id("id1")); - - ScriptKey key = ((JavascriptExecutor) driver).pin("return arguments;"); - List arguments = - (List) ((JavascriptExecutor) driver).executeScript(key, 1, true, element); - - Assertions.assertEquals(List.of(1L, true, element), arguments); - } - - @Test - public void mutatedElements() { - driver.get("https://www.selenium.dev/selenium/web/dynamic.html"); - - CopyOnWriteArrayList mutations = new CopyOnWriteArrayList<>(); - ((HasLogEvents) driver).onLogEvent(domMutation(e -> mutations.add(e.getElement()))); - - driver.findElement(By.id("reveal")).click(); - - wait.until(_d -> !mutations.isEmpty()); - Assertions.assertEquals(mutations.get(0), driver.findElement(By.id("revealed"))); - } - - @Test - public void consoleLogs() { - driver.get("https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html"); - - CopyOnWriteArrayList messages = new CopyOnWriteArrayList<>(); - ((HasLogEvents) driver).onLogEvent(consoleEvent(e -> messages.add(e.getMessages().get(0)))); - - driver.findElement(By.id("consoleLog")).click(); - driver.findElement(By.id("consoleError")).click(); - - wait.until(_d -> messages.size() > 1); - Assertions.assertTrue(messages.contains("Hello, world!")); - Assertions.assertTrue(messages.contains("I am console error")); - } - @Test public void recordResponse() { CopyOnWriteArrayList contentType = new CopyOnWriteArrayList<>(); @@ -119,7 +83,6 @@ public void transformResponses() { .setStatus(200) .addHeader("Content-Type", MediaType.HTML_UTF_8.toString()) .setContent(Contents.utf8String("Creamy, delicious cheese!"))))) { - driver.get("https://www.selenium.dev/selenium/web/blank.html"); } @@ -128,7 +91,6 @@ public void transformResponses() { } @Test - @Disabled("Not working yet") public void interceptRequests() { AtomicBoolean completed = new AtomicBoolean(false); @@ -152,4 +114,74 @@ public void interceptRequests() { Assertions.assertEquals("two", driver.findElement(By.id("result")).getText()); } + + @Test + public void performanceMetrics() { + driver.get("https://www.selenium.dev/selenium/web/frameset.html"); + + DevTools devTools = ((HasDevTools) driver).getDevTools(); + devTools.createSession(); + + devTools.send(Performance.enable(Optional.empty())); + List metricList = devTools.send(Performance.getMetrics()); + + Map metrics = new HashMap<>(); + for (Metric metric : metricList) { + metrics.put(metric.getName(), metric.getValue()); + } + + Assertions.assertTrue(metrics.get("DevToolsCommandDuration").doubleValue() > 0); + Assertions.assertEquals(12, metrics.get("Frames").intValue()); + } + + @Test + public void setCookie() { + DevTools devTools = ((HasDevTools) driver).getDevTools(); + devTools.createSession(); + + devTools.send( + Network.setCookie( + "cheese", + "gouda", + Optional.empty(), + Optional.of("www.selenium.dev"), + Optional.empty(), + Optional.of(true), + Optional.empty(), + Optional.empty(), + Optional.empty(), + Optional.empty(), + Optional.empty(), + Optional.empty(), + Optional.empty(), + Optional.empty())); + + driver.get("https://www.selenium.dev"); + Cookie cheese = driver.manage().getCookieNamed("cheese"); + Assertions.assertEquals("gouda", cheese.getValue()); + } + + @Test + public void waitForDownload() { + driver.get("https://www.selenium.dev/selenium/web/downloads/download.html"); + + DevTools devTools = ((HasDevTools) driver).getDevTools(); + devTools.createSession(); + + devTools.send( + Browser.setDownloadBehavior( + Browser.SetDownloadBehaviorBehavior.ALLOWANDNAME, + Optional.empty(), + Optional.of(""), + Optional.of(true))); + + AtomicBoolean completed = new AtomicBoolean(false); + devTools.addListener( + Browser.downloadProgress(), + e -> completed.set(Objects.equals(e.getState().toString(), "completed"))); + + driver.findElement(By.id("file-2")).click(); + + Assertions.assertDoesNotThrow(() -> wait.until(_d -> completed)); + } } diff --git a/examples/java/src/test/java/dev/selenium/bidi/cdp/ScriptTest.java b/examples/java/src/test/java/dev/selenium/bidi/cdp/ScriptTest.java new file mode 100644 index 000000000000..dd6436f4f327 --- /dev/null +++ b/examples/java/src/test/java/dev/selenium/bidi/cdp/ScriptTest.java @@ -0,0 +1,51 @@ +package dev.selenium.bidi.cdp; + +import static org.openqa.selenium.devtools.events.CdpEventTypes.domMutation; + +import dev.selenium.BaseTest; + +import java.time.Duration; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.openqa.selenium.*; +import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.logging.HasLogEvents; +import org.openqa.selenium.support.ui.WebDriverWait; + +public class ScriptTest extends BaseTest { + + @BeforeEach + public void createSession() { + driver = new ChromeDriver(); + wait = new WebDriverWait(driver, Duration.ofSeconds(10)); + } + + @Test + public void pinScript() { + driver.get("https://www.selenium.dev/selenium/web/xhtmlTest.html"); + WebElement element = driver.findElement(By.id("id1")); + + ScriptKey key = ((JavascriptExecutor) driver).pin("return arguments;"); + List arguments = + (List) ((JavascriptExecutor) driver).executeScript(key, 1, true, element); + + Assertions.assertEquals(List.of(1L, true, element), arguments); + } + + @Test + public void mutatedElements() { + driver.get("https://www.selenium.dev/selenium/web/dynamic.html"); + CopyOnWriteArrayList mutations = new CopyOnWriteArrayList<>(); + + ((HasLogEvents) driver).onLogEvent(domMutation(e -> mutations.add(e.getElement()))); + + driver.findElement(By.id("reveal")).click(); + + wait.until(_d -> !mutations.isEmpty()); + Assertions.assertEquals(mutations.get(0), driver.findElement(By.id("revealed"))); + } +} diff --git a/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/CdpEndpointTest.java b/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/CdpEndpointTest.java deleted file mode 100644 index c8845e727d4d..000000000000 --- a/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/CdpEndpointTest.java +++ /dev/null @@ -1,74 +0,0 @@ -package dev.selenium.bidirectional.chrome_devtools; - -import com.google.common.collect.ImmutableMap; -import dev.selenium.BaseTest; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.Cookie; -import org.openqa.selenium.chrome.ChromeDriver; -import org.openqa.selenium.chromium.HasCdp; - -import java.util.Base64; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class CdpEndpointTest extends BaseTest { - @BeforeEach - public void createSession() { - driver = new ChromeDriver(); - } - - @Test - public void setCookie() { - Map cookie = new HashMap<>(); - cookie.put("name", "cheese"); - cookie.put("value", "gouda"); - cookie.put("domain", "www.selenium.dev"); - cookie.put("secure", true); - - ((HasCdp) driver).executeCdpCommand("Network.setCookie", cookie); - - driver.get("https://www.selenium.dev"); - Cookie cheese = driver.manage().getCookieNamed("cheese"); - Assertions.assertEquals("gouda", cheese.getValue()); - } - - @Test - public void performanceMetrics() { - driver.get("https://www.selenium.dev/selenium/web/frameset.html"); - - ((HasCdp) driver).executeCdpCommand("Performance.enable", new HashMap<>()); - - Map response = - ((HasCdp) driver).executeCdpCommand("Performance.getMetrics", new HashMap<>()); - List> metricList = (List>) response.get("metrics"); - - Map metrics = new HashMap<>(); - for (Map metric : metricList) { - metrics.put((String) metric.get("name"), (Number) metric.get("value")); - } - - Assertions.assertTrue(metrics.get("DevToolsCommandDuration").doubleValue() > 0); - Assertions.assertEquals(12, metrics.get("Frames").intValue()); - } - - @Test - public void basicAuth() { - ((HasCdp) driver).executeCdpCommand("Network.enable", new HashMap<>()); - - String encodedAuth = Base64.getEncoder().encodeToString("admin:admin".getBytes()); - Map headers = - ImmutableMap.of("headers", ImmutableMap.of("authorization", "Basic " + encodedAuth)); - - ((HasCdp) driver).executeCdpCommand("Network.setExtraHTTPHeaders", headers); - - driver.get("https://the-internet.herokuapp.com/basic_auth"); - - Assertions.assertEquals( - "Congratulations! You must have the proper credentials.", - driver.findElement(By.tagName("p")).getText()); - } -} diff --git a/examples/python/tests/bidi/cdp/test_cdp.py b/examples/python/tests/bidi/cdp/test_cdp.py new file mode 100644 index 000000000000..97664812f8fd --- /dev/null +++ b/examples/python/tests/bidi/cdp/test_cdp.py @@ -0,0 +1,12 @@ +def test_set_cookie(driver): + cookie = {'name': 'cheese', + 'value': 'gouda', + 'domain': 'www.selenium.dev', + 'secure': True} + + driver.execute_cdp_cmd('Network.setCookie', cookie) + + driver.get('https://www.selenium.dev') + cheese = driver.get_cookie(cookie['name']) + + assert cheese['value'] == 'gouda' diff --git a/examples/python/tests/bidirectional/chrome_devtools/test_bidi_api.py b/examples/python/tests/bidi/cdp/test_logs.py similarity index 58% rename from examples/python/tests/bidirectional/chrome_devtools/test_bidi_api.py rename to examples/python/tests/bidi/cdp/test_logs.py index b7e7a89b728a..573ead1e578a 100644 --- a/examples/python/tests/bidirectional/chrome_devtools/test_bidi_api.py +++ b/examples/python/tests/bidi/cdp/test_logs.py @@ -4,26 +4,12 @@ from selenium.webdriver.common.log import Log -@pytest.mark.trio -async def test_mutation(driver): - async with driver.bidi_connection() as session: - log = Log(driver, session) - - async with log.mutation_events() as event: - driver.get('https://www.selenium.dev/selenium/web/dynamic.html') - driver.find_element(By.ID, "reveal").click() - - assert event["element"] == driver.find_element(By.ID, "revealed") - - @pytest.mark.trio async def test_console_log(driver): driver.get('https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html') async with driver.bidi_connection() as session: - log = Log(driver, session) - - async with log.add_listener(Console.ALL) as messages: + async with Log(driver, session).add_listener(Console.ALL) as messages: driver.find_element(by=By.ID, value='consoleLog').click() assert messages["message"] == "Hello, world!" @@ -34,9 +20,7 @@ async def test_js_error(driver): driver.get('https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html') async with driver.bidi_connection() as session: - log = Log(driver, session) - - async with log.add_js_error_listener() as messages: + async with Log(driver, session).add_js_error_listener() as messages: driver.find_element(by=By.ID, value='jsException').click() assert "Error: Not working" in messages.exception_details.exception.description diff --git a/examples/python/tests/bidirectional/chrome_devtools/test_cdp_api.py b/examples/python/tests/bidi/cdp/test_network.py similarity index 99% rename from examples/python/tests/bidirectional/chrome_devtools/test_cdp_api.py rename to examples/python/tests/bidi/cdp/test_network.py index be0aac66d444..99eada8e4f57 100644 --- a/examples/python/tests/bidirectional/chrome_devtools/test_cdp_api.py +++ b/examples/python/tests/bidi/cdp/test_network.py @@ -6,22 +6,18 @@ @pytest.mark.trio -async def test_set_cookie(driver): +async def test_basic_auth(driver): async with driver.bidi_connection() as connection: - execution = connection.devtools.network.set_cookie( - name="cheese", - value="gouda", - domain="www.selenium.dev", - secure=True - ) - - await connection.session.execute(execution) + await connection.session.execute(connection.devtools.network.enable()) - driver.get("https://www.selenium.dev") - cheese = driver.get_cookie("cheese") + credentials = base64.b64encode("admin:admin".encode()).decode() + auth = {'authorization': 'Basic ' + credentials} + await connection.session.execute(connection.devtools.network.set_extra_http_headers(Headers(auth))) - assert cheese["value"] == "gouda" + driver.get('https://the-internet.herokuapp.com/basic_auth') + success = driver.find_element(by=By.TAG_NAME, value='p') + assert success.text == 'Congratulations! You must have the proper credentials.' @pytest.mark.trio async def test_performance(driver): @@ -29,7 +25,6 @@ async def test_performance(driver): async with driver.bidi_connection() as connection: await connection.session.execute(connection.devtools.performance.enable()) - metric_list = await connection.session.execute(connection.devtools.performance.get_metrics()) metrics = {metric.name: metric.value for metric in metric_list} @@ -37,18 +32,18 @@ async def test_performance(driver): assert metrics["DevToolsCommandDuration"] > 0 assert metrics["Frames"] == 12 - @pytest.mark.trio -async def test_basic_auth(driver): +async def test_set_cookie(driver): async with driver.bidi_connection() as connection: - await connection.session.execute(connection.devtools.network.enable()) - - credentials = base64.b64encode("admin:admin".encode()).decode() - auth = {'authorization': 'Basic ' + credentials} - - await connection.session.execute(connection.devtools.network.set_extra_http_headers(Headers(auth))) + execution = connection.devtools.network.set_cookie( + name="cheese", + value="gouda", + domain="www.selenium.dev", + secure=True + ) + await connection.session.execute(execution) - driver.get('https://the-internet.herokuapp.com/basic_auth') + driver.get("https://www.selenium.dev") + cheese = driver.get_cookie("cheese") - success = driver.find_element(by=By.TAG_NAME, value='p') - assert success.text == 'Congratulations! You must have the proper credentials.' + assert cheese["value"] == "gouda" diff --git a/examples/python/tests/bidi/cdp/test_script.py b/examples/python/tests/bidi/cdp/test_script.py new file mode 100644 index 000000000000..c547de1d25da --- /dev/null +++ b/examples/python/tests/bidi/cdp/test_script.py @@ -0,0 +1,13 @@ +import pytest +from selenium.webdriver.common.by import By +from selenium.webdriver.common.log import Log + + +@pytest.mark.trio +async def test_mutation(driver): + async with driver.bidi_connection() as session: + async with Log(driver, session).mutation_events() as event: + driver.get('https://www.selenium.dev/selenium/web/dynamic.html') + driver.find_element(By.ID, "reveal").click() + + assert event["element"] == driver.find_element(By.ID, "revealed") diff --git a/examples/python/tests/bidi/test_logging.py b/examples/python/tests/bidi/test_logging.py new file mode 100644 index 000000000000..c2269ba28379 --- /dev/null +++ b/examples/python/tests/bidi/test_logging.py @@ -0,0 +1,51 @@ +import pytest +from selenium.webdriver.common.by import By +from selenium.webdriver.support.wait import WebDriverWait + + +@pytest.mark.driver_type("bidi") +def test_add_console_log_handler(driver): + driver.get('https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html') + log_entries = [] + + driver.script.add_console_message_handler(log_entries.append) + + driver.find_element(By.ID, "consoleLog").click() + WebDriverWait(driver, 5).until(lambda _: log_entries) + assert log_entries[0].text == "Hello, world!" + + +@pytest.mark.driver_type("bidi") +def test_remove_console_log_handler(driver): + driver.get('https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html') + log_entries = [] + + id = driver.script.add_console_message_handler(log_entries.append) + driver.script.remove_console_message_handler(id) + + driver.find_element(By.ID, "consoleLog").click() + assert len(log_entries) == 0 + + +@pytest.mark.driver_type("bidi") +def test_add_js_exception_handler(driver): + driver.get('https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html') + log_entries = [] + + driver.script.add_javascript_error_handler(log_entries.append) + + driver.find_element(By.ID, "jsException").click() + WebDriverWait(driver, 5).until(lambda _: log_entries) + assert log_entries[0].text == "Error: Not working" + + +@pytest.mark.driver_type("bidi") +def test_remove_js_exception_handler(driver): + driver.get('https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html') + log_entries = [] + + id = driver.script.add_javascript_error_handler(log_entries.append) + driver.script.remove_javascript_error_handler(id) + + driver.find_element(By.ID, "consoleLog").click() + assert len(log_entries) == 0 diff --git a/examples/python/tests/bidirectional/chrome_devtools/test_cdp_endpoint.py b/examples/python/tests/bidirectional/chrome_devtools/test_cdp_endpoint.py deleted file mode 100644 index 85f3b295d439..000000000000 --- a/examples/python/tests/bidirectional/chrome_devtools/test_cdp_endpoint.py +++ /dev/null @@ -1,44 +0,0 @@ -import base64 - -from selenium.webdriver.common.by import By - - -def test_set_cookie(driver): - cookie = {'name': 'cheese', - 'value': 'gouda', - 'domain': 'www.selenium.dev', - 'secure': True} - - driver.execute_cdp_cmd('Network.setCookie', cookie) - - driver.get('https://www.selenium.dev') - cheese = driver.get_cookie(cookie['name']) - - assert cheese['value'] == 'gouda' - - -def test_performance(driver): - driver.get('https://www.selenium.dev/selenium/web/frameset.html') - - driver.execute_cdp_cmd('Performance.enable', {}) - - metric_list = driver.execute_cdp_cmd('Performance.getMetrics', {})["metrics"] - - metrics = {metric["name"]: metric["value"] for metric in metric_list} - - assert metrics["DevToolsCommandDuration"] > 0 - assert metrics["Frames"] == 12 - - -def test_basic_auth(driver): - driver.execute_cdp_cmd("Network.enable", {}) - - credentials = base64.b64encode("admin:admin".encode()).decode() - headers = {'headers': {'authorization': 'Basic ' + credentials}} - - driver.execute_cdp_cmd('Network.setExtraHTTPHeaders', headers) - - driver.get('https://the-internet.herokuapp.com/basic_auth') - - success = driver.find_element(by=By.TAG_NAME, value='p') - assert success.text == 'Congratulations! You must have the proper credentials.' diff --git a/examples/python/tests/bidirectional/webdriver_bidi/test_browsing_context.py b/examples/python/tests/bidirectional/webdriver_bidi/test_browsing_context.py deleted file mode 100644 index 53b695b6fc83..000000000000 --- a/examples/python/tests/bidirectional/webdriver_bidi/test_browsing_context.py +++ /dev/null @@ -1,2 +0,0 @@ -from selenium import webdriver - diff --git a/examples/python/tests/bidirectional/webdriver_bidi/test_log.py b/examples/python/tests/bidirectional/webdriver_bidi/test_log.py deleted file mode 100644 index 53b695b6fc83..000000000000 --- a/examples/python/tests/bidirectional/webdriver_bidi/test_log.py +++ /dev/null @@ -1,2 +0,0 @@ -from selenium import webdriver - diff --git a/examples/python/tests/conftest.py b/examples/python/tests/conftest.py index 5f49c94a1dc8..a91c1928f3c4 100644 --- a/examples/python/tests/conftest.py +++ b/examples/python/tests/conftest.py @@ -13,8 +13,18 @@ @pytest.fixture(scope='function') -def driver(): - driver = webdriver.Chrome() +def driver(request): + marker = request.node.get_closest_marker("driver_type") + driver_type = marker.args[0] if marker else None + + if driver_type == "bidi": + options = webdriver.ChromeOptions() + options.enable_bidi = True + driver = webdriver.Chrome(options=options) + elif driver_type == "firefox": + driver = webdriver.Firefox() + else: + driver = webdriver.Chrome() yield driver @@ -23,7 +33,7 @@ def driver(): @pytest.fixture(scope='function') def chromedriver_bin(): - service = webdriver.chrome.service.Service() + service = webdriver.ChromeService() options = webdriver.ChromeOptions() options.browser_version = 'stable' yield webdriver.common.driver_finder.DriverFinder(service=service, options=options).get_driver_path() @@ -31,7 +41,7 @@ def chromedriver_bin(): @pytest.fixture(scope='function') def chrome_bin(): - service = webdriver.chrome.service.Service() + service = webdriver.ChromeService() options = webdriver.ChromeOptions() options.browser_version = 'stable' yield webdriver.common.driver_finder.DriverFinder(service=service, options=options).get_browser_path() @@ -39,7 +49,7 @@ def chrome_bin(): @pytest.fixture(scope='function') def edge_bin(): - service = webdriver.edge.service.Service() + service = webdriver.EdgeService() options = webdriver.EdgeOptions() options.browser_version = 'stable' yield webdriver.common.driver_finder.DriverFinder(service=service, options=options).get_browser_path() @@ -47,7 +57,7 @@ def edge_bin(): @pytest.fixture(scope='function') def firefox_bin(): - service = webdriver.firefox.service.Service() + service = webdriver.FirefoxService() options = webdriver.FirefoxOptions() options.browser_version = 'stable' yield webdriver.common.driver_finder.DriverFinder(service=service, options=options).get_browser_path() diff --git a/examples/ruby/spec/bidi/cdp/cdp_spec.rb b/examples/ruby/spec/bidi/cdp/cdp_spec.rb new file mode 100644 index 000000000000..fa2d82f14767 --- /dev/null +++ b/examples/ruby/spec/bidi/cdp/cdp_spec.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'Logging' do + let(:driver) { start_session } + + it 'sets cookie' do + driver.execute_cdp('Network.setCookie', + name: 'cheese', + value: 'gouda', + domain: 'www.selenium.dev', + secure: true) + + driver.get('https://www.selenium.dev') + cheese = driver.manage.cookie_named('cheese') + + expect(cheese[:value]).to eq 'gouda' + end +end diff --git a/examples/ruby/spec/bidi/cdp/logging_spec.rb b/examples/ruby/spec/bidi/cdp/logging_spec.rb new file mode 100644 index 000000000000..c92f924faccf --- /dev/null +++ b/examples/ruby/spec/bidi/cdp/logging_spec.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'Logging' do + let(:driver) { start_session } + + it 'listens for console logs' do + driver.get('https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html') + + logs = [] + driver.on_log_event(:console) { |log| logs << log.args.first } + + driver.find_element(id: 'consoleLog').click + driver.find_element(id: 'consoleError').click + + Selenium::WebDriver::Wait.new.until { logs.size > 1 } + expect(logs).to include 'Hello, world!' + expect(logs).to include 'I am console error' + end + + it 'listens for js exception' do + driver.get('https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html') + + exceptions = [] + driver.on_log_event(:exception) { |exception| exceptions << exception } + + driver.find_element(id: 'jsException').click + + Selenium::WebDriver::Wait.new.until { exceptions.any? } + expect(exceptions.first&.description).to include 'Error: Not working' + end +end diff --git a/examples/ruby/spec/bidirectional/chrome_devtools/cdp_api_spec.rb b/examples/ruby/spec/bidi/cdp/network_spec.rb similarity index 57% rename from examples/ruby/spec/bidirectional/chrome_devtools/cdp_api_spec.rb rename to examples/ruby/spec/bidi/cdp/network_spec.rb index 3974cd0ae0fa..c9a818917702 100644 --- a/examples/ruby/spec/bidirectional/chrome_devtools/cdp_api_spec.rb +++ b/examples/ruby/spec/bidi/cdp/network_spec.rb @@ -2,26 +2,58 @@ require 'spec_helper' -RSpec.describe 'Chrome DevTools' do +RSpec.describe 'Network' do let(:driver) { start_session } - it 'sets cookie' do - driver.devtools.network.set_cookie(name: 'cheese', - value: 'gouda', - domain: 'www.selenium.dev', - secure: true) + it 'does basic authentication' do + driver.register(username: 'admin', + password: 'admin', + uri: /herokuapp/) - driver.get('https://www.selenium.dev') - cheese = driver.manage.cookie_named('cheese') + driver.get('https://the-internet.herokuapp.com/basic_auth') - expect(cheese[:value]).to eq 'gouda' + expect(driver.find_element(tag_name: 'p').text).to eq('Congratulations! You must have the proper credentials.') + end + + it 'records network response' do + content_type = [] + driver.intercept do |request, &continue| + continue.call(request) do |response| + content_type << response.headers['content-type'] + end + end + + driver.get('https://www.selenium.dev/selenium/web/blank.html') + expect(content_type.first).to eq('text/html; charset=utf-8') + end + + it 'transforms network response' do + driver.intercept do |request, &continue| + continue.call(request) do |response| + response.body = 'Creamy, delicious cheese!' if request.url.include?('blank') + end + end + + driver.get('https://www.selenium.dev/selenium/web/blank.html') + expect(driver.find_element(tag_name: 'body').text).to eq('Creamy, delicious cheese!') + end + + it 'intercepts network request' do + driver.intercept do |request, &continue| + uri = URI(request.url) + request.url = uri.to_s.gsub('one', 'two') if uri.path&.end_with?('one.js') + continue.call(request) + end + + driver.get('https://www.selenium.dev/selenium/web/devToolsRequestInterceptionTest.html') + driver.find_element(tag_name: 'button').click + expect(driver.find_element(id: 'result').text).to eq('two') end it 'gets performance metrics' do driver.get('https://www.selenium.dev/selenium/web/frameset.html') driver.devtools.performance.enable - metric_list = driver.devtools.performance.get_metrics.dig('result', 'metrics') metrics = metric_list.each_with_object({}) do |metric, hash| @@ -32,32 +64,16 @@ expect(metrics['Frames']).to eq 12 end - it 'does basic authentication' do - driver.devtools.network.enable - - credentials = Base64.strict_encode64('admin:admin') - - driver.devtools.network.set_extra_http_headers(headers: {authorization: "Basic #{credentials}"}) - - driver.get('https://the-internet.herokuapp.com/basic_auth') - - expect(driver.find_element(tag_name: 'p').text).to eq('Congratulations! You must have the proper credentials.') - end - - it 'listens for console logs' do - driver.get('https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html') - - driver.devtools.runtime.enable - - logs = [] - driver.devtools.runtime.on(:console_api_called) do |params| - logs << params['args'].first['value'] - end + it 'sets cookie' do + driver.devtools.network.set_cookie(name: 'cheese', + value: 'gouda', + domain: 'www.selenium.dev', + secure: true) - driver.find_element(id: 'consoleLog').click + driver.get('https://www.selenium.dev') + cheese = driver.manage.cookie_named('cheese') - Selenium::WebDriver::Wait.new.until { logs.any? } - expect(logs).to include 'Hello, world!' + expect(cheese[:value]).to eq 'gouda' end it 'waits for downloads', except: {platform: :windows} do diff --git a/examples/ruby/spec/bidi/cdp/script_spec.rb b/examples/ruby/spec/bidi/cdp/script_spec.rb new file mode 100644 index 000000000000..77575404cd6e --- /dev/null +++ b/examples/ruby/spec/bidi/cdp/script_spec.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'Script' do + let(:driver) { start_session } + + it 'pins script' do + driver.get('https://www.selenium.dev/selenium/web/xhtmlTest.html') + element = driver.find_element(id: 'id1') + + key = driver.pin_script('return arguments;') + arguments = driver.execute_script(key, 1, true, element) + + expect(arguments).to eq([1, true, element]) + end + + it 'gets mutated elements' do + driver.get 'https://www.selenium.dev/selenium/web/dynamic.html' + + mutations = [] + driver.on_log_event(:mutation) { |mutation| mutations << mutation.element } + + driver.find_element(id: 'reveal').click + Selenium::WebDriver::Wait.new(timeout: 30).until { mutations.any? } + + expect(mutations).to include(driver.find_element(id: 'revealed')) + end +end diff --git a/examples/ruby/spec/bidi/logging_spec.rb b/examples/ruby/spec/bidi/logging_spec.rb new file mode 100644 index 000000000000..b07b93342628 --- /dev/null +++ b/examples/ruby/spec/bidi/logging_spec.rb @@ -0,0 +1,50 @@ +require 'spec_helper' + +RSpec.describe 'Logging' do + let(:driver) { start_bidi_session } + let(:wait) { Selenium::WebDriver::Wait.new(timeout: 2) } + + it 'adds console message handler' do + driver.navigate.to 'https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html' + log_entries = [] + + driver.script.add_console_message_handler { |log| log_entries << log } + + driver.find_element(id: 'consoleLog').click + wait.until { log_entries.any? } + expect(log_entries.first&.text).to eq 'Hello, world!' + end + + it 'removes console message handler' do + driver.navigate.to 'https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html' + log_entries = [] + + id = driver.script.add_console_message_handler { |log| log_entries << log } + driver.script.remove_console_message_handler(id) + + driver.find_element(id: 'consoleLog').click + expect(log_entries).to be_empty + end + + it 'adds JavaScript error handler' do + driver.navigate.to 'https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html' + log_entries = [] + + driver.script.add_javascript_error_handler { |error| log_entries << error } + + driver.find_element(id: 'jsException').click + wait.until { log_entries.any? } + expect(log_entries.first&.text).to eq 'Error: Not working' + end + + it 'removes JavaScript error handler' do + driver.navigate.to 'https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html' + log_entries = [] + + id = driver.script.add_javascript_error_handler { |error| log_entries << error } + driver.script.remove_javascript_error_handler(id) + + driver.find_element(id: 'jsException').click + expect(log_entries).to be_empty + end +end diff --git a/examples/ruby/spec/bidirectional/chrome_devtools/bidi_api_spec.rb b/examples/ruby/spec/bidirectional/chrome_devtools/bidi_api_spec.rb deleted file mode 100644 index 68bc6b29ad8e..000000000000 --- a/examples/ruby/spec/bidirectional/chrome_devtools/bidi_api_spec.rb +++ /dev/null @@ -1,100 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe 'BiDi API' do - let(:driver) { start_session } - - it 'does basic authentication' do - driver.register(username: 'admin', - password: 'admin', - uri: /herokuapp/) - - driver.get('https://the-internet.herokuapp.com/basic_auth') - - expect(driver.find_element(tag_name: 'p').text).to eq('Congratulations! You must have the proper credentials.') - end - - it 'pins script' do - driver.get('https://www.selenium.dev/selenium/web/xhtmlTest.html') - element = driver.find_element(id: 'id1') - - key = driver.pin_script('return arguments;') - arguments = driver.execute_script(key, 1, true, element) - - expect(arguments).to eq([1, true, element]) - end - - it 'gets mutated elements' do - driver.get 'https://www.selenium.dev/selenium/web/dynamic.html' - - mutations = [] - driver.on_log_event(:mutation) { |mutation| mutations << mutation.element } - - driver.find_element(id: 'reveal').click - Selenium::WebDriver::Wait.new(timeout: 30).until { mutations.any? } - - expect(mutations).to include(driver.find_element(id: 'revealed')) - end - - it 'listens for console logs' do - driver.get('https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html') - - logs = [] - driver.on_log_event(:console) { |log| logs << log.args.first } - - driver.find_element(id: 'consoleLog').click - driver.find_element(id: 'consoleError').click - - Selenium::WebDriver::Wait.new.until { logs.size > 1 } - expect(logs).to include 'Hello, world!' - expect(logs).to include 'I am console error' - end - - it 'listens for js exception' do - driver.get('https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html') - - exceptions = [] - driver.on_log_event(:exception) { |exception| exceptions << exception } - - driver.find_element(id: 'jsException').click - - Selenium::WebDriver::Wait.new.until { exceptions.any? } - expect(exceptions.first&.description).to include 'Error: Not working' - end - - it 'records network response' do - content_type = [] - driver.intercept do |request, &continue| - continue.call(request) do |response| - content_type << response.headers['content-type'] - end - end - - driver.get('https://www.selenium.dev/selenium/web/blank.html') - expect(content_type.first).to eq('text/html; charset=utf-8') - end - - it 'transforms network response' do - driver.intercept do |request, &continue| - continue.call(request) do |response| - response.body = 'Creamy, delicious cheese!' if request.url.include?('blank') - end - end - - driver.get('https://www.selenium.dev/selenium/web/blank.html') - expect(driver.find_element(tag_name: 'body').text).to eq('Creamy, delicious cheese!') - end - - it 'intercepts network request' do - driver.intercept do |request, &continue| - uri = URI(request.url) - request.url = uri.to_s.gsub('one', 'two') if uri.path&.end_with?('one.js') - continue.call(request) - end - - driver.get('https://www.selenium.dev/selenium/web/devToolsRequestInterceptionTest.html') - driver.find_element(tag_name: 'button').click - expect(driver.find_element(id: 'result').text).to eq('two') - end -end diff --git a/examples/ruby/spec/bidirectional/chrome_devtools/cdp_endpoint_spec.rb b/examples/ruby/spec/bidirectional/chrome_devtools/cdp_endpoint_spec.rb deleted file mode 100644 index 543f8c81fe43..000000000000 --- a/examples/ruby/spec/bidirectional/chrome_devtools/cdp_endpoint_spec.rb +++ /dev/null @@ -1,49 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe 'Execute CDP' do - let(:driver) { start_session } - - it 'sets cookie' do - cookie = {name: 'cheese', - value: 'gouda', - domain: 'www.selenium.dev', - secure: true} - - driver.execute_cdp('Network.setCookie', **cookie) - - driver.get('https://www.selenium.dev') - cheese = driver.manage.cookie_named(cookie[:name]) - - expect(cheese[:value]).to eq 'gouda' - end - - it 'gets performance metrics' do - driver.get('https://www.selenium.dev/selenium/web/frameset.html') - - driver.execute_cdp('Performance.enable') - - metric_list = driver.execute_cdp('Performance.getMetrics')['metrics'] - - metrics = metric_list.each_with_object({}) do |metric, hash| - hash[metric['name']] = metric['value'] - end - - expect(metrics['DevToolsCommandDuration']).to be > 0 - expect(metrics['Frames']).to eq 12 - end - - it 'sets basic authentication' do - driver.execute_cdp('Network.enable') - - credentials = Base64.strict_encode64('admin:admin') - headers = {authorization: "Basic #{credentials}"} - - driver.execute_cdp('Network.setExtraHTTPHeaders', headers: headers) - - driver.get('https://the-internet.herokuapp.com/basic_auth') - - expect(driver.find_element(tag_name: 'p').text).to eq('Congratulations! You must have the proper credentials.') - end -end diff --git a/examples/ruby/spec/bidirectional/webdriver_bidi/browsing_context_spec.rb b/examples/ruby/spec/bidirectional/webdriver_bidi/browsing_context_spec.rb deleted file mode 100644 index 17500df33484..000000000000 --- a/examples/ruby/spec/bidirectional/webdriver_bidi/browsing_context_spec.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe 'Browsing Context' do - it 'opens a window without browsing context' - it 'opens a window with browsing context' - it 'opens a tab without browsing context' - it 'opens a tab with browsing context' - it 'uses existing window' - it 'navigates to url with readiness state' - it 'navigates to url without readiness state' - it 'gets browsing context tree with depth' - it 'gets browsing context tree without depth' - it 'gets all browsing contexts' - it 'closes a tab' - it 'closes a window' -end diff --git a/examples/ruby/spec/bidirectional/webdriver_bidi/log_spec.rb b/examples/ruby/spec/bidirectional/webdriver_bidi/log_spec.rb deleted file mode 100644 index cde9854b1e4e..000000000000 --- a/examples/ruby/spec/bidirectional/webdriver_bidi/log_spec.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe 'Log Inspector' do - it 'listens to console log' - it 'gets JS exceptions' - it 'gets JS logs' -end diff --git a/examples/ruby/spec/spec_helper.rb b/examples/ruby/spec/spec_helper.rb index 902e708d8c6c..20273e7019c5 100644 --- a/examples/ruby/spec/spec_helper.rb +++ b/examples/ruby/spec/spec_helper.rb @@ -31,6 +31,11 @@ def start_session @driver = Selenium::WebDriver.for :chrome end + def start_bidi_session + options = Selenium::WebDriver::Chrome::Options.new(web_socket_url: true) + @driver = Selenium::WebDriver.for :chrome, options: options + end + def start_firefox options = Selenium::WebDriver::Options.firefox(timeouts: {implicit: 1500}) @driver = Selenium::WebDriver.for :firefox, options: options diff --git a/website_and_docs/content/blog/2021/announcing-selenium-4.md b/website_and_docs/content/blog/2021/announcing-selenium-4.md index 5648e02ba91e..9747b6f3f9ef 100644 --- a/website_and_docs/content/blog/2021/announcing-selenium-4.md +++ b/website_and_docs/content/blog/2021/announcing-selenium-4.md @@ -98,7 +98,7 @@ our users. **We hope you enjoy Selenium 4, and we can’t wait to see what you do with it!** -[auth]: /documentation/webdriver/bidirectional/chrome_devtools/bidi_api/#basic-authentication +[auth]: /documentation/webdriver/bidi/cdp/network/#basic-authentication [browserstack]: https://www.browserstack.com/ [chromium]: https://www.chromium.org/Home [docker]: https://hub.docker.com/u/selenium @@ -106,8 +106,8 @@ with it!** [firefox]: https://www.mozilla.org/en-GB/firefox/new/ [github]: https://github.com/SeleniumHQ/selenium/releases/tag/selenium-4.0.0 [grid]: /documentation/grid/ -[js errors]: /documentation/webdriver/bidirectional/chrome_devtools/bidi_api/#javascript-exceptions -[mutation]: /documentation/webdriver/bidirectional/chrome_devtools/bidi_api/#mutation-observation +[js errors]: /documentation/webdriver/bidi/cdp/bidi_api/#javascript-exceptions +[mutation]: /documentation/webdriver/bidi/cdp/bidi_api/#mutation-observation [otel]: https://opentelemetry.io [pr]: https://github.com/SeleniumHQ/selenium/pulls [relative locators]: /documentation/webdriver/locating_elements/#relative-locators diff --git a/website_and_docs/content/blog/2024/selenium-4-22-released.md b/website_and_docs/content/blog/2024/selenium-4-22-released.md new file mode 100644 index 000000000000..a4d7f5612e2b --- /dev/null +++ b/website_and_docs/content/blog/2024/selenium-4-22-released.md @@ -0,0 +1,151 @@ +--- +title: "Selenium 4.22 Released!" +linkTitle: "Selenium 4.22 Released!" +date: 2024-05-16 +tags: ["selenium"] +categories: ["releases"] +author: Titus Fortner [@titusfortner](https://titusfortner.com) +description: > + Today we're happy to announce that Selenium 4.22 has been released! +--- + +We're very happy to announce the release of Selenium 4.22.0 for +Javascript, Ruby, Python, .NET, Java and the Grid! +Links to everything can be found on our [downloads page][downloads]. + +### Highlights + + * Selenium has at least [2.6 active users](https://plausible.io/manager.selenium.dev) in the last 30 days. 200k more than last month! + * All information we collect is publicly available. + * The numbers only represent users who have Selenium Manager enabled and are using Selenium v4.17 or greater. + * Python, Chrome and Windows all see the majority of use. +* Chrome DevTools support is now: v124, v125, and v126 (Firefox still uses v85 for all versions) +* The first implementations of the new [BiDi API](https://www.selenium.dev/documentation/webdriver/bidi/logging) +have rolled out in Ruby, Python and JavaScript + +#### Noteworthy changes per language + + * Java + * Enabling BiDi can now be accomplished by calling `enableBiDi()` on an Options class instance. + * Video file name in Dynamic Grid can be seet with `se:videoName` capability. + * [See all changes](https://github.com/SeleniumHQ/selenium/blob/trunk/java/CHANGELOG) + +
+ + * JavaScript + * BiDi API for console logging and JavaScript errors has been implemented. + * Additional BiDi implementations. + * [See all changes](https://github.com/SeleniumHQ/selenium/blob/trunk/javascript/node/selenium-webdriver/CHANGES.md) + +
+ + * .NET + * The .NET bindings have started to roll out asynchronous methods. + * The synchronous methods will still be supported, but they will call the async methods "under the hood." + * This release adds asynchronous methods to the Navigation class. + * [See all changes](https://github.com/SeleniumHQ/selenium/blob/trunk/dotnet/CHANGELOG) + +
+ + * Python + * This release implements a new way of working with Chrome Devtools Protocol + * The previous implementation requires async/await pattern, so it was not backwards compatible. + * The new implementation is backwards compatible and executes async code in separate threads. + * Updated the webkitgtk and wpewebkit driver implementations. + * Enabling BiDi can now be accomplished by setting the `enable_bidi()` property of an Options class instance to `True`. + * BiDi API for console logging and JavaScript errors has been implemented. + * [See all changes](https://github.com/SeleniumHQ/selenium/blob/trunk/py/CHANGES) + +
+ + * Ruby + * Implemented a toggle for BiDi and Classic implementations. + * BiDi API for console logging and JavaScript errors has been implemented. + * [See all changes](https://github.com/SeleniumHQ/selenium/blob/trunk/rb/CHANGES) + + +
+ + * Rust + * Added the ability to stream logging information to stdout instead of after execution complete. + * Improved binary location on Windows with native Rust methods. + * [See all changes](https://github.com/SeleniumHQ/selenium/blob/trunk/rust/CHANGELOG.md) + +### Contributors + +**Special shout-out to everyone who helped the Selenium Team get this release out!** + +#### [Selenium](https://github.com/SeleniumHQ/selenium) + +
+
+
+{{< gh-user "https://api.github.com/users/3dprogramin" >}} +{{< gh-user "https://api.github.com/users/VietND96" >}} +{{< gh-user "https://api.github.com/users/aguspe" >}} +{{< gh-user "https://api.github.com/users/bgermann" >}} +{{< gh-user "https://api.github.com/users/Earlopain" >}} +{{< gh-user "https://api.github.com/users/iampopovich" >}} +{{< gh-user "https://api.github.com/users/millin" >}} +{{< gh-user "https://api.github.com/users/sbabcoc" >}} +{{< gh-user "https://api.github.com/users/vlad8x8" >}} +{{< gh-user "https://api.github.com/users/yuzawa-san" >}} +
+
+
+ + +#### [Selenium Docs & Website](https://github.com/SeleniumHQ/seleniumhq.github.io) + +
+
+
+{{< gh-user "https://api.github.com/users/alaahong" >}} +{{< gh-user "https://api.github.com/users/aguspe" >}} +{{< gh-user "https://api.github.com/users/digitalvoice-nz" >}} +{{< gh-user "https://api.github.com/users/josh-pinwheelapi" >}} +{{< gh-user "https://api.github.com/users/pallavigitwork" >}} +{{< gh-user "https://api.github.com/users/Pexpe" >}} +{{< gh-user "https://api.github.com/users/sangcnguyen" >}} +
+
+
+ +#### [Docker Selenium](https://github.com/SeleniumHQ/docker-selenium) + +
+
+
+{{< gh-user "https://api.github.com/users/VietND96" >}} +
+
+
+ +#### [Selenium Team Members][team] + +**Thanks as well to all the team members who contributed to this release:** + +
+
+
+{{< gh-user "https://api.github.com/users/AutomatedTester" >}} +{{< gh-user "https://api.github.com/users/bonigarcia" >}} +{{< gh-user "https://api.github.com/users/diemol" >}} +{{< gh-user "https://api.github.com/users/harsha509" >}} +{{< gh-user "https://api.github.com/users/joerg1985" >}} +{{< gh-user "https://api.github.com/users/p0deje" >}} +{{< gh-user "https://api.github.com/users/pujagani" >}} +{{< gh-user "https://api.github.com/users/shs96c" >}} +{{< gh-user "https://api.github.com/users/titusfortner" >}} +
+
+
+ +Stay tuned for updates by following SeleniumHQ on [X (Formerly Twitter)](https://twitter.com/seleniumhq) or [LinkedIn](https://www.linkedin.com/company/selenium/)! + +Happy automating! + +[downloads]: /downloads +[bindings]: /downloads#bindings +[team]: /project/structure +[BiDi]: https://github.com/w3c/webdriver-bidi diff --git a/website_and_docs/content/documentation/webdriver/bidi/_index.en.md b/website_and_docs/content/documentation/webdriver/bidi/_index.en.md new file mode 100644 index 000000000000..a37413b7fc1a --- /dev/null +++ b/website_and_docs/content/documentation/webdriver/bidi/_index.en.md @@ -0,0 +1,41 @@ +--- +title: "BiDirectional functionality" +linkTitle: "BiDi" +weight: 16 +aliases: [ +"/documentation/en/webdriver/bidi_apis/", +"/documentation/webdriver/bidi_apis/", +"/documentation/webdriver/bidirectional/bidi_api_remotewebdriver", +"/documentation/webdriver/bidirectional/webdriver_bidi", +"/documentation/webdriver/bidirectional/webdriver_bidi/browsing_context", +"/documentation/webdriver/bidirectional/webdriver_bidi/input" +] +--- + +BiDirectional means that communication is happening in two directions simultaneously. +The traditional WebDriver model involves strict request/response commands which only allows for communication to +happen in one direction at any given time. In most cases this is what you want; it ensures that the browser is +doing the expected things in the right order, but there are a number of interesting things that can be done with +asynchronous interactions. + +This functionality is currently available in a limited fashion with the [Chrome DevTools Protocol] (CDP), +but to address some of its drawbacks, the Selenium team, along with the major +browser vendors, have worked to create the new [WebDriver BiDi Protocol](https://w3c.github.io/webdriver-bidi/). +This specification aims to create a stable, cross-browser API that leverages bidirectional +communication for enhanced browser automation and testing functionality, +including streaming events from the user agent to the controlling software via WebSockets. +Users will be able to listen for and record or manipulate events as they happen during the course of a Selenium session. + +To use WebDriver BiDi, you must [enable it in Options](http://www.example.com) + +Note that Selenium is updating its entire implementation from WebDriver Classic to WebDriver BiDi (while +maintaining backwards compatibility as much as possible), but this section of documentation focuses on the new +functionality that bidirectional communication allows. +The low-level BiDi domains will be accessible in the code to the end user, but the goal is to provide +high-level APIs that are straightforward methods of real-world use cases. As such, the low-level +components will not be documented, and this section will focus only on the user-friendly +features that we encourage users to take advantage of. + +If there is additional functionality you'd like to see, please raise a +[feature request](https://github.com/SeleniumHQ/selenium/issues/new?assignees=&labels=&template=feature.md). + diff --git a/website_and_docs/content/documentation/webdriver/bidi/cdp/_index.en.md b/website_and_docs/content/documentation/webdriver/bidi/cdp/_index.en.md new file mode 100644 index 000000000000..198e6d8c95f2 --- /dev/null +++ b/website_and_docs/content/documentation/webdriver/bidi/cdp/_index.en.md @@ -0,0 +1,73 @@ +--- +title: "Chrome DevTools Protocol" +linkTitle: "CDP" +weight: 10 +description: > + Examples of working with Chrome DevTools Protocol in Selenium. + CDP support is temporary until WebDriver BiDi has been implemented. +aliases: [ +"/documentation/en/support_packages/chrome_devtools/", +"/documentation/support_packages/chrome_devtools/", +"/documentation/webdriver/bidirectional/chrome_devtools/", +"documentation/webdriver/bidirectional/chrome_devtools/cdp_endpoint/", +"documentation/webdriver/bidirectional/chrome_devtools/bidi_api/", +"documentation/webdriver/bidirectional/chrome_devtools/cdp_api/", +] +--- + +Many browsers provide "DevTools" -- a set of tools that are integrated with the browser that +developers can use to debug web apps and explore the performance of their pages. Google Chrome's +DevTools make use of a protocol called the Chrome DevTools Protocol (or "CDP" for short). +As the name suggests, this is not designed for testing, nor to have a stable API, so functionality +is highly dependent on the version of the browser. + +Selenium is working to implement a standards-based, cross-browser, stable alternative to CDP called +[WebDriver BiDi]. Until the support for this new protocol has finished, Selenium plans to provide access +to CDP features where applicable. + +### Using Chrome DevTools Protocol with Selenium + +Chrome and Edge have a method to send basic CDP commands. +This does not work for features that require bidirectional communication, and you need to know what domains to enable when +and the exact names and types of domains/methods/parameters. + +{{< tabpane text=true >}} +{{% tab header="Java" %}} +{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidi/cdp/CdpTest.java#L22-L27" >}} +{{% /tab %}} +{{% tab header="Python" %}} +{{< gh-codeblock path="/examples/python/tests/bidi/cdp/test_cdp.py#L2-L7" >}} +{{% /tab %}} +{{% tab header="CSharp" %}} +{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/BiDi/CDP/CDPTest.cs#L14-L21" >}} +{{% /tab %}} +{{% tab header="Ruby" %}} +{{< gh-codeblock path="/examples/ruby/spec/bidi/cdp/cdp_spec.rb#L9-L13" >}} +{{% /tab %}} +{{% tab header="JavaScript" %}} +{{< badge-code >}} +{{% /tab %}} +{{% tab header="Kotlin" %}} +{{< badge-code >}} +{{% /tab %}} +{{< /tabpane >}} + + +To make working with CDP easier, and to provide access to the more advanced features, Selenium bindings +automatically generate classes and methods for the most common domains. +CDP methods and implementations can change from version to version, though, so you want to keep the +version of Chrome and the version of DevTools matching. Selenium supports the 3 most +recent versions of Chrome at any given time, +and tries to time releases to ensure that access to the latest versions are available. + +This limitation provides additional challenges for several bindings, where dynamically +generated CDP support requires users to regularly update their code to reference the proper version of CDP. +In some cases an idealized implementation has been created that should work for any version of CDP without the +user needing to change their code, but that is not always available. + +Examples of how to use CDP in your Selenium tests can be found on the following pages, but +we want to call out a couple commonly cited examples that are of limited practical value. +* **Geo Location** — almost all sites use the IP address to determine physical location, +so setting an emulated geolocation rarely has the desired effect. +* **Overriding Device Metrics** — Chrome provides a great API for setting [Mobile Emulation](https://chromedriver.chromium.org/mobile-emulation) +in the Options classes, which is generally superior to attempting to do this with CDP. diff --git a/website_and_docs/content/documentation/webdriver/bidi/cdp/logging.en.md b/website_and_docs/content/documentation/webdriver/bidi/cdp/logging.en.md new file mode 100644 index 000000000000..e2583b945e73 --- /dev/null +++ b/website_and_docs/content/documentation/webdriver/bidi/cdp/logging.en.md @@ -0,0 +1,59 @@ +--- +title: "Chrome DevTools Logging Features" +linkTitle: "Logging" +weight: 2 +description: > + Logging features using CDP. +--- + +{{% pageinfo color="warning" %}} +While Selenium 4 provides direct access to the Chrome DevTools Protocol, these +methods will eventually be removed when WebDriver BiDi implemented. +{{% /pageinfo %}} + + +## Console Logs + +{{< tabpane text=true >}} +{{% tab header="Java" %}} +{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidi/cdp/LoggingTest.java#L31" >}} +{{% /tab %}} +{{% tab header="Python" %}} +{{< gh-codeblock path="/examples/python/tests/bidi/cdp/test_logs.py#L11-12" >}} +{{% /tab %}} +{{% tab header="CSharp" %}} +{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/BiDi/CDP/LoggingTest.cs#L19-L25" >}} +{{% /tab %}} +{{% tab header="Ruby" %}} +{{< gh-codeblock path="/examples/ruby/spec/bidi/cdp/logging_spec.rb#L12" >}} +{{% /tab %}} +{{% tab header="JavaScript" %}} +{{< badge-implementation >}} +{{% /tab %}} +{{% tab header="Kotlin" %}} +{{< badge-code >}} +{{% /tab %}} +{{< /tabpane >}} + +## JavaScript Exceptions + +{{< tabpane text=true >}} +{{% tab header="Java" %}} +{{< badge-implementation >}} +{{% /tab %}} +{{% tab header="Python" %}} +{{< gh-codeblock path="/examples/python/tests/bidi/cdp/test_logs.py#L22-L23" >}} +{{% /tab %}} +{{% tab header="CSharp" %}} +{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/BiDi/CDP/LoggingTest.cs#L41-L47" >}} +{{% /tab %}} +{{% tab header="Ruby" %}} +{{< gh-codeblock path="/examples/ruby/spec/bidi/cdp/logging_spec.rb#L26" >}} +{{% /tab %}} +{{% tab header="JavaScript" %}} +{{< badge-implementation >}} +{{% /tab %}} +{{% tab header="Kotlin" %}} +{{< badge-code >}} +{{% /tab %}} +{{< /tabpane >}} diff --git a/website_and_docs/content/documentation/webdriver/bidi/cdp/network.en.md b/website_and_docs/content/documentation/webdriver/bidi/cdp/network.en.md new file mode 100644 index 000000000000..777c3c978709 --- /dev/null +++ b/website_and_docs/content/documentation/webdriver/bidi/cdp/network.en.md @@ -0,0 +1,187 @@ +--- +title: "Chrome DevTools Network Features" +linkTitle: "Network" +weight: 4 +description: > + Network features using CDP. +--- + +{{% pageinfo color="warning" %}} +While Selenium 4 provides direct access to the Chrome DevTools Protocol, these +methods will eventually be removed when WebDriver BiDi implemented. +{{% /pageinfo %}} + + +## Basic authentication + +Some applications make use of browser authentication to secure pages. +It used to be common to handle them in the URL, but browsers stopped supporting this. +With this code you can insert the credentials into the header when necessary + +{{< tabpane text=true >}} +{{% tab header="Java" %}} +{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidi/cdp/NetworkTest.java#L41-L43" >}} +{{% /tab %}} +{{% tab header="Python" %}} +{{< gh-codeblock path="/examples/python/tests/bidi/cdp/test_network.py#L13-15" >}} +{{% /tab %}} +{{% tab header="CSharp" %}} +{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs#L25-L32" >}} +{{% /tab %}} +{{% tab header="Ruby" %}} +{{< gh-codeblock path="/examples/ruby/spec/bidi/cdp/network_spec.rb#L9-L11" >}} +{{% /tab %}} +{{% tab header="JavaScript" %}} +{{< badge-implementation >}} +{{% /tab %}} +{{% tab header="Kotlin" %}} +{{< badge-implementation >}} +{{% /tab %}} +{{< /tabpane >}} + + +## Network Interception + +Both requests and responses can be recorded or transformed. + +#### Response information + +{{< tabpane text=true >}} +{{% tab header="Java" %}} +{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidi/cdp/NetworkTest.java#L56-L65" >}} +{{% /tab %}} +{{% tab header="Python" %}} +{{< badge-implementation >}} +{{% /tab %}} +{{% tab header="CSharp" %}} +{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs#L46-L51" >}} +{{% /tab %}} +{{% tab header="Ruby" %}} +{{< gh-codeblock path="/examples/ruby/spec/bidi/cdp/network_spec.rb#L20-L24" >}} +{{% /tab %}} +{{% tab header="JavaScript" %}} +{{< badge-implementation >}} +{{% /tab %}} +{{% tab header="Kotlin" %}} +{{< badge-code >}} +{{% /tab %}} +{{< /tabpane >}} + +#### Response transformation + +{{< tabpane text=true >}} +{{% tab header="Java" %}} +{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidi/cdp/NetworkTest.java#L75-L85" >}} +{{% /tab %}} +{{% tab header="Python" %}} +{{< badge-implementation >}} +{{% /tab %}} +{{% tab header="CSharp" %}} +{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs#L62-L73" >}} +{{% /tab %}} +{{% tab header="Ruby" %}} +{{< gh-codeblock path="/examples/ruby/spec/bidi/cdp/network_spec.rb#L31-L35" >}} +{{% /tab %}} +{{% tab header="JavaScript" %}} +{{< badge-implementation >}} +{{% /tab %}} +{{% tab header="Kotlin" %}} +{{< badge-code >}} +{{% /tab %}} +{{< /tabpane >}} + + +#### Request interception + +{{< tabpane text=true >}} +{{% tab header="Java" %}} +{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidi/cdp/NetworkTest.java#L97-L110" >}} +{{% /tab %}} +{{% tab header="Python" %}} +{{< badge-implementation >}} +{{% /tab %}} +{{% tab header="CSharp" %}} +{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs#L85-L97" >}} +{{% /tab %}} +{{% tab header="Ruby" %}} +{{< gh-codeblock path="/examples/ruby/spec/bidi/cdp/network_spec.rb#L42-L46" >}} +{{% /tab %}} +{{% tab header="JavaScript" %}} +{{< badge-implementation >}} +{{% /tab %}} +{{% tab header="Kotlin" %}} +{{< badge-code >}} +{{% /tab %}} +{{< /tabpane >}} + + +## Performance Metrics + +{{< tabpane text=true >}} +{{% tab header="Java" %}} +{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidi/cdp/NetworkTest.java#L125-L126" >}} +{{% /tab %}} +{{% tab header="Python" %}} +{{< gh-codeblock path="/examples/python/tests/bidi/cdp/test_network.py#L26-L28" >}} +{{% /tab %}} +{{% tab header="CSharp" %}} +{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs#L114-L118" >}} +{{% /tab %}} +{{% tab header="Ruby" %}} +{{< gh-codeblock path="/examples/ruby/spec/bidi/cdp/network_spec.rb#L56-L57" >}} +{{% /tab %}} +{{% tab header="JavaScript" %}} +{{< badge-implementation >}} +{{% /tab %}} +{{% tab header="Kotlin" %}} +{{< badge-code >}} +{{% /tab %}} +{{< /tabpane >}} + + +## Setting Cookies + +{{< tabpane text=true >}} +{{% tab header="Java" %}} +{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidi/cdp/NetworkTest.java#L142-L157" >}} +{{% /tab %}} +{{% tab header="Python" %}} +{{< gh-codeblock path="/examples/python/tests/bidi/cdp/test_network.py#L37-L44" >}} +{{% /tab %}} +{{% tab header="CSharp" %}} +{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/BiDi/CDP/NetworkTest.cs#L136-L143" >}} +{{% /tab %}} +{{% tab header="Ruby" %}} +{{< gh-codeblock path="/examples/ruby/spec/bidi/cdp/network_spec.rb#L68-L71" >}} +{{% /tab %}} +{{% tab header="JavaScript" %}} +{{< badge-implementation >}} +{{% /tab %}} +{{% tab header="Kotlin" %}} +{{< badge-code >}} +{{% /tab %}} +{{< /tabpane >}} + + +## Waiting for Downloads + +{{< tabpane text=true >}} +{{% tab header="Java" %}} +{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidi/cdp/NetworkTest.java#L171-L176" >}} +{{% /tab %}} +{{% tab header="Python" %}} +{{< badge-implementation >}} +{{% /tab %}} +{{% tab header="CSharp" %}} +{{< badge-implementation >}} +{{% /tab %}} +{{% tab header="Ruby" %}} +{{< gh-codeblock path="/examples/ruby/spec/bidi/cdp/network_spec.rb#L82-L88" >}} +{{% /tab %}} +{{% tab header="JavaScript" %}} +{{< badge-implementation >}} +{{% /tab %}} +{{% tab header="Kotlin" %}} +{{< badge-code >}} +{{% /tab %}} +{{< /tabpane >}} diff --git a/website_and_docs/content/documentation/webdriver/bidi/cdp/script.en.md b/website_and_docs/content/documentation/webdriver/bidi/cdp/script.en.md new file mode 100644 index 000000000000..6b82792f71df --- /dev/null +++ b/website_and_docs/content/documentation/webdriver/bidi/cdp/script.en.md @@ -0,0 +1,59 @@ +--- +title: "Chrome DevTools Script Features" +linkTitle: "Script" +weight: 6 +description: > + Script features using CDP. +--- + +{{% pageinfo color="warning" %}} +While Selenium 4 provides direct access to the Chrome DevTools Protocol, these +methods will eventually be removed when WebDriver BiDi implemented. +{{% /pageinfo %}} + +## Script Pinning + +{{< tabpane text=true >}} +{{% tab header="Java" %}} +{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidi/cdp/ScriptTest.java#L32-L34" >}} +{{% /tab %}} +{{% tab header="Python" %}} +{{< badge-implementation >}} +{{% /tab %}} +{{% tab header="CSharp" %}} +{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/BiDi/CDP/ScriptTest.cs#L21-L22" >}} +{{% /tab %}} +{{% tab header="Ruby" %}} +{{< gh-codeblock path="/examples/ruby/spec/bidi/cdp/script_spec.rb#L12-L13" >}} +{{% /tab %}} +{{% tab header="JavaScript" %}} +{{< badge-implementation >}} +{{% /tab %}} +{{% tab header="Kotlin" %}} +{{< badge-code >}} +{{% /tab %}} +{{< /tabpane >}} + + +## DOM Mutation Handlers + +{{< tabpane text=true >}} +{{% tab header="Java" %}} +{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidi/cdp/NetworkTest.java#L44" >}} +{{% /tab %}} +{{% tab header="Python" %}} +{{< gh-codeblock path="/examples/python/tests/bidi/cdp/test_script.py#L8-L9" >}} +{{% /tab %}} +{{% tab header="CSharp" %}} +{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/BiDi/CDP/ScriptTest.cs#L39-L46" >}} +{{% /tab %}} +{{% tab header="Ruby" %}} +{{< gh-codeblock path="/examples/ruby/spec/bidi/cdp/script_spec.rb#L22" >}} +{{% /tab %}} +{{% tab header="JavaScript" %}} +{{< badge-implementation >}} +{{% /tab %}} +{{% tab header="Kotlin" %}} +{{< badge-code >}} +{{% /tab %}} +{{< /tabpane >}} diff --git a/website_and_docs/content/documentation/webdriver/bidi/logging.en.md b/website_and_docs/content/documentation/webdriver/bidi/logging.en.md new file mode 100644 index 000000000000..257e5f9aab4a --- /dev/null +++ b/website_and_docs/content/documentation/webdriver/bidi/logging.en.md @@ -0,0 +1,118 @@ +--- +title: "WebDriver BiDi Logging Features" +linkTitle: "Logging" +weight: 1 +description: > + These features are related to logging. Because "logging" can refer to so many + different things, these methods are made available via a "script" namespace. +aliases: [ + "/documentation/en/webdriver/bidirectional/bidirectional_w3c/log", + "/documentation/webdriver/bidirectional/webdriver_bidi/log" +] +--- + +Remember that to use WebDriver BiDi, you must [enable it in Options](http://www.example.com) + +## Console Message Handlers + +Record or take actions on `console.log` events. + +### Add Handler + +{{< tabpane text=true >}} +{{< tab header="Java" >}} +{{< badge-implementation >}} +{{< /tab >}} +{{< tab header="Python" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_logging.py#L11" >}} +{{< /tab >}} +{{< tab header="CSharp" >}} +{{< badge-implementation >}} +{{< /tab >}} +{{< tab header="Ruby" >}} +{{< gh-codeblock path="/examples/ruby/spec/bidi/logging_spec.rb#L11" >}} +{{< /tab >}} +{{< tab header="JavaScript" >}} +{{< badge-implementation >}} +{{< /tab >}} +{{< tab header="Kotlin" >}} +{{< badge-implementation >}} +{{< /tab >}} +{{< /tabpane >}} + +### Remove Handler + +You need to store the ID returned when adding the handler to delete it. + +{{< tabpane text=true >}} +{{< tab header="Java" >}} +{{< badge-implementation >}} +{{< /tab >}} +{{< tab header="Python" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_logging.py#L23-24" >}} +{{< /tab >}} +{{< tab header="CSharp" >}} +{{< badge-implementation >}} +{{< /tab >}} +{{< tab header="Ruby" >}} +{{< gh-codeblock path="/examples/ruby/spec/bidi/logging_spec.rb#L22-L23" >}} +{{< /tab >}} +{{< tab header="JavaScript" >}} +{{< badge-implementation >}} +{{< /tab >}} +{{< tab header="Kotlin" >}} +{{< badge-implementation >}} +{{< /tab >}} +{{< /tabpane >}} + +## JavaScript Exception Handlers + +Record or take actions on JavaScript exception events. + +### Add Handler + +{{< tabpane text=true >}} +{{< tab header="Java" >}} +{{< badge-implementation >}} +{{< /tab >}} +{{< tab header="Python" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_logging.py#L35" >}} +{{< /tab >}} +{{< tab header="CSharp" >}} +{{< badge-implementation >}} +{{< /tab >}} +{{< tab header="Ruby" >}} +{{< gh-codeblock path="/examples/ruby/spec/bidi/logging_spec.rb#L33" >}} +{{< /tab >}} +{{< tab header="JavaScript" >}} +{{< badge-implementation >}} +{{< /tab >}} +{{< tab header="Kotlin" >}} +{{< badge-implementation >}} +{{< /tab >}} +{{< /tabpane >}} + +### Remove Handler + +You need to store the ID returned when adding the handler to delete it. + +{{< tabpane text=true >}} +{{< tab header="Java" >}} +{{< badge-implementation >}} +{{< /tab >}} +{{< tab header="Python" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_logging.py#L47-48" >}} +{{< /tab >}} +{{< tab header="CSharp" >}} +{{< badge-implementation >}} +{{< /tab >}} +{{< tab header="Ruby" >}} +{{< gh-codeblock path="/examples/ruby/spec/bidi/logging_spec.rb#L44-L45" >}} +{{< /tab >}} +{{< tab header="JavaScript" >}} +{{< badge-implementation >}} +{{< /tab >}} +{{< tab header="Kotlin" >}} +{{< badge-implementation >}} +{{< /tab >}} +{{< /tabpane >}} diff --git a/website_and_docs/content/documentation/webdriver/bidi/network.en.md b/website_and_docs/content/documentation/webdriver/bidi/network.en.md new file mode 100644 index 000000000000..248ad86b9c82 --- /dev/null +++ b/website_and_docs/content/documentation/webdriver/bidi/network.en.md @@ -0,0 +1,21 @@ +--- +title: "WebDriver BiDi Network Features" +linkTitle: "Network" +weight: 1 +description: > + These features are related to networking, and are made available via a "network" namespace. +aliases: [ + "/documentation/en/webdriver/bidirectional/bidirectional_w3c/network", + "/documentation/webdriver/bidirectional/webdriver_bidi/network" +] +--- + +The implementation of these features is being tracked here: [#13993](https://github.com/SeleniumHQ/selenium/issues/13993) + +Remember that to use WebDriver BiDi, you must [enable it in Options](http://www.example.com) + +## Authentication Handlers + +## Request Handlers + +## Response Handlers diff --git a/website_and_docs/content/documentation/webdriver/bidi/script.en.md b/website_and_docs/content/documentation/webdriver/bidi/script.en.md new file mode 100644 index 000000000000..2ce8c4c15032 --- /dev/null +++ b/website_and_docs/content/documentation/webdriver/bidi/script.en.md @@ -0,0 +1,21 @@ +--- +title: "WebDriver BiDi Script Features" +linkTitle: "Script" +weight: 1 +description: > + These features are related to scripts, and are made available via a "script" namespace. +aliases: [ + "/documentation/en/webdriver/bidirectional/bidirectional_w3c/script", + "/documentation/webdriver/bidirectional/webdriver_bidi/script" +] +--- + +The implementation of these features is being tracked here: [#13992](https://github.com/SeleniumHQ/selenium/issues/13992) + +Remember that to use WebDriver BiDi, you must [enable it in Options](http://www.example.com) + +## Script Pinning + +## Execute Script + +## DOM Mutation Handlers diff --git a/website_and_docs/content/documentation/webdriver/bidirectional/webdriver_bidi/_index.en.md b/website_and_docs/content/documentation/webdriver/bidi/w3c/_index.en.md similarity index 80% rename from website_and_docs/content/documentation/webdriver/bidirectional/webdriver_bidi/_index.en.md rename to website_and_docs/content/documentation/webdriver/bidi/w3c/_index.en.md index 09f9e815d024..6e7cbe79eebb 100644 --- a/website_and_docs/content/documentation/webdriver/bidirectional/webdriver_bidi/_index.en.md +++ b/website_and_docs/content/documentation/webdriver/bidi/w3c/_index.en.md @@ -1,7 +1,10 @@ --- title: "BiDirectional API (W3C compliant)" -linkTitle: "WebDriver-BiDi" +linkTitle: "W3C" weight: 16 +description: > + Examples of working with Chrome DevTools Protocol in Selenium. + CDP support is temporary until WebDriver BiDi has been implemented. aliases: [ "/documentation/en/webdriver/bidirectional/bidirectional_w3c", "/documentation/en/webdriver/bidi_apis/bidi_w3c", diff --git a/website_and_docs/content/documentation/webdriver/bidirectional/webdriver_bidi/_index.ja.md b/website_and_docs/content/documentation/webdriver/bidi/w3c/_index.ja.md similarity index 100% rename from website_and_docs/content/documentation/webdriver/bidirectional/webdriver_bidi/_index.ja.md rename to website_and_docs/content/documentation/webdriver/bidi/w3c/_index.ja.md diff --git a/website_and_docs/content/documentation/webdriver/bidirectional/webdriver_bidi/_index.pt-br.md b/website_and_docs/content/documentation/webdriver/bidi/w3c/_index.pt-br.md similarity index 100% rename from website_and_docs/content/documentation/webdriver/bidirectional/webdriver_bidi/_index.pt-br.md rename to website_and_docs/content/documentation/webdriver/bidi/w3c/_index.pt-br.md diff --git a/website_and_docs/content/documentation/webdriver/bidirectional/webdriver_bidi/_index.zh-cn.md b/website_and_docs/content/documentation/webdriver/bidi/w3c/_index.zh-cn.md similarity index 100% rename from website_and_docs/content/documentation/webdriver/bidirectional/webdriver_bidi/_index.zh-cn.md rename to website_and_docs/content/documentation/webdriver/bidi/w3c/_index.zh-cn.md diff --git a/website_and_docs/content/documentation/webdriver/bidirectional/webdriver_bidi/browsing_context.en.md b/website_and_docs/content/documentation/webdriver/bidi/w3c/browsing_context.en.md similarity index 100% rename from website_and_docs/content/documentation/webdriver/bidirectional/webdriver_bidi/browsing_context.en.md rename to website_and_docs/content/documentation/webdriver/bidi/w3c/browsing_context.en.md diff --git a/website_and_docs/content/documentation/webdriver/bidirectional/webdriver_bidi/browsing_context.ja.md b/website_and_docs/content/documentation/webdriver/bidi/w3c/browsing_context.ja.md similarity index 100% rename from website_and_docs/content/documentation/webdriver/bidirectional/webdriver_bidi/browsing_context.ja.md rename to website_and_docs/content/documentation/webdriver/bidi/w3c/browsing_context.ja.md diff --git a/website_and_docs/content/documentation/webdriver/bidirectional/webdriver_bidi/browsing_context.pt-br.md b/website_and_docs/content/documentation/webdriver/bidi/w3c/browsing_context.pt-br.md similarity index 100% rename from website_and_docs/content/documentation/webdriver/bidirectional/webdriver_bidi/browsing_context.pt-br.md rename to website_and_docs/content/documentation/webdriver/bidi/w3c/browsing_context.pt-br.md diff --git a/website_and_docs/content/documentation/webdriver/bidirectional/webdriver_bidi/browsing_context.zh-cn.md b/website_and_docs/content/documentation/webdriver/bidi/w3c/browsing_context.zh-cn.md similarity index 100% rename from website_and_docs/content/documentation/webdriver/bidirectional/webdriver_bidi/browsing_context.zh-cn.md rename to website_and_docs/content/documentation/webdriver/bidi/w3c/browsing_context.zh-cn.md diff --git a/website_and_docs/content/documentation/webdriver/bidirectional/webdriver_bidi/input.en.md b/website_and_docs/content/documentation/webdriver/bidi/w3c/input.en.md similarity index 100% rename from website_and_docs/content/documentation/webdriver/bidirectional/webdriver_bidi/input.en.md rename to website_and_docs/content/documentation/webdriver/bidi/w3c/input.en.md diff --git a/website_and_docs/content/documentation/webdriver/bidirectional/webdriver_bidi/input.ja.md b/website_and_docs/content/documentation/webdriver/bidi/w3c/input.ja.md similarity index 100% rename from website_and_docs/content/documentation/webdriver/bidirectional/webdriver_bidi/input.ja.md rename to website_and_docs/content/documentation/webdriver/bidi/w3c/input.ja.md diff --git a/website_and_docs/content/documentation/webdriver/bidirectional/webdriver_bidi/input.pt-br.md b/website_and_docs/content/documentation/webdriver/bidi/w3c/input.pt-br.md similarity index 100% rename from website_and_docs/content/documentation/webdriver/bidirectional/webdriver_bidi/input.pt-br.md rename to website_and_docs/content/documentation/webdriver/bidi/w3c/input.pt-br.md diff --git a/website_and_docs/content/documentation/webdriver/bidirectional/webdriver_bidi/input.zh-cn.md b/website_and_docs/content/documentation/webdriver/bidi/w3c/input.zh-cn.md similarity index 100% rename from website_and_docs/content/documentation/webdriver/bidirectional/webdriver_bidi/input.zh-cn.md rename to website_and_docs/content/documentation/webdriver/bidi/w3c/input.zh-cn.md diff --git a/website_and_docs/content/documentation/webdriver/bidirectional/webdriver_bidi/log.en.md b/website_and_docs/content/documentation/webdriver/bidi/w3c/log.en.md similarity index 100% rename from website_and_docs/content/documentation/webdriver/bidirectional/webdriver_bidi/log.en.md rename to website_and_docs/content/documentation/webdriver/bidi/w3c/log.en.md diff --git a/website_and_docs/content/documentation/webdriver/bidirectional/webdriver_bidi/log.ja.md b/website_and_docs/content/documentation/webdriver/bidi/w3c/log.ja.md similarity index 100% rename from website_and_docs/content/documentation/webdriver/bidirectional/webdriver_bidi/log.ja.md rename to website_and_docs/content/documentation/webdriver/bidi/w3c/log.ja.md diff --git a/website_and_docs/content/documentation/webdriver/bidirectional/webdriver_bidi/log.pt-br.md b/website_and_docs/content/documentation/webdriver/bidi/w3c/log.pt-br.md similarity index 100% rename from website_and_docs/content/documentation/webdriver/bidirectional/webdriver_bidi/log.pt-br.md rename to website_and_docs/content/documentation/webdriver/bidi/w3c/log.pt-br.md diff --git a/website_and_docs/content/documentation/webdriver/bidirectional/webdriver_bidi/log.zh-cn.md b/website_and_docs/content/documentation/webdriver/bidi/w3c/log.zh-cn.md similarity index 100% rename from website_and_docs/content/documentation/webdriver/bidirectional/webdriver_bidi/log.zh-cn.md rename to website_and_docs/content/documentation/webdriver/bidi/w3c/log.zh-cn.md diff --git a/website_and_docs/content/documentation/webdriver/bidirectional/webdriver_bidi/network.en.md b/website_and_docs/content/documentation/webdriver/bidi/w3c/network.en.md similarity index 100% rename from website_and_docs/content/documentation/webdriver/bidirectional/webdriver_bidi/network.en.md rename to website_and_docs/content/documentation/webdriver/bidi/w3c/network.en.md diff --git a/website_and_docs/content/documentation/webdriver/bidirectional/webdriver_bidi/network.ja.md b/website_and_docs/content/documentation/webdriver/bidi/w3c/network.ja.md similarity index 100% rename from website_and_docs/content/documentation/webdriver/bidirectional/webdriver_bidi/network.ja.md rename to website_and_docs/content/documentation/webdriver/bidi/w3c/network.ja.md diff --git a/website_and_docs/content/documentation/webdriver/bidirectional/webdriver_bidi/network.pt-br.md b/website_and_docs/content/documentation/webdriver/bidi/w3c/network.pt-br.md similarity index 100% rename from website_and_docs/content/documentation/webdriver/bidirectional/webdriver_bidi/network.pt-br.md rename to website_and_docs/content/documentation/webdriver/bidi/w3c/network.pt-br.md diff --git a/website_and_docs/content/documentation/webdriver/bidirectional/webdriver_bidi/network.zh-cn.md b/website_and_docs/content/documentation/webdriver/bidi/w3c/network.zh-cn.md similarity index 100% rename from website_and_docs/content/documentation/webdriver/bidirectional/webdriver_bidi/network.zh-cn.md rename to website_and_docs/content/documentation/webdriver/bidi/w3c/network.zh-cn.md diff --git a/website_and_docs/content/documentation/webdriver/bidirectional/webdriver_bidi/script.en.md b/website_and_docs/content/documentation/webdriver/bidi/w3c/script.en.md similarity index 100% rename from website_and_docs/content/documentation/webdriver/bidirectional/webdriver_bidi/script.en.md rename to website_and_docs/content/documentation/webdriver/bidi/w3c/script.en.md diff --git a/website_and_docs/content/documentation/webdriver/bidirectional/webdriver_bidi/script.ja.md b/website_and_docs/content/documentation/webdriver/bidi/w3c/script.ja.md similarity index 100% rename from website_and_docs/content/documentation/webdriver/bidirectional/webdriver_bidi/script.ja.md rename to website_and_docs/content/documentation/webdriver/bidi/w3c/script.ja.md diff --git a/website_and_docs/content/documentation/webdriver/bidirectional/webdriver_bidi/script.pt-br.md b/website_and_docs/content/documentation/webdriver/bidi/w3c/script.pt-br.md similarity index 100% rename from website_and_docs/content/documentation/webdriver/bidirectional/webdriver_bidi/script.pt-br.md rename to website_and_docs/content/documentation/webdriver/bidi/w3c/script.pt-br.md diff --git a/website_and_docs/content/documentation/webdriver/bidirectional/webdriver_bidi/script.zh-cn.md b/website_and_docs/content/documentation/webdriver/bidi/w3c/script.zh-cn.md similarity index 100% rename from website_and_docs/content/documentation/webdriver/bidirectional/webdriver_bidi/script.zh-cn.md rename to website_and_docs/content/documentation/webdriver/bidi/w3c/script.zh-cn.md diff --git a/website_and_docs/content/documentation/webdriver/bidirectional/_index.en.md b/website_and_docs/content/documentation/webdriver/bidirectional/_index.en.md deleted file mode 100644 index 2582c19467ee..000000000000 --- a/website_and_docs/content/documentation/webdriver/bidirectional/_index.en.md +++ /dev/null @@ -1,34 +0,0 @@ ---- -title: "BiDirectional functionality" -linkTitle: "BiDirectional" -weight: 16 -aliases: [ -"/documentation/en/webdriver/bidi_apis/", -"/documentation/webdriver/bidi_apis/", -"/documentation/webdriver/bidirectional/bidi_api_remotewebdriver" -] ---- - -Selenium is working with browser vendors to create the -[WebDriver BiDirectional Protocol](https://w3c.github.io/webdriver-bidi/) -as a means to provide a stable, cross-browser API that uses the bidirectional -functionality useful for both browser automation generally and testing specifically. -Before now, users seeking this functionality have had to rely on CDP (Chrome DevTools Protocol) -with all of its frustrations and limitations. - -The traditional WebDriver model of strict request/response commands will be supplemented -with the ability to stream events from the user agent to the controlling software via WebSockets, -better matching the evented nature of the browser DOM. - -As it is not a good idea to tie your tests to a specific version of any browser, the -Selenium project recommends using WebDriver BiDi wherever possible. - -While the specification is in works, the browser vendors are parallely implementing -the [WebDriver BiDirectional Protocol](https://w3c.github.io/webdriver-bidi/). -Refer [web-platform-tests dashboard](https://wpt.fyi/results/webdriver/tests/bidi?label=experimental&label=master&aligned&view=subtest) -to see how far along the browser vendors are. -Selenium is trying to keep up with the browser vendors and has started implementing W3C BiDi APIs. -The goal is to ensure APIs are W3C compliant and uniform among the different language bindings. - -However, until the specification and corresponding Selenium implementation is complete there are many useful things that -CDP offers. Selenium offers some useful helper classes that use CDP. \ No newline at end of file diff --git a/website_and_docs/content/documentation/webdriver/bidirectional/_index.ja.md b/website_and_docs/content/documentation/webdriver/bidirectional/_index.ja.md deleted file mode 100644 index 39b4dfdadd99..000000000000 --- a/website_and_docs/content/documentation/webdriver/bidirectional/_index.ja.md +++ /dev/null @@ -1,43 +0,0 @@ ---- -title: "BiDirectional Functionality" -linkTitle: "BiDirectional" -weight: 16 -aliases: [ -"/documentation/ja/webdriver/bidi_apis/", -"/ja/documentation/webdriver/bidi_apis/", -"/ja/documentation/webdriver/bidirectional/bidi_api_remotewebdriver" -] ---- - -{{% pageinfo color="warning" %}} -

- - Page being translated from English to Japanese. - Do you speak Japanese? Help us to translate - it by sending us pull requests! -

-{{% /pageinfo %}} - -Selenium is working with browser vendors to create the -[WebDriver BiDirectional Protocol](https://w3c.github.io/webdriver-bidi/) -as a means to provide a stable, cross-browser API that uses the bidirectional -functionality useful for both browser automation generally and testing specifically. -Before now, users seeking this functionality have had to rely on -with all of its frustrations and limitations. - -The traditional WebDriver model of strict request/response commands will be supplemented -with the ability to stream events from the user agent to the controlling software via WebSockets, -better matching the evented nature of the browser DOM. - -As it is not a good idea to tie your tests to a specific version of any browser, the -Selenium project recommends using WebDriver BiDi wherever possible. - -While the specification is in works, the browser vendors are parallely implementing -the [WebDriver BiDirectional Protocol](https://w3c.github.io/webdriver-bidi/). -Refer [web-platform-tests dashboard](https://wpt.fyi/results/webdriver/tests/bidi?label=experimental&label=master&aligned&view=subtest) -to see how far along the browser vendors are. -Selenium is trying to keep up with the browser vendors and has started implementing W3C BiDi APIs. -The goal is to ensure APIs are W3C compliant and uniform among the different language bindings. - -However, until the specification and corresponding Selenium implementation is complete there are many useful things that -CDP offers. Selenium offers some useful helper classes that use CDP. \ No newline at end of file diff --git a/website_and_docs/content/documentation/webdriver/bidirectional/_index.pt-br.md b/website_and_docs/content/documentation/webdriver/bidirectional/_index.pt-br.md deleted file mode 100644 index 218ad8df93a3..000000000000 --- a/website_and_docs/content/documentation/webdriver/bidirectional/_index.pt-br.md +++ /dev/null @@ -1,43 +0,0 @@ ---- -title: "BiDirectional Functionality" -linkTitle: "BiDirectional" -weight: 16 -aliases: [ -"/documentation/pt-br/webdriver/bidi_apis/", -"/pt-br/documentation/webdriver/bidi_apis/", -"/pt-br/documentation/webdriver/bidirectional/bidi_api_remotewebdriver" -] ---- - -{{% pageinfo color="warning" %}} -

- - Page being translated from - English to Portuguese. Do you speak Portuguese? Help us to translate - it by sending us pull requests! -

-{{% /pageinfo %}} - -Selenium is working with browser vendors to create the -[WebDriver BiDirectional Protocol](https://w3c.github.io/webdriver-bidi/) -as a means to provide a stable, cross-browser API that uses the bidirectional -functionality useful for both browser automation generally and testing specifically. -Before now, users seeking this functionality have had to rely on -with all of its frustrations and limitations. - -The traditional WebDriver model of strict request/response commands will be supplemented -with the ability to stream events from the user agent to the controlling software via WebSockets, -better matching the evented nature of the browser DOM. - -As it is not a good idea to tie your tests to a specific version of any browser, the -Selenium project recommends using WebDriver BiDi wherever possible. - -While the specification is in works, the browser vendors are parallely implementing -the [WebDriver BiDirectional Protocol](https://w3c.github.io/webdriver-bidi/). -Refer [web-platform-tests dashboard](https://wpt.fyi/results/webdriver/tests/bidi?label=experimental&label=master&aligned&view=subtest) -to see how far along the browser vendors are. -Selenium is trying to keep up with the browser vendors and has started implementing W3C BiDi APIs. -The goal is to ensure APIs are W3C compliant and uniform among the different language bindings. - -However, until the specification and corresponding Selenium implementation is complete there are many useful things that -CDP offers. Selenium offers some useful helper classes that use CDP. \ No newline at end of file diff --git a/website_and_docs/content/documentation/webdriver/bidirectional/_index.zh-cn.md b/website_and_docs/content/documentation/webdriver/bidirectional/_index.zh-cn.md deleted file mode 100644 index 731e9555de00..000000000000 --- a/website_and_docs/content/documentation/webdriver/bidirectional/_index.zh-cn.md +++ /dev/null @@ -1,34 +0,0 @@ ---- -title: "双向协议" -linkTitle: "双向协议" -weight: 16 -aliases: [ -"/documentation/zh-cn/webdriver/bidi_apis/", -"/zh-cn/documentation/webdriver/bidi_apis/", -"/zh-cn/documentation/webdriver/bidirectional/bidi_api_remotewebdriver" -] ---- - -Selenium正在与浏览器供应商合作创建 -[WebDriver双向协议](https://w3c.github.io/webdriver-bidi/) , -作为一种提供稳定的跨浏览器API的方法, -该API使用双向协议处理 -各种浏览器的通用自动化以及特定测试的需求. -在此之前, 寻求此功能的用户 -必须忍受当前实现的全部问题和局限. - - -严格限制请求响应命令的传统WebDriver模型, -将从user agent转变为基于WebSockets的软件控制, -通过这样完善流事件的能力, -以便更好地匹配浏览器DOM的事件性质. - -While the specification is in works, the browser vendors are parallely implementing -the [WebDriver BiDirectional Protocol](https://w3c.github.io/webdriver-bidi/). -Refer [web-platform-tests dashboard](https://wpt.fyi/results/webdriver/tests/bidi?label=experimental&label=master&aligned&view=subtest) -to see how far along the browser vendors are. -Selenium is trying to keep up with the browser vendors and has started implementing W3C BiDi APIs. -The goal is to ensure APIs are W3C compliant and uniform among the different language bindings. - -However, until the specification and corresponding Selenium implementation is complete there are many useful things that -CDP offers. Selenium offers some useful helper classes that use CDP. \ No newline at end of file diff --git a/website_and_docs/content/documentation/webdriver/bidirectional/chrome_devtools/_index.en.md b/website_and_docs/content/documentation/webdriver/bidirectional/chrome_devtools/_index.en.md deleted file mode 100644 index 6965c884fc70..000000000000 --- a/website_and_docs/content/documentation/webdriver/bidirectional/chrome_devtools/_index.en.md +++ /dev/null @@ -1,47 +0,0 @@ ---- -title: "Chrome DevTools" -linkTitle: "Chrome DevTools" -weight: 2 -aliases: [ -"/documentation/en/support_packages/chrome_devtools/", -"/documentation/support_packages/chrome_devtools/" -] ---- - -Many browsers provide "DevTools" -- a set of tools that are integrated with the browser that -developers can use to debug web apps and explore the performance of their pages. Google Chrome's -DevTools make use of a protocol called the Chrome DevTools Protocol (or "CDP" for short). -As the name suggests, this is not designed for testing, nor to have a stable API, so functionality -is highly dependent on the version of the browser. - -The [WebDriver BiDirectional Protocol](https://w3c.github.io/webdriver-bidi/) is the next generation of the -W3C WebDriver protocol and aims to provide a stable API implemented by all browsers, but it's not yet complete. -Until it is, Selenium provides access to -the CDP for those browsers that implement it (such as Google Chrome, or Microsoft Edge, and -Firefox), allowing you to enhance your tests in interesting ways. Some examples of what you can -do with it are given below. - -### Ways to Use Chrome DevTools With Selenium -There are three different ways to access Chrome DevTools in Selenium. If you look for other examples online, -you will likely see each of these mixed and matched. - -* The [CDP Endpoint]({{< ref "cdp_endpoint.md" >}}) was the first option available to users. -It only works for the most simple things (setting state, getting basic information), and you -have to know the "magic strings" for the domain and methods and key value pairs. -For basic requirements, this might be simpler than the other options. These methods are only temporarily supported. -* The [CDP API]({{< ref "cdp_api.md" >}}) is an improvement on just using the endpoint because you can set -do things asynchronously. Instead of a String and a Map, you can access the supported classes, -methods and parameters in the code. These methods are also only temporarily supported. -* The [BiDi API]({{< ref "bidi_api.md" >}}) option should be used whenever possible because it -abstracts away the implementation details entirely and will work with either CDP or WebDriver-BiDi -when Selenium moves away from CDP. - -### Examples With Limited Value - -There are a number of commonly cited examples for using CDP that are of limited practical value. -* **Geo Location** — almost all sites use the IP address to determine physical location, -so setting an emulated geolocation rarely has the desired effect. -* **Overriding Device Metrics** — Chrome provides a great API for setting [Mobile Emulation](https://chromedriver.chromium.org/mobile-emulation) -in the Options classes, which is generally superior to attempting to do this with CDP. - -Check out the examples in these documents for ways to do additional useful things: diff --git a/website_and_docs/content/documentation/webdriver/bidirectional/chrome_devtools/_index.ja.md b/website_and_docs/content/documentation/webdriver/bidirectional/chrome_devtools/_index.ja.md deleted file mode 100644 index 17b043d19b0f..000000000000 --- a/website_and_docs/content/documentation/webdriver/bidirectional/chrome_devtools/_index.ja.md +++ /dev/null @@ -1,47 +0,0 @@ ---- -title: "Chrome DevTools" -linkTitle: "Chrome DevTools" -weight: 2 -aliases: [ -"/documentation/ja/support_packages/chrome_devtools/", -"/ja/documentation/support_packages/chrome_devtools/" -] ---- - -Many browsers provide "DevTools" -- a set of tools that are integrated with the browser that -developers can use to debug web apps and explore the performance of their pages. Google Chrome's -DevTools make use of a protocol called the Chrome DevTools Protocol (or "CDP" for short). -As the name suggests, this is not designed for testing, nor to have a stable API, so functionality -is highly dependent on the version of the browser. - -The [WebDriver BiDirectional Protocol](https://w3c.github.io/webdriver-bidi/) is the next generation of the -W3C WebDriver protocol and aims to provide a stable API implemented by all browsers, but it's not yet complete. -Until it is, Selenium provides access to -the CDP for those browsers that implement it (such as Google Chrome, or Microsoft Edge, and -Firefox), allowing you to enhance your tests in interesting ways. Some examples of what you can -do with it are given below. - -### Ways to Use Chrome DevTools With Selenium -There are three different ways to access Chrome DevTools in Selenium. If you look for other examples online, -you will likely see each of these mixed and matched. - -* The [CDP Endpoint]({{< ref "cdp_endpoint.md" >}}) was the first option available to users. -It only works for the most simple things (setting state, getting basic information), and you -have to know the "magic strings" for the domain and methods and key value pairs. -For basic requirements, this might be simpler than the other options. These methods are only temporarily supported. -* The [CDP API]({{< ref "cdp_api.md" >}}) is an improvement on just using the endpoint because you can set -do things asynchronously. Instead of a String and a Map, you can access the supported classes, -methods and parameters in the code. These methods are also only temporarily supported. -* The [BiDi API]({{< ref "bidi_api.md" >}}) option should be used whenever possible because it -abstracts away the implementation details entirely and will work with either CDP or WebDriver-BiDi -when Selenium moves away from CDP. - -### Examples With Limited Value - -There are a number of commonly cited examples for using CDP that are of limited practical value. -* **Geo Location** — almost all sites use the IP address to determine physical location, -so setting an emulated geolocation rarely has the desired effect. -* **Overriding Device Metrics** — Chrome provides a great API for setting [Mobile Emulation](https://chromedriver.chromium.org/mobile-emulation) -in the Options classes, which is generally superior to attempting to do this with CDP. - -Check out the examples in these documents for ways to do additional useful things: diff --git a/website_and_docs/content/documentation/webdriver/bidirectional/chrome_devtools/_index.pt-br.md b/website_and_docs/content/documentation/webdriver/bidirectional/chrome_devtools/_index.pt-br.md deleted file mode 100644 index d9256c366fe6..000000000000 --- a/website_and_docs/content/documentation/webdriver/bidirectional/chrome_devtools/_index.pt-br.md +++ /dev/null @@ -1,47 +0,0 @@ ---- -title: "Chrome DevTools" -linkTitle: "Chrome DevTools" -weight: 2 -aliases: [ -"/documentation/pt-br/support_packages/chrome_devtools/", -"/pt-br/documentation/support_packages/chrome_devtools/" -] ---- - -Many browsers provide "DevTools" -- a set of tools that are integrated with the browser that -developers can use to debug web apps and explore the performance of their pages. Google Chrome's -DevTools make use of a protocol called the Chrome DevTools Protocol (or "CDP" for short). -As the name suggests, this is not designed for testing, nor to have a stable API, so functionality -is highly dependent on the version of the browser. - -The [WebDriver BiDirectional Protocol](https://w3c.github.io/webdriver-bidi/) is the next generation of the -W3C WebDriver protocol and aims to provide a stable API implemented by all browsers, but it's not yet complete. -Until it is, Selenium provides access to -the CDP for those browsers that implement it (such as Google Chrome, or Microsoft Edge, and -Firefox), allowing you to enhance your tests in interesting ways. Some examples of what you can -do with it are given below. - -### Ways to Use Chrome DevTools With Selenium -There are three different ways to access Chrome DevTools in Selenium. If you look for other examples online, -you will likely see each of these mixed and matched. - -* The [CDP Endpoint]({{< ref "cdp_endpoint.md" >}}) was the first option available to users. -It only works for the most simple things (setting state, getting basic information), and you -have to know the "magic strings" for the domain and methods and key value pairs. -For basic requirements, this might be simpler than the other options. These methods are only temporarily supported. -* The [CDP API]({{< ref "cdp_api.md" >}}) is an improvement on just using the endpoint because you can set -do things asynchronously. Instead of a String and a Map, you can access the supported classes, -methods and parameters in the code. These methods are also only temporarily supported. -* The [BiDi API]({{< ref "bidi_api.md" >}}) option should be used whenever possible because it -abstracts away the implementation details entirely and will work with either CDP or WebDriver-BiDi -when Selenium moves away from CDP. - -### Examples With Limited Value - -There are a number of commonly cited examples for using CDP that are of limited practical value. -* **Geo Location** — almost all sites use the IP address to determine physical location, -so setting an emulated geolocation rarely has the desired effect. -* **Overriding Device Metrics** — Chrome provides a great API for setting [Mobile Emulation](https://chromedriver.chromium.org/mobile-emulation) -in the Options classes, which is generally superior to attempting to do this with CDP. - -Check out the examples in these documents for ways to do additional useful things: diff --git a/website_and_docs/content/documentation/webdriver/bidirectional/chrome_devtools/_index.zh-cn.md b/website_and_docs/content/documentation/webdriver/bidirectional/chrome_devtools/_index.zh-cn.md deleted file mode 100644 index 0ad7b3c715f7..000000000000 --- a/website_and_docs/content/documentation/webdriver/bidirectional/chrome_devtools/_index.zh-cn.md +++ /dev/null @@ -1,47 +0,0 @@ ---- -title: "Chrome DevTools" -linkTitle: "Chrome DevTools" -weight: 2 -aliases: [ -"/documentation/zh-cn/support_packages/chrome_devtools/", -"/zh-cn/documentation/support_packages/chrome_devtools/" -] ---- - -Many browsers provide "DevTools" -- a set of tools that are integrated with the browser that -developers can use to debug web apps and explore the performance of their pages. Google Chrome's -DevTools make use of a protocol called the Chrome DevTools Protocol (or "CDP" for short). -As the name suggests, this is not designed for testing, nor to have a stable API, so functionality -is highly dependent on the version of the browser. - -The [WebDriver BiDirectional Protocol](https://w3c.github.io/webdriver-bidi/) is the next generation of the -W3C WebDriver protocol and aims to provide a stable API implemented by all browsers, but it's not yet complete. -Until it is, Selenium provides access to -the CDP for those browsers that implement it (such as Google Chrome, or Microsoft Edge, and -Firefox), allowing you to enhance your tests in interesting ways. Some examples of what you can -do with it are given below. - -### Ways to Use Chrome DevTools With Selenium -There are three different ways to access Chrome DevTools in Selenium. If you look for other examples online, -you will likely see each of these mixed and matched. - -* The [CDP Endpoint]({{< ref "cdp_endpoint.md" >}}) was the first option available to users. -It only works for the most simple things (setting state, getting basic information), and you -have to know the "magic strings" for the domain and methods and key value pairs. -For basic requirements, this might be simpler than the other options. These methods are only temporarily supported. -* The [CDP API]({{< ref "cdp_api.md" >}}) is an improvement on just using the endpoint because you can set -do things asynchronously. Instead of a String and a Map, you can access the supported classes, -methods and parameters in the code. These methods are also only temporarily supported. -* The [BiDi API]({{< ref "bidi_api.md" >}}) option should be used whenever possible because it -abstracts away the implementation details entirely and will work with either CDP or WebDriver-BiDi -when Selenium moves away from CDP. - -### Examples With Limited Value - -There are a number of commonly cited examples for using CDP that are of limited practical value. -* **Geo Location** — almost all sites use the IP address to determine physical location, -so setting an emulated geolocation rarely has the desired effect. -* **Overriding Device Metrics** — Chrome provides a great API for setting [Mobile Emulation](https://chromedriver.chromium.org/mobile-emulation) -in the Options classes, which is generally superior to attempting to do this with CDP. - -Check out the examples in these documents for ways to do additional useful things: diff --git a/website_and_docs/content/documentation/webdriver/bidirectional/chrome_devtools/bidi_api.en.md b/website_and_docs/content/documentation/webdriver/bidirectional/chrome_devtools/bidi_api.en.md deleted file mode 100644 index da625febd386..000000000000 --- a/website_and_docs/content/documentation/webdriver/bidirectional/chrome_devtools/bidi_api.en.md +++ /dev/null @@ -1,359 +0,0 @@ ---- -title: "Chrome Devtools Protocol with BiDi API" -linkTitle: "BiDi API" -weight: 6 -description: > - These examples are currently implemented with CDP, but the same code should work when the functionality - is re-implemented with WebDriver-BiDi. ---- - -## Usage - -The following list of APIs will be growing as the Selenium -project works through supporting real world use cases. If there -is additional functionality you'd like to see, please raise a -[feature request](https://github.com/SeleniumHQ/selenium/issues/new?assignees=&labels=&template=feature.md). - -As these examples are re-implemented with the [WebDriver-Bidi](https://w3c.github.io/webdriver-bidi) protocol, they will -be moved to the [WebDriver Bidi]({{< ref "../webdriver_bidi/" >}}) pages. - -## Examples - -### Basic authentication - -Some applications make use of browser authentication to secure pages. -It used to be common to handle them in the URL, but browser stopped supporting this. -With BiDi, you can now provide the credentials when necessary - -Alternate implementations can be found at -[CDP Endpoint Basic Authentication]({{< ref "cdp_endpoint#basic-authentication" >}}) -and [CDP API Basic Authentication]({{< ref "cdp_api#basic-authentication" >}}) - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/BidiApiTest.java#L36-L39" >}} -{{% /tab %}} -{{% tab header="Python" %}} -An alternate implementation may be found at -[CDP Endpoint Basic Authentication]({{< ref "cdp_endpoint#basic-authentication" >}}) -{{< badge-implementation >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/BidiApiTest.cs#L18-L27" >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/bidi_api_spec.rb#L9-L11" >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-examples >}} -```js -const {Builder} = require('selenium-webdriver'); - -(async function example() { - try { - let driver = await new Builder() - .forBrowser('chrome') - .build(); - - const pageCdpConnection = await driver.createCDPConnection('page'); - await driver.register('username', 'password', pageCdpConnection); - await driver.get('https://the-internet.herokuapp.com/basic_auth'); - await driver.quit(); - }catch (e){ - console.log(e) - } -}()) -``` -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-examples >}} -```java -val uriPredicate = Predicate { uri: URI -> - uri.host.contains("your-domain.com") - } -(driver as HasAuthentication).register(uriPredicate, UsernameAndPassword.of("admin", "password")) -driver.get("https://your-domain.com/login") -``` -{{% /tab %}} -{{< /tabpane >}} - - -### Pin scripts - -This can be especially useful when executing on a remote server. For example, -whenever you check the visibility of an element, or whenever you use -the classic get attribute method, Selenium is sending the contents of a js file -to the script execution endpoint. These files are each about 50kB, which adds up. - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -{{< badge-implementation >}} -{{% /tab %}} -{{% tab header="Python" %}} -{{< badge-implementation >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/BidiApiTest.cs#L41-L43" >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/bidi_api_spec.rb#L22-L23" >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-implementation >}} -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-code >}} -{{% /tab %}} -{{< /tabpane >}} - - -### Mutation observation - -Mutation Observation is the ability to capture events via -WebDriver BiDi when there are DOM mutations on a specific -element in the DOM. - -{{< tabpane text=true >}} - {{% tab header="Java" %}} -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/BidiApiTest.java#L64-L65" >}} - {{% /tab %}} - {{% tab header="Python" %}} -{{< gh-codeblock path="/examples/python/tests/bidirectional/chrome_devtools/test_bidi_api.py#L9-L11" >}} - {{% /tab %}} - {{% tab header="CSharp" %}} -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/BidiApiTest.cs#L59-L68" >}} - {{% /tab %}} - {{< tab header="Ruby" >}} -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/bidi_api_spec.rb#L31-L32" >}} - {{< /tab >}} - {{% tab header="JavaScript" %}} - {{< badge-examples >}} -```js -const {Builder, until} = require('selenium-webdriver'); -const assert = require("assert"); - -(async function example() { - try { - let driver = await new Builder() - .forBrowser('chrome') - .build(); - - const cdpConnection = await driver.createCDPConnection('page'); - await driver.logMutationEvents(cdpConnection, event => { - assert.deepStrictEqual(event['attribute_name'], 'style'); - assert.deepStrictEqual(event['current_value'], ""); - assert.deepStrictEqual(event['old_value'], "display:none;"); - }); - - await driver.get('dynamic.html'); - await driver.findElement({id: 'reveal'}).click(); - let revealed = driver.findElement({id: 'revealed'}); - await driver.wait(until.elementIsVisible(revealed), 5000); - await driver.quit(); - }catch (e){ - console.log(e) - } -}()) -``` -{{% /tab %}} - {{< tab header="Kotlin" >}} -{{< badge-code >}} - {{< /tab >}} -{{< /tabpane >}} - - -### Console logs and errors - -Listen to the `console.log` events and register callbacks to process the event. - -[CDP API Console logs]({{< ref "cdp_api#console-logs-and-errors" >}}) -and [WebDriver BiDi Console logs]({{< ref "../webdriver_bidi/log#console-logs" >}}) - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -Use the [WebDriver BiDi Console logs]({{< ref "../webdriver_bidi/log#console-logs" >}}) implementation. `HasLogEvents` -will likely end up deprecated because it does not implement `Closeable`. -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/BidiApiTest.java#L77-L78" >}} -{{% /tab %}} -{{% tab header="Python" %}} -{{< gh-codeblock path="/examples/python/tests/bidirectional/chrome_devtools/test_bidi_api.py#L23-L26" >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/BidiApiTest.cs#L85-L92" >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/bidi_api_spec.rb#L43-L44" >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-examples >}} -```js -const {Builder} = require('selenium-webdriver'); -(async () => { - try { - let driver = new Builder() - .forBrowser('chrome') - .build(); - - const cdpConnection = await driver.createCDPConnection('page'); - await driver.onLogEvent(cdpConnection, function (event) { - console.log(event['args'][0]['value']); - }); - await driver.executeScript('console.log("here")'); - await driver.quit(); - }catch (e){ - console.log(e); - } -})() -``` -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-examples >}} -```java -fun kotlinConsoleLogExample() { - val driver = ChromeDriver() - val devTools = driver.devTools - devTools.createSession() - - val logConsole = { c: ConsoleEvent -> print("Console log message is: " + c.messages)} - devTools.domains.events().addConsoleListener(logConsole) - - driver.get("https://www.google.com") - - val executor = driver as JavascriptExecutor - executor.executeScript("console.log('Hello World')") - - val input = driver.findElement(By.name("q")) - input.sendKeys("Selenium 4") - input.sendKeys(Keys.RETURN) - driver.quit() -} -``` -{{% /tab %}} -{{< /tabpane >}} - - -### JavaScript exceptions - -Listen to the JS Exceptions -and register callbacks to process the exception details. - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -Use the [WebDriver BiDi JavaScript exceptions]({{< ref "../webdriver_bidi/log#javascript-exceptions" >}}) implementation -{{% /tab %}} -{{% tab header="Python" %}} -{{< gh-codeblock path="/examples/python/tests/bidirectional/chrome_devtools/test_bidi_api.py#L36-L39" >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/BidiApiTest.cs#L107-L114" >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/bidi_api_spec.rb#L57-L58" >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-implementation >}} -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-code >}} -{{% /tab %}} -{{< /tabpane >}} - - -### Network Interception - -Both requests and responses can be recorded or transformed. - -#### Response information - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/BidiApiTest.java#L90-L101" >}} -{{% /tab %}} -{{% tab header="Python" %}} -{{< badge-implementation >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/BidiApiTest.cs#L125-L133" >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/bidi_api_spec.rb#L67-L72" >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-implementation >}} -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-code >}} -{{% /tab %}} -{{< /tabpane >}} - -#### Response transformation - -{{< tabpane text=true >}} -{{< tab header="Java" >}} -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/BidiApiTest.java#L111-L121" >}} -{{< /tab >}} -{{< tab header="Python" >}} -{{< badge-implementation >}} -{{< /tab >}} -{{< tab header="CSharp" >}} -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/BidiApiTest.cs#L143-L156" >}} -{{< /tab >}} -{{< tab header="Ruby" >}} -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/bidi_api_spec.rb#L79-L83" >}} -{{< /tab >}} -{{% tab header="JavaScript" %}} -{{< badge-examples >}} -```js -const connection = await driver.createCDPConnection('page') -let url = fileServer.whereIs("/cheese") -let httpResponse = new HttpResponse(url) -httpResponse.addHeaders("Content-Type", "UTF-8") -httpResponse.body = "sausages" -await driver.onIntercept(connection, httpResponse, async function () { - let body = await driver.getPageSource() - assert.strictEqual(body.includes("sausages"), true, `Body contains: ${body}`) -}) -driver.get(url) -``` -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-examples >}} -```java -val driver = ChromeDriver() -val interceptor = new NetworkInterceptor( - driver, - Route.matching(req -> true) - .to(() -> req -> new HttpResponse() - .setStatus(200) - .addHeader("Content-Type", MediaType.HTML_UTF_8.toString()) - .setContent(utf8String("Creamy, delicious cheese!")))) - - driver.get(appServer.whereIs("/cheese")) - - String source = driver.getPageSource() -``` -{{% /tab %}} -{{< /tabpane >}} - -#### Request interception - -{{< tabpane text=true >}} -{{< tab header="Java" >}} -{{< badge-implementation >}} -{{< /tab >}} -{{< tab header="Python" >}} -{{< badge-implementation >}} -{{< /tab >}} -{{< tab header="CSharp" >}} -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/BidiApiTest.cs#L167-L181" >}} -{{< /tab >}} -{{< tab header="Ruby" >}} -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/bidi_api_spec.rb#L90-L94" >}} -{{< /tab >}} -{{< tab header="JavaScript" >}} -{{< badge-code >}} -{{< /tab >}} -{{< tab header="Kotlin" >}} -{{< badge-code >}} -{{< /tab >}} -{{< /tabpane >}} diff --git a/website_and_docs/content/documentation/webdriver/bidirectional/chrome_devtools/bidi_api.ja.md b/website_and_docs/content/documentation/webdriver/bidirectional/chrome_devtools/bidi_api.ja.md deleted file mode 100644 index 659735eeaae2..000000000000 --- a/website_and_docs/content/documentation/webdriver/bidirectional/chrome_devtools/bidi_api.ja.md +++ /dev/null @@ -1,361 +0,0 @@ ---- -title: "Chrome Devtools Protocol with BiDi API" -linkTitle: "BiDi API" -weight: 6 -description: > - These examples are currently implemented with CDP, but the same code should work when the functionality - is re-implemented with WebDriver-BiDi. ---- - -## Usage - -The following list of APIs will be growing as the Selenium -project works through supporting real world use cases. If there -is additional functionality you'd like to see, please raise a -[feature request](https://github.com/SeleniumHQ/selenium/issues/new?assignees=&labels=&template=feature.md). - -As these examples are re-implemented with the [WebDriver-Bidi](https://w3c.github.io/webdriver-bidi) protocol, they will -be moved to the [WebDriver Bidi]({{< ref "../webdriver_bidi/" >}}) pages. - -## Examples - -### Basic authentication - -Some applications make use of browser authentication to secure pages. -It used to be common to handle them in the URL, but browser stopped supporting this. -With BiDi, you can now provide the credentials when necessary - -Alternate implementations can be found at -[CDP Endpoint Basic Authentication]({{< ref "cdp_endpoint#basic-authentication" >}}) -and [CDP API Basic Authentication]({{< ref "cdp_api#basic-authentication" >}}) - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/BidiApiTest.java#L36-L39" >}} -{{% /tab %}} -{{% tab header="Python" %}} -An alternate implementation may be found at -[CDP Endpoint Basic Authentication]({{< ref "cdp_endpoint#basic-authentication" >}}) -{{< badge-implementation >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/BidiApiTest.cs#L18-L27" >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/bidi_api_spec.rb#L9-L11" >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-examples >}} - -```js -const {Builder} = require('selenium-webdriver'); - -(async function example() { - try { - let driver = await new Builder() - .forBrowser('chrome') - .build(); - - const pageCdpConnection = await driver.createCDPConnection('page'); - await driver.register('username', 'password', pageCdpConnection); - await driver.get('https://the-internet.herokuapp.com/basic_auth'); - await driver.quit(); - }catch (e){ - console.log(e) - } -}()) -``` -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-examples >}} - -```java -val uriPredicate = Predicate { uri: URI -> - uri.host.contains("your-domain.com") - } -(driver as HasAuthentication).register(uriPredicate, UsernameAndPassword.of("admin", "password")) -driver.get("https://your-domain.com/login") -``` -{{% /tab %}} -{{< /tabpane >}} - - -### Pin scripts - -This can be especially useful when executing on a remote server. For example, -whenever you check the visibility of an element, or whenever you use -the classic get attribute method, Selenium is sending the contents of a js file -to the script execution endpoint. These files are each about 50kB, which adds up. - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -{{< badge-implementation >}} -{{% /tab %}} -{{% tab header="Python" %}} -{{< badge-implementation >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/BidiApiTest.cs#L41-L43" >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/bidi_api_spec.rb#L22-L23" >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-implementation >}} -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-code >}} -{{% /tab %}} -{{< /tabpane >}} - - -### Mutation observation - -Mutation Observation is the ability to capture events via -WebDriver BiDi when there are DOM mutations on a specific -element in the DOM. - -{{< tabpane text=true >}} - {{% tab header="Java" %}} -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/BidiApiTest.java#L64-L65" >}} - {{% /tab %}} - {{% tab header="Python" %}} -{{< gh-codeblock path="/examples/python/tests/bidirectional/chrome_devtools/test_bidi_api.py#L9-L11" >}} - {{% /tab %}} - {{% tab header="CSharp" %}} -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/BidiApiTest.cs#L59-L68" >}} - {{% /tab %}} - {{< tab header="Ruby" >}} -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/bidi_api_spec.rb#L31-L32" >}} - {{< /tab >}} - {{% tab header="JavaScript" %}} - {{< badge-examples >}} -```js -const {Builder, until} = require('selenium-webdriver'); -const assert = require("assert"); - -(async function example() { - try { - let driver = await new Builder() - .forBrowser('chrome') - .build(); - - const cdpConnection = await driver.createCDPConnection('page'); - await driver.logMutationEvents(cdpConnection, event => { - assert.deepStrictEqual(event['attribute_name'], 'style'); - assert.deepStrictEqual(event['current_value'], ""); - assert.deepStrictEqual(event['old_value'], "display:none;"); - }); - - await driver.get('dynamic.html'); - await driver.findElement({id: 'reveal'}).click(); - let revealed = driver.findElement({id: 'revealed'}); - await driver.wait(until.elementIsVisible(revealed), 5000); - await driver.quit(); - }catch (e){ - console.log(e) - } -}()) -``` -{{% /tab %}} - {{< tab header="Kotlin" >}} -{{< badge-code >}} - {{< /tab >}} -{{< /tabpane >}} - - -### Console logs and errors - -Listen to the `console.log` events and register callbacks to process the event. - -[CDP API Console logs]({{< ref "cdp_api#console-logs-and-errors" >}}) -and [WebDriver BiDi Console logs]({{< ref "../webdriver_bidi/log#console-logs" >}}) - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -Use the [WebDriver BiDi Console logs]({{< ref "../webdriver_bidi/log#console-logs" >}}) implementation. `HasLogEvents` -will likely end up deprecated because it does not implement `Closeable`. -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/BidiApiTest.java#L77-L78" >}} -{{% /tab %}} -{{% tab header="Python" %}} -{{< gh-codeblock path="/examples/python/tests/bidirectional/chrome_devtools/test_bidi_api.py#L23-L26" >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/BidiApiTest.cs#L85-L92" >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/bidi_api_spec.rb#L43-L44" >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-examples >}} -```js -const {Builder} = require('selenium-webdriver'); -(async () => { - try { - let driver = new Builder() - .forBrowser('chrome') - .build(); - - const cdpConnection = await driver.createCDPConnection('page'); - await driver.onLogEvent(cdpConnection, function (event) { - console.log(event['args'][0]['value']); - }); - await driver.executeScript('console.log("here")'); - await driver.quit(); - }catch (e){ - console.log(e); - } -})() -``` -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-examples >}} -```java -fun kotlinConsoleLogExample() { - val driver = ChromeDriver() - val devTools = driver.devTools - devTools.createSession() - - val logConsole = { c: ConsoleEvent -> print("Console log message is: " + c.messages)} - devTools.domains.events().addConsoleListener(logConsole) - - driver.get("https://www.google.com") - - val executor = driver as JavascriptExecutor - executor.executeScript("console.log('Hello World')") - - val input = driver.findElement(By.name("q")) - input.sendKeys("Selenium 4") - input.sendKeys(Keys.RETURN) - driver.quit() -} -``` -{{% /tab %}} -{{< /tabpane >}} - - -### JavaScript exceptions - -Listen to the JS Exceptions -and register callbacks to process the exception details. - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -Use the [WebDriver BiDi JavaScript exceptions]({{< ref "../webdriver_bidi/log#javascript-exceptions" >}}) implementation -{{% /tab %}} -{{% tab header="Python" %}} -{{< gh-codeblock path="/examples/python/tests/bidirectional/chrome_devtools/test_bidi_api.py#L36-L39" >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/BidiApiTest.cs#L107-L114" >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/bidi_api_spec.rb#L57-L58" >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-implementation >}} -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-code >}} -{{% /tab %}} -{{< /tabpane >}} - - -### Network Interception - -Both requests and responses can be recorded or transformed. - -#### Response information - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/BidiApiTest.java#L90-L101" >}} -{{% /tab %}} -{{% tab header="Python" %}} -{{< badge-implementation >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/BidiApiTest.cs#L125-L133" >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/bidi_api_spec.rb#L67-L72" >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-implementation >}} -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-code >}} -{{% /tab %}} -{{< /tabpane >}} - -#### Response transformation - -{{< tabpane text=true >}} -{{< tab header="Java" >}} -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/BidiApiTest.java#L111-L121" >}} -{{< /tab >}} -{{< tab header="Python" >}} -{{< badge-implementation >}} -{{< /tab >}} -{{< tab header="CSharp" >}} -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/BidiApiTest.cs#L143-L156" >}} -{{< /tab >}} -{{< tab header="Ruby" >}} -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/bidi_api_spec.rb#L79-L83" >}} -{{< /tab >}} -{{% tab header="JavaScript" %}} -{{< badge-examples >}} -```js -const connection = await driver.createCDPConnection('page') -let url = fileServer.whereIs("/cheese") -let httpResponse = new HttpResponse(url) -httpResponse.addHeaders("Content-Type", "UTF-8") -httpResponse.body = "sausages" -await driver.onIntercept(connection, httpResponse, async function () { - let body = await driver.getPageSource() - assert.strictEqual(body.includes("sausages"), true, `Body contains: ${body}`) -}) -driver.get(url) -``` -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-examples >}} -```java -val driver = ChromeDriver() -val interceptor = new NetworkInterceptor( - driver, - Route.matching(req -> true) - .to(() -> req -> new HttpResponse() - .setStatus(200) - .addHeader("Content-Type", MediaType.HTML_UTF_8.toString()) - .setContent(utf8String("Creamy, delicious cheese!")))) - - driver.get(appServer.whereIs("/cheese")) - - String source = driver.getPageSource() -``` -{{% /tab %}} -{{< /tabpane >}} - -#### Request interception - -{{< tabpane text=true >}} -{{< tab header="Java" >}} -{{< badge-implementation >}} -{{< /tab >}} -{{< tab header="Python" >}} -{{< badge-implementation >}} -{{< /tab >}} -{{< tab header="CSharp" >}} -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/BidiApiTest.cs#L167-L181" >}} -{{< /tab >}} -{{< tab header="Ruby" >}} -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/bidi_api_spec.rb#L90-L94" >}} -{{< /tab >}} -{{< tab header="JavaScript" >}} -{{< badge-code >}} -{{< /tab >}} -{{< tab header="Kotlin" >}} -{{< badge-code >}} -{{< /tab >}} -{{< /tabpane >}} diff --git a/website_and_docs/content/documentation/webdriver/bidirectional/chrome_devtools/bidi_api.pt-br.md b/website_and_docs/content/documentation/webdriver/bidirectional/chrome_devtools/bidi_api.pt-br.md deleted file mode 100644 index b0174aef9bb8..000000000000 --- a/website_and_docs/content/documentation/webdriver/bidirectional/chrome_devtools/bidi_api.pt-br.md +++ /dev/null @@ -1,350 +0,0 @@ ---- -title: "Chrome Devtools Protocol with BiDi API" -linkTitle: "BiDi API" -weight: 6 -description: > - These examples are currently implemented with CDP, but the same code should work when the functionality - is re-implemented with WebDriver-BiDi. ---- - -## Usage - -A seguinte lista de APIs crescerá à medida que o projeto Selenium se prepara -para suportar casos de uso do mundo real. Se houver funcionalidades adicionais que você gostaria de ver, por favor, levante uma [solicitação de recurso](https://github.com/SeleniumHQ/selenium/issues/new?assignees=&labels=&template=feature.md). - -As these examples are re-implemented with the [WebDriver-Bidi](https://w3c.github.io/webdriver-bidi) protocol, they will -be moved to the [WebDriver Bidi]({{< ref "../webdriver_bidi/" >}}) pages. - -## Examples - -### Basic authentication - -Alguns aplicativos fazem o uso da autenticação do navegador para proteger suas páginas. Com o Selenium, você pode automatizar a entrada de credenciais básicas de autenticação sempre que for necessário. - -Alternate implementations can be found at -[CDP Endpoint Basic Authentication]({{< ref "cdp_endpoint#basic-authentication" >}}) -and [CDP API Basic Authentication]({{< ref "cdp_api#basic-authentication" >}}) - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/BidiApiTest.java#L36-L39" >}} -{{% /tab %}} -{{% tab header="Python" %}} -An alternate implementation may be found at -[CDP Endpoint Basic Authentication]({{< ref "cdp_endpoint#basic-authentication" >}}) -{{< badge-implementation >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/BidiApiTest.cs#L18-L27" >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/bidi_api_spec.rb#L9-L11" >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-examples >}} -```js -const {Builder} = require('selenium-webdriver'); - -(async function example() { - try { - let driver = await new Builder() - .forBrowser('chrome') - .build(); - - const pageCdpConnection = await driver.createCDPConnection('page'); - await driver.register('username', 'password', pageCdpConnection); - await driver.get('https://the-internet.herokuapp.com/basic_auth'); - await driver.quit(); - }catch (e){ - console.log(e) - } -}()) -``` -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-examples >}} -```java -val uriPredicate = Predicate { uri: URI -> - uri.host.contains("your-domain.com") - } -(driver as HasAuthentication).register(uriPredicate, UsernameAndPassword.of("admin", "password")) -driver.get("https://your-domain.com/login") -``` -{{% /tab %}} -{{< /tabpane >}} - - -### Pin scripts -This can be especially useful when executing on a remote server. For example, -whenever you check the visibility of an element, or whenever you use -the classic get attribute method, Selenium is sending the contents of a js file -to the script execution endpoint. These files are each about 50kB, which adds up. - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -{{< badge-implementation >}} -{{% /tab %}} -{{% tab header="Python" %}} -{{< badge-implementation >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/BidiApiTest.cs#L41-L43" >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/bidi_api_spec.rb#L22-L23" >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-implementation >}} -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-code >}} -{{% /tab %}} -{{< /tabpane >}} - - -### Mutation observation - -Mutation Observation(Observação de Mutação) é a capacidade de capturar eventos via WebDriver BiDi quando há mutações DOM em um elemento específico no DOM. - -{{< tabpane text=true >}} - {{% tab header="Java" %}} -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/BidiApiTest.java#L64-L65" >}} - {{% /tab %}} - {{% tab header="Python" %}} -{{< gh-codeblock path="/examples/python/tests/bidirectional/chrome_devtools/test_bidi_api.py#L9-L11" >}} - {{% /tab %}} - {{% tab header="CSharp" %}} -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/BidiApiTest.cs#L59-L68" >}} - {{% /tab %}} - {{< tab header="Ruby" >}} -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/bidi_api_spec.rb#L31-L32" >}} - {{< /tab >}} - {{% tab header="JavaScript" %}} - {{< badge-examples >}} -```js -const {Builder, until} = require('selenium-webdriver'); -const assert = require("assert"); - -(async function example() { - try { - let driver = await new Builder() - .forBrowser('chrome') - .build(); - - const cdpConnection = await driver.createCDPConnection('page'); - await driver.logMutationEvents(cdpConnection, event => { - assert.deepStrictEqual(event['attribute_name'], 'style'); - assert.deepStrictEqual(event['current_value'], ""); - assert.deepStrictEqual(event['old_value'], "display:none;"); - }); - - await driver.get('dynamic.html'); - await driver.findElement({id: 'reveal'}).click(); - let revealed = driver.findElement({id: 'revealed'}); - await driver.wait(until.elementIsVisible(revealed), 5000); - await driver.quit(); - }catch (e){ - console.log(e) - } -}()) -``` -{{% /tab %}} - {{< tab header="Kotlin" >}} -{{< badge-code >}} - {{< /tab >}} -{{< /tabpane >}} - - -### Console logs and errors -Vigie os eventos `console.log` e registre os callbacks(retornos de chamada) para processar o evento. - -[CDP API Console logs]({{< ref "cdp_api#console-logs-and-errors" >}}) -and [WebDriver BiDi Console logs]({{< ref "../webdriver_bidi/log#console-logs" >}}) - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -Use the [WebDriver BiDi Console logs]({{< ref "../webdriver_bidi/log#console-logs" >}}) implementation. `HasLogEvents` -will likely end up deprecated because it does not implement `Closeable`. -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/BidiApiTest.java#L77-L78" >}} -{{% /tab %}} -{{% tab header="Python" %}} -{{< gh-codeblock path="/examples/python/tests/bidirectional/chrome_devtools/test_bidi_api.py#L23-L26" >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/BidiApiTest.cs#L85-L92" >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/bidi_api_spec.rb#L43-L44" >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-examples >}} -```js -const {Builder} = require('selenium-webdriver'); -(async () => { - try { - let driver = new Builder() - .forBrowser('chrome') - .build(); - - const cdpConnection = await driver.createCDPConnection('page'); - await driver.onLogEvent(cdpConnection, function (event) { - console.log(event['args'][0]['value']); - }); - await driver.executeScript('console.log("here")'); - await driver.quit(); - }catch (e){ - console.log(e); - } -})() -``` -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-examples >}} -```java -fun kotlinConsoleLogExample() { - val driver = ChromeDriver() - val devTools = driver.devTools - devTools.createSession() - - val logConsole = { c: ConsoleEvent -> print("Console log message is: " + c.messages)} - devTools.domains.events().addConsoleListener(logConsole) - - driver.get("https://www.google.com") - - val executor = driver as JavascriptExecutor - executor.executeScript("console.log('Hello World')") - - val input = driver.findElement(By.name("q")) - input.sendKeys("Selenium 4") - input.sendKeys(Keys.RETURN) - driver.quit() -} -``` -{{% /tab %}} -{{< /tabpane >}} - -### JavaScript exceptions - -Vigie as exceções JS -e registre callbacks(retornos de chamada) para processar os detalhes da exceção. - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -Use the [WebDriver BiDi JavaScript exceptions]({{< ref "../webdriver_bidi/log#javascript-exceptions" >}}) implementation -{{% /tab %}} -{{% tab header="Python" %}} -{{< gh-codeblock path="/examples/python/tests/bidirectional/chrome_devtools/test_bidi_api.py#L36-L39" >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/BidiApiTest.cs#L107-L114" >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/bidi_api_spec.rb#L57-L58" >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-implementation >}} -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-code >}} -{{% /tab %}} -{{< /tabpane >}} - - -### Interceptação de Rede - -Both requests and responses can be recorded or transformed. - -#### Response information - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/BidiApiTest.java#L90-L101" >}} -{{% /tab %}} -{{% tab header="Python" %}} -{{< badge-implementation >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/BidiApiTest.cs#L125-L133" >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/bidi_api_spec.rb#L67-L72" >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-implementation >}} -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-code >}} -{{% /tab %}} -{{< /tabpane >}} - -#### Response transformation - -{{< tabpane text=true >}} -{{< tab header="Java" >}} -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/BidiApiTest.java#L111-L121" >}} -{{< /tab >}} -{{< tab header="Python" >}} -{{< badge-implementation >}} -{{< /tab >}} -{{< tab header="CSharp" >}} -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/BidiApiTest.cs#L143-L156" >}} -{{< /tab >}} -{{< tab header="Ruby" >}} -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/bidi_api_spec.rb#L79-L83" >}} -{{< /tab >}} -{{% tab header="JavaScript" %}} -{{< badge-examples >}} -```js -const connection = await driver.createCDPConnection('page') -let url = fileServer.whereIs("/cheese") -let httpResponse = new HttpResponse(url) -httpResponse.addHeaders("Content-Type", "UTF-8") -httpResponse.body = "sausages" -await driver.onIntercept(connection, httpResponse, async function () { - let body = await driver.getPageSource() - assert.strictEqual(body.includes("sausages"), true, `Body contains: ${body}`) -}) -driver.get(url) -``` -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-examples >}} -```java -val driver = ChromeDriver() -val interceptor = new NetworkInterceptor( - driver, - Route.matching(req -> true) - .to(() -> req -> new HttpResponse() - .setStatus(200) - .addHeader("Content-Type", MediaType.HTML_UTF_8.toString()) - .setContent(utf8String("Creamy, delicious cheese!")))) - - driver.get(appServer.whereIs("/cheese")) - - String source = driver.getPageSource() -``` -{{% /tab %}} -{{< /tabpane >}} - -#### Request interception - -{{< tabpane text=true >}} -{{< tab header="Java" >}} -{{< badge-implementation >}} -{{< /tab >}} -{{< tab header="Python" >}} -{{< badge-implementation >}} -{{< /tab >}} -{{< tab header="CSharp" >}} -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/BidiApiTest.cs#L167-L181" >}} -{{< /tab >}} -{{< tab header="Ruby" >}} -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/bidi_api_spec.rb#L90-L94" >}} -{{< /tab >}} -{{< tab header="JavaScript" >}} -{{< badge-code >}} -{{< /tab >}} -{{< tab header="Kotlin" >}} -{{< badge-code >}} -{{< /tab >}} -{{< /tabpane >}} diff --git a/website_and_docs/content/documentation/webdriver/bidirectional/chrome_devtools/bidi_api.zh-cn.md b/website_and_docs/content/documentation/webdriver/bidirectional/chrome_devtools/bidi_api.zh-cn.md deleted file mode 100644 index da625febd386..000000000000 --- a/website_and_docs/content/documentation/webdriver/bidirectional/chrome_devtools/bidi_api.zh-cn.md +++ /dev/null @@ -1,359 +0,0 @@ ---- -title: "Chrome Devtools Protocol with BiDi API" -linkTitle: "BiDi API" -weight: 6 -description: > - These examples are currently implemented with CDP, but the same code should work when the functionality - is re-implemented with WebDriver-BiDi. ---- - -## Usage - -The following list of APIs will be growing as the Selenium -project works through supporting real world use cases. If there -is additional functionality you'd like to see, please raise a -[feature request](https://github.com/SeleniumHQ/selenium/issues/new?assignees=&labels=&template=feature.md). - -As these examples are re-implemented with the [WebDriver-Bidi](https://w3c.github.io/webdriver-bidi) protocol, they will -be moved to the [WebDriver Bidi]({{< ref "../webdriver_bidi/" >}}) pages. - -## Examples - -### Basic authentication - -Some applications make use of browser authentication to secure pages. -It used to be common to handle them in the URL, but browser stopped supporting this. -With BiDi, you can now provide the credentials when necessary - -Alternate implementations can be found at -[CDP Endpoint Basic Authentication]({{< ref "cdp_endpoint#basic-authentication" >}}) -and [CDP API Basic Authentication]({{< ref "cdp_api#basic-authentication" >}}) - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/BidiApiTest.java#L36-L39" >}} -{{% /tab %}} -{{% tab header="Python" %}} -An alternate implementation may be found at -[CDP Endpoint Basic Authentication]({{< ref "cdp_endpoint#basic-authentication" >}}) -{{< badge-implementation >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/BidiApiTest.cs#L18-L27" >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/bidi_api_spec.rb#L9-L11" >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-examples >}} -```js -const {Builder} = require('selenium-webdriver'); - -(async function example() { - try { - let driver = await new Builder() - .forBrowser('chrome') - .build(); - - const pageCdpConnection = await driver.createCDPConnection('page'); - await driver.register('username', 'password', pageCdpConnection); - await driver.get('https://the-internet.herokuapp.com/basic_auth'); - await driver.quit(); - }catch (e){ - console.log(e) - } -}()) -``` -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-examples >}} -```java -val uriPredicate = Predicate { uri: URI -> - uri.host.contains("your-domain.com") - } -(driver as HasAuthentication).register(uriPredicate, UsernameAndPassword.of("admin", "password")) -driver.get("https://your-domain.com/login") -``` -{{% /tab %}} -{{< /tabpane >}} - - -### Pin scripts - -This can be especially useful when executing on a remote server. For example, -whenever you check the visibility of an element, or whenever you use -the classic get attribute method, Selenium is sending the contents of a js file -to the script execution endpoint. These files are each about 50kB, which adds up. - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -{{< badge-implementation >}} -{{% /tab %}} -{{% tab header="Python" %}} -{{< badge-implementation >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/BidiApiTest.cs#L41-L43" >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/bidi_api_spec.rb#L22-L23" >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-implementation >}} -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-code >}} -{{% /tab %}} -{{< /tabpane >}} - - -### Mutation observation - -Mutation Observation is the ability to capture events via -WebDriver BiDi when there are DOM mutations on a specific -element in the DOM. - -{{< tabpane text=true >}} - {{% tab header="Java" %}} -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/BidiApiTest.java#L64-L65" >}} - {{% /tab %}} - {{% tab header="Python" %}} -{{< gh-codeblock path="/examples/python/tests/bidirectional/chrome_devtools/test_bidi_api.py#L9-L11" >}} - {{% /tab %}} - {{% tab header="CSharp" %}} -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/BidiApiTest.cs#L59-L68" >}} - {{% /tab %}} - {{< tab header="Ruby" >}} -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/bidi_api_spec.rb#L31-L32" >}} - {{< /tab >}} - {{% tab header="JavaScript" %}} - {{< badge-examples >}} -```js -const {Builder, until} = require('selenium-webdriver'); -const assert = require("assert"); - -(async function example() { - try { - let driver = await new Builder() - .forBrowser('chrome') - .build(); - - const cdpConnection = await driver.createCDPConnection('page'); - await driver.logMutationEvents(cdpConnection, event => { - assert.deepStrictEqual(event['attribute_name'], 'style'); - assert.deepStrictEqual(event['current_value'], ""); - assert.deepStrictEqual(event['old_value'], "display:none;"); - }); - - await driver.get('dynamic.html'); - await driver.findElement({id: 'reveal'}).click(); - let revealed = driver.findElement({id: 'revealed'}); - await driver.wait(until.elementIsVisible(revealed), 5000); - await driver.quit(); - }catch (e){ - console.log(e) - } -}()) -``` -{{% /tab %}} - {{< tab header="Kotlin" >}} -{{< badge-code >}} - {{< /tab >}} -{{< /tabpane >}} - - -### Console logs and errors - -Listen to the `console.log` events and register callbacks to process the event. - -[CDP API Console logs]({{< ref "cdp_api#console-logs-and-errors" >}}) -and [WebDriver BiDi Console logs]({{< ref "../webdriver_bidi/log#console-logs" >}}) - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -Use the [WebDriver BiDi Console logs]({{< ref "../webdriver_bidi/log#console-logs" >}}) implementation. `HasLogEvents` -will likely end up deprecated because it does not implement `Closeable`. -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/BidiApiTest.java#L77-L78" >}} -{{% /tab %}} -{{% tab header="Python" %}} -{{< gh-codeblock path="/examples/python/tests/bidirectional/chrome_devtools/test_bidi_api.py#L23-L26" >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/BidiApiTest.cs#L85-L92" >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/bidi_api_spec.rb#L43-L44" >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-examples >}} -```js -const {Builder} = require('selenium-webdriver'); -(async () => { - try { - let driver = new Builder() - .forBrowser('chrome') - .build(); - - const cdpConnection = await driver.createCDPConnection('page'); - await driver.onLogEvent(cdpConnection, function (event) { - console.log(event['args'][0]['value']); - }); - await driver.executeScript('console.log("here")'); - await driver.quit(); - }catch (e){ - console.log(e); - } -})() -``` -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-examples >}} -```java -fun kotlinConsoleLogExample() { - val driver = ChromeDriver() - val devTools = driver.devTools - devTools.createSession() - - val logConsole = { c: ConsoleEvent -> print("Console log message is: " + c.messages)} - devTools.domains.events().addConsoleListener(logConsole) - - driver.get("https://www.google.com") - - val executor = driver as JavascriptExecutor - executor.executeScript("console.log('Hello World')") - - val input = driver.findElement(By.name("q")) - input.sendKeys("Selenium 4") - input.sendKeys(Keys.RETURN) - driver.quit() -} -``` -{{% /tab %}} -{{< /tabpane >}} - - -### JavaScript exceptions - -Listen to the JS Exceptions -and register callbacks to process the exception details. - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -Use the [WebDriver BiDi JavaScript exceptions]({{< ref "../webdriver_bidi/log#javascript-exceptions" >}}) implementation -{{% /tab %}} -{{% tab header="Python" %}} -{{< gh-codeblock path="/examples/python/tests/bidirectional/chrome_devtools/test_bidi_api.py#L36-L39" >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/BidiApiTest.cs#L107-L114" >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/bidi_api_spec.rb#L57-L58" >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-implementation >}} -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-code >}} -{{% /tab %}} -{{< /tabpane >}} - - -### Network Interception - -Both requests and responses can be recorded or transformed. - -#### Response information - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/BidiApiTest.java#L90-L101" >}} -{{% /tab %}} -{{% tab header="Python" %}} -{{< badge-implementation >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/BidiApiTest.cs#L125-L133" >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/bidi_api_spec.rb#L67-L72" >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-implementation >}} -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-code >}} -{{% /tab %}} -{{< /tabpane >}} - -#### Response transformation - -{{< tabpane text=true >}} -{{< tab header="Java" >}} -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/BidiApiTest.java#L111-L121" >}} -{{< /tab >}} -{{< tab header="Python" >}} -{{< badge-implementation >}} -{{< /tab >}} -{{< tab header="CSharp" >}} -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/BidiApiTest.cs#L143-L156" >}} -{{< /tab >}} -{{< tab header="Ruby" >}} -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/bidi_api_spec.rb#L79-L83" >}} -{{< /tab >}} -{{% tab header="JavaScript" %}} -{{< badge-examples >}} -```js -const connection = await driver.createCDPConnection('page') -let url = fileServer.whereIs("/cheese") -let httpResponse = new HttpResponse(url) -httpResponse.addHeaders("Content-Type", "UTF-8") -httpResponse.body = "sausages" -await driver.onIntercept(connection, httpResponse, async function () { - let body = await driver.getPageSource() - assert.strictEqual(body.includes("sausages"), true, `Body contains: ${body}`) -}) -driver.get(url) -``` -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-examples >}} -```java -val driver = ChromeDriver() -val interceptor = new NetworkInterceptor( - driver, - Route.matching(req -> true) - .to(() -> req -> new HttpResponse() - .setStatus(200) - .addHeader("Content-Type", MediaType.HTML_UTF_8.toString()) - .setContent(utf8String("Creamy, delicious cheese!")))) - - driver.get(appServer.whereIs("/cheese")) - - String source = driver.getPageSource() -``` -{{% /tab %}} -{{< /tabpane >}} - -#### Request interception - -{{< tabpane text=true >}} -{{< tab header="Java" >}} -{{< badge-implementation >}} -{{< /tab >}} -{{< tab header="Python" >}} -{{< badge-implementation >}} -{{< /tab >}} -{{< tab header="CSharp" >}} -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/BidiApiTest.cs#L167-L181" >}} -{{< /tab >}} -{{< tab header="Ruby" >}} -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/bidi_api_spec.rb#L90-L94" >}} -{{< /tab >}} -{{< tab header="JavaScript" >}} -{{< badge-code >}} -{{< /tab >}} -{{< tab header="Kotlin" >}} -{{< badge-code >}} -{{< /tab >}} -{{< /tabpane >}} diff --git a/website_and_docs/content/documentation/webdriver/bidirectional/chrome_devtools/cdp_api.en.md b/website_and_docs/content/documentation/webdriver/bidirectional/chrome_devtools/cdp_api.en.md deleted file mode 100644 index 54cb54f6c961..000000000000 --- a/website_and_docs/content/documentation/webdriver/bidirectional/chrome_devtools/cdp_api.en.md +++ /dev/null @@ -1,208 +0,0 @@ ---- -title: "Chrome DevTools Protocol API" -linkTitle: "CDP API" -weight: 4 -description: > - Each of the Selenium bindings dynamically generates classes and methods for the various CDP domains and features; - these are tied to specific versions of Chrome. ---- - -{{% pageinfo color="warning" %}} -While Selenium 4 provides direct access to the Chrome DevTools Protocol (CDP), these -methods will eventually be removed. It is recommended to use the [WebDriver Bidi APIs]({{< ref "bidi_api.md" >}}) -methods where possible to ensure future compatibility. -{{% /pageinfo %}} - -## Usage - -If your use case has been implemented by [WebDriver Bidi]({{< ref "../webdriver_bidi/" >}}) or -the [BiDi API]({{< ref "bidi_api.md" >}}), you should use those implementations instead of this one. -Generally you should prefer this approach over executing with the [CDP Endpoint]({{< ref "cdp_endpoint.md" >}}), -especially in Ruby. - - -## Examples - -### Set Cookie - -An alternate implementation can be found at [CDP Endpoint Set Cookie]({{< ref "cdp_endpoint#set-cookie" >}}) - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -Because Java requires using all the parameters example, the Map approach used in -[CDP Endpoint Set Cookie]({{< ref "cdp_endpoint#set-cookie" >}}) might be more simple. -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/CdpApiTest.java#L47-L65" >}} -{{% /tab %}} -{{% tab header="Python" %}} -Because Python requires using async methods for this example, the synchronous approach found in -[CDP Endpoint Set Cookie]({{< ref "cdp_endpoint#set-cookie" >}}) might be easier. -{{< gh-codeblock path="/examples/python/tests/bidirectional/chrome_devtools/test_cdp_api.py#L10-L18" >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -Due to the added complexity in .NET of obtaining the domains and executing with awaits, the -[CDP Endpoint Set Cookie]({{< ref "cdp_endpoint#set-cookie" >}}) might be easier. -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/CdpApiTest.cs#L25-L37" >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/cdp_api_spec.rb#L9-L12" >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-code >}} -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-code >}} -{{% /tab %}} -{{< /tabpane >}} - -### Performance Metrics - -An alternate implementation can be found at [CDP Endpoint Performance Metrics]({{< ref "cdp_endpoint#performance-metrics" >}}) - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/CdpApiTest.java#L77-L81" >}} -{{% /tab %}} -{{% tab header="Python" %}} -Because Python requires using async methods for this example, the synchronous approach found in -[CDP Endpoint Performance Metrics]({{< ref "cdp_endpoint#performance-metrics" >}}) might be easier. -{{< gh-codeblock path="/examples/python/tests/bidirectional/chrome_devtools/test_cdp_api.py#L30-L33" >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -Due to the added complexity in .NET of obtaining the domains and executing with awaits, the -[CDP Endpoint Performance Metrics]({{< ref "cdp_endpoint#performance-metrics" >}}) might be easier. -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/CdpApiTest.cs#L49-L56" >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/cdp_api_spec.rb#L23-L25" >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-code >}} -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-code >}} -{{% /tab %}} -{{< /tabpane >}} - -### Basic authentication - -Alternate implementations can be found at -[CDP Endpoint Basic Authentication]({{< ref "cdp_endpoint#basic-authentication" >}}) -and [BiDi API Basic Authentication]({{< ref "bidi_api#basic-authentication" >}}) - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -The [BiDi API Basic Authentication]({{< ref "bidi_api#basic-authentication" >}}) implementation should be preferred -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/CdpApiTest.java#L94-L101" >}} -{{% /tab %}} -{{% tab header="Python" %}} -Because Python requires using async methods for this example, the synchronous approach found in -[CDP Endpoint Basic Authentication]({{< ref "cdp_endpoint#basic-authentication" >}}) might be easier. -{{< gh-codeblock path="/examples/python/tests/bidirectional/chrome_devtools/test_cdp_api.py#L43-L49" >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -Due to the added complexity in .NET of obtaining the domains and executing with awaits, the -[CDP Endpoint Basic Authentication]({{< ref "cdp_endpoint#basic-authentication" >}}) might be easier. -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/CdpApiTest.cs#L70-L83" >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -The [BiDi API Basic Authentication]({{< ref "bidi_api#basic-authentication" >}}) implementation should be preferred -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/cdp_api_spec.rb#L36-L40" >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-code >}} -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-code >}} -{{% /tab %}} -{{< /tabpane >}} - -### Console logs - -Because reading console logs requires setting an event listener, -this cannot be done with a CDP Endpoint implementation -Alternate implementations can be found at -[BiDi API Console logs and errors]({{< ref "bidi_api#console-logs-and-errors" >}}) -and [WebDriver BiDi Console logs]({{< ref "../webdriver_bidi/log#console-logs" >}}) - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -Use the [WebDriver BiDi Console logs]({{< ref "../webdriver_bidi/log#console-logs" >}}) implementation -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/CdpApiTest.java#L114-L121" >}} -{{% /tab %}} -{{% tab header="Python" %}} -Use the [BiDi API Console logs and errors]({{< ref "bidi_api#console-logs-and-errors" >}}) implementation -{{< badge-code >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -Use the [BiDi API Console logs and errors]({{< ref "bidi_api#console-logs-and-errors" >}}) implementation -{{< badge-code >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -The [BiDi API Console logs and errors]({{< ref "bidi_api#console-logs-and-errors" >}}) implementation should be preferred -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/cdp_api_spec.rb#L50-L55" >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-code >}} -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-code >}} -{{% /tab %}} -{{< /tabpane >}} - -### JavaScript exceptions - -Similar to console logs, but this listens for actual javascript exceptions not just logged errors -Alternate implementations can be found at -[BiDi API JavaScript exceptions]({{< ref "bidi_api#javascript-exceptions" >}}) -and [WebDriver BiDi JavaScript exceptions]({{< ref "../webdriver_bidi/log#javascript-exceptions" >}}) - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -Use the [WebDriver BiDi JavaScript exceptions]({{< ref "../webdriver_bidi/log#javascript-exceptions" >}}) implementation -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/CdpApiTest.java#L133-L138" >}} -{{% /tab %}} -{{% tab header="Python" %}} -Use the [BiDi API JavaScript exceptions]({{< ref "bidi_api#javascript-exceptions" >}}) implementation -{{< badge-code >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -Use the [BiDi API JavaScript exceptions]({{< ref "bidi_api#javascript-exceptions" >}}) implementation -{{< badge-code >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -Use the [BiDi API JavaScript exceptions]({{< ref "bidi_api#javascript-exceptions" >}}) implementation -{{< badge-code >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-code >}} -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-code >}} -{{% /tab %}} -{{< /tabpane >}} - -### Download complete - -Wait for a download to finish before continuing. -Because getting download status requires setting a listener, this cannot be done with a CDP Endpoint implementation. - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/CdpApiTest.java#L150-L162" >}} -{{% /tab %}} -{{% tab header="Python" %}} -{{< badge-code >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -{{< badge-code >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/cdp_api_spec.rb#L66-L72" >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-code >}} -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-code >}} -{{% /tab %}} -{{< /tabpane >}} diff --git a/website_and_docs/content/documentation/webdriver/bidirectional/chrome_devtools/cdp_api.ja.md b/website_and_docs/content/documentation/webdriver/bidirectional/chrome_devtools/cdp_api.ja.md deleted file mode 100644 index 54cb54f6c961..000000000000 --- a/website_and_docs/content/documentation/webdriver/bidirectional/chrome_devtools/cdp_api.ja.md +++ /dev/null @@ -1,208 +0,0 @@ ---- -title: "Chrome DevTools Protocol API" -linkTitle: "CDP API" -weight: 4 -description: > - Each of the Selenium bindings dynamically generates classes and methods for the various CDP domains and features; - these are tied to specific versions of Chrome. ---- - -{{% pageinfo color="warning" %}} -While Selenium 4 provides direct access to the Chrome DevTools Protocol (CDP), these -methods will eventually be removed. It is recommended to use the [WebDriver Bidi APIs]({{< ref "bidi_api.md" >}}) -methods where possible to ensure future compatibility. -{{% /pageinfo %}} - -## Usage - -If your use case has been implemented by [WebDriver Bidi]({{< ref "../webdriver_bidi/" >}}) or -the [BiDi API]({{< ref "bidi_api.md" >}}), you should use those implementations instead of this one. -Generally you should prefer this approach over executing with the [CDP Endpoint]({{< ref "cdp_endpoint.md" >}}), -especially in Ruby. - - -## Examples - -### Set Cookie - -An alternate implementation can be found at [CDP Endpoint Set Cookie]({{< ref "cdp_endpoint#set-cookie" >}}) - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -Because Java requires using all the parameters example, the Map approach used in -[CDP Endpoint Set Cookie]({{< ref "cdp_endpoint#set-cookie" >}}) might be more simple. -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/CdpApiTest.java#L47-L65" >}} -{{% /tab %}} -{{% tab header="Python" %}} -Because Python requires using async methods for this example, the synchronous approach found in -[CDP Endpoint Set Cookie]({{< ref "cdp_endpoint#set-cookie" >}}) might be easier. -{{< gh-codeblock path="/examples/python/tests/bidirectional/chrome_devtools/test_cdp_api.py#L10-L18" >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -Due to the added complexity in .NET of obtaining the domains and executing with awaits, the -[CDP Endpoint Set Cookie]({{< ref "cdp_endpoint#set-cookie" >}}) might be easier. -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/CdpApiTest.cs#L25-L37" >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/cdp_api_spec.rb#L9-L12" >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-code >}} -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-code >}} -{{% /tab %}} -{{< /tabpane >}} - -### Performance Metrics - -An alternate implementation can be found at [CDP Endpoint Performance Metrics]({{< ref "cdp_endpoint#performance-metrics" >}}) - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/CdpApiTest.java#L77-L81" >}} -{{% /tab %}} -{{% tab header="Python" %}} -Because Python requires using async methods for this example, the synchronous approach found in -[CDP Endpoint Performance Metrics]({{< ref "cdp_endpoint#performance-metrics" >}}) might be easier. -{{< gh-codeblock path="/examples/python/tests/bidirectional/chrome_devtools/test_cdp_api.py#L30-L33" >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -Due to the added complexity in .NET of obtaining the domains and executing with awaits, the -[CDP Endpoint Performance Metrics]({{< ref "cdp_endpoint#performance-metrics" >}}) might be easier. -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/CdpApiTest.cs#L49-L56" >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/cdp_api_spec.rb#L23-L25" >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-code >}} -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-code >}} -{{% /tab %}} -{{< /tabpane >}} - -### Basic authentication - -Alternate implementations can be found at -[CDP Endpoint Basic Authentication]({{< ref "cdp_endpoint#basic-authentication" >}}) -and [BiDi API Basic Authentication]({{< ref "bidi_api#basic-authentication" >}}) - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -The [BiDi API Basic Authentication]({{< ref "bidi_api#basic-authentication" >}}) implementation should be preferred -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/CdpApiTest.java#L94-L101" >}} -{{% /tab %}} -{{% tab header="Python" %}} -Because Python requires using async methods for this example, the synchronous approach found in -[CDP Endpoint Basic Authentication]({{< ref "cdp_endpoint#basic-authentication" >}}) might be easier. -{{< gh-codeblock path="/examples/python/tests/bidirectional/chrome_devtools/test_cdp_api.py#L43-L49" >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -Due to the added complexity in .NET of obtaining the domains and executing with awaits, the -[CDP Endpoint Basic Authentication]({{< ref "cdp_endpoint#basic-authentication" >}}) might be easier. -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/CdpApiTest.cs#L70-L83" >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -The [BiDi API Basic Authentication]({{< ref "bidi_api#basic-authentication" >}}) implementation should be preferred -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/cdp_api_spec.rb#L36-L40" >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-code >}} -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-code >}} -{{% /tab %}} -{{< /tabpane >}} - -### Console logs - -Because reading console logs requires setting an event listener, -this cannot be done with a CDP Endpoint implementation -Alternate implementations can be found at -[BiDi API Console logs and errors]({{< ref "bidi_api#console-logs-and-errors" >}}) -and [WebDriver BiDi Console logs]({{< ref "../webdriver_bidi/log#console-logs" >}}) - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -Use the [WebDriver BiDi Console logs]({{< ref "../webdriver_bidi/log#console-logs" >}}) implementation -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/CdpApiTest.java#L114-L121" >}} -{{% /tab %}} -{{% tab header="Python" %}} -Use the [BiDi API Console logs and errors]({{< ref "bidi_api#console-logs-and-errors" >}}) implementation -{{< badge-code >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -Use the [BiDi API Console logs and errors]({{< ref "bidi_api#console-logs-and-errors" >}}) implementation -{{< badge-code >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -The [BiDi API Console logs and errors]({{< ref "bidi_api#console-logs-and-errors" >}}) implementation should be preferred -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/cdp_api_spec.rb#L50-L55" >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-code >}} -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-code >}} -{{% /tab %}} -{{< /tabpane >}} - -### JavaScript exceptions - -Similar to console logs, but this listens for actual javascript exceptions not just logged errors -Alternate implementations can be found at -[BiDi API JavaScript exceptions]({{< ref "bidi_api#javascript-exceptions" >}}) -and [WebDriver BiDi JavaScript exceptions]({{< ref "../webdriver_bidi/log#javascript-exceptions" >}}) - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -Use the [WebDriver BiDi JavaScript exceptions]({{< ref "../webdriver_bidi/log#javascript-exceptions" >}}) implementation -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/CdpApiTest.java#L133-L138" >}} -{{% /tab %}} -{{% tab header="Python" %}} -Use the [BiDi API JavaScript exceptions]({{< ref "bidi_api#javascript-exceptions" >}}) implementation -{{< badge-code >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -Use the [BiDi API JavaScript exceptions]({{< ref "bidi_api#javascript-exceptions" >}}) implementation -{{< badge-code >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -Use the [BiDi API JavaScript exceptions]({{< ref "bidi_api#javascript-exceptions" >}}) implementation -{{< badge-code >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-code >}} -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-code >}} -{{% /tab %}} -{{< /tabpane >}} - -### Download complete - -Wait for a download to finish before continuing. -Because getting download status requires setting a listener, this cannot be done with a CDP Endpoint implementation. - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/CdpApiTest.java#L150-L162" >}} -{{% /tab %}} -{{% tab header="Python" %}} -{{< badge-code >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -{{< badge-code >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/cdp_api_spec.rb#L66-L72" >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-code >}} -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-code >}} -{{% /tab %}} -{{< /tabpane >}} diff --git a/website_and_docs/content/documentation/webdriver/bidirectional/chrome_devtools/cdp_api.pt-br.md b/website_and_docs/content/documentation/webdriver/bidirectional/chrome_devtools/cdp_api.pt-br.md deleted file mode 100644 index 54cb54f6c961..000000000000 --- a/website_and_docs/content/documentation/webdriver/bidirectional/chrome_devtools/cdp_api.pt-br.md +++ /dev/null @@ -1,208 +0,0 @@ ---- -title: "Chrome DevTools Protocol API" -linkTitle: "CDP API" -weight: 4 -description: > - Each of the Selenium bindings dynamically generates classes and methods for the various CDP domains and features; - these are tied to specific versions of Chrome. ---- - -{{% pageinfo color="warning" %}} -While Selenium 4 provides direct access to the Chrome DevTools Protocol (CDP), these -methods will eventually be removed. It is recommended to use the [WebDriver Bidi APIs]({{< ref "bidi_api.md" >}}) -methods where possible to ensure future compatibility. -{{% /pageinfo %}} - -## Usage - -If your use case has been implemented by [WebDriver Bidi]({{< ref "../webdriver_bidi/" >}}) or -the [BiDi API]({{< ref "bidi_api.md" >}}), you should use those implementations instead of this one. -Generally you should prefer this approach over executing with the [CDP Endpoint]({{< ref "cdp_endpoint.md" >}}), -especially in Ruby. - - -## Examples - -### Set Cookie - -An alternate implementation can be found at [CDP Endpoint Set Cookie]({{< ref "cdp_endpoint#set-cookie" >}}) - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -Because Java requires using all the parameters example, the Map approach used in -[CDP Endpoint Set Cookie]({{< ref "cdp_endpoint#set-cookie" >}}) might be more simple. -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/CdpApiTest.java#L47-L65" >}} -{{% /tab %}} -{{% tab header="Python" %}} -Because Python requires using async methods for this example, the synchronous approach found in -[CDP Endpoint Set Cookie]({{< ref "cdp_endpoint#set-cookie" >}}) might be easier. -{{< gh-codeblock path="/examples/python/tests/bidirectional/chrome_devtools/test_cdp_api.py#L10-L18" >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -Due to the added complexity in .NET of obtaining the domains and executing with awaits, the -[CDP Endpoint Set Cookie]({{< ref "cdp_endpoint#set-cookie" >}}) might be easier. -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/CdpApiTest.cs#L25-L37" >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/cdp_api_spec.rb#L9-L12" >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-code >}} -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-code >}} -{{% /tab %}} -{{< /tabpane >}} - -### Performance Metrics - -An alternate implementation can be found at [CDP Endpoint Performance Metrics]({{< ref "cdp_endpoint#performance-metrics" >}}) - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/CdpApiTest.java#L77-L81" >}} -{{% /tab %}} -{{% tab header="Python" %}} -Because Python requires using async methods for this example, the synchronous approach found in -[CDP Endpoint Performance Metrics]({{< ref "cdp_endpoint#performance-metrics" >}}) might be easier. -{{< gh-codeblock path="/examples/python/tests/bidirectional/chrome_devtools/test_cdp_api.py#L30-L33" >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -Due to the added complexity in .NET of obtaining the domains and executing with awaits, the -[CDP Endpoint Performance Metrics]({{< ref "cdp_endpoint#performance-metrics" >}}) might be easier. -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/CdpApiTest.cs#L49-L56" >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/cdp_api_spec.rb#L23-L25" >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-code >}} -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-code >}} -{{% /tab %}} -{{< /tabpane >}} - -### Basic authentication - -Alternate implementations can be found at -[CDP Endpoint Basic Authentication]({{< ref "cdp_endpoint#basic-authentication" >}}) -and [BiDi API Basic Authentication]({{< ref "bidi_api#basic-authentication" >}}) - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -The [BiDi API Basic Authentication]({{< ref "bidi_api#basic-authentication" >}}) implementation should be preferred -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/CdpApiTest.java#L94-L101" >}} -{{% /tab %}} -{{% tab header="Python" %}} -Because Python requires using async methods for this example, the synchronous approach found in -[CDP Endpoint Basic Authentication]({{< ref "cdp_endpoint#basic-authentication" >}}) might be easier. -{{< gh-codeblock path="/examples/python/tests/bidirectional/chrome_devtools/test_cdp_api.py#L43-L49" >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -Due to the added complexity in .NET of obtaining the domains and executing with awaits, the -[CDP Endpoint Basic Authentication]({{< ref "cdp_endpoint#basic-authentication" >}}) might be easier. -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/CdpApiTest.cs#L70-L83" >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -The [BiDi API Basic Authentication]({{< ref "bidi_api#basic-authentication" >}}) implementation should be preferred -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/cdp_api_spec.rb#L36-L40" >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-code >}} -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-code >}} -{{% /tab %}} -{{< /tabpane >}} - -### Console logs - -Because reading console logs requires setting an event listener, -this cannot be done with a CDP Endpoint implementation -Alternate implementations can be found at -[BiDi API Console logs and errors]({{< ref "bidi_api#console-logs-and-errors" >}}) -and [WebDriver BiDi Console logs]({{< ref "../webdriver_bidi/log#console-logs" >}}) - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -Use the [WebDriver BiDi Console logs]({{< ref "../webdriver_bidi/log#console-logs" >}}) implementation -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/CdpApiTest.java#L114-L121" >}} -{{% /tab %}} -{{% tab header="Python" %}} -Use the [BiDi API Console logs and errors]({{< ref "bidi_api#console-logs-and-errors" >}}) implementation -{{< badge-code >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -Use the [BiDi API Console logs and errors]({{< ref "bidi_api#console-logs-and-errors" >}}) implementation -{{< badge-code >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -The [BiDi API Console logs and errors]({{< ref "bidi_api#console-logs-and-errors" >}}) implementation should be preferred -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/cdp_api_spec.rb#L50-L55" >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-code >}} -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-code >}} -{{% /tab %}} -{{< /tabpane >}} - -### JavaScript exceptions - -Similar to console logs, but this listens for actual javascript exceptions not just logged errors -Alternate implementations can be found at -[BiDi API JavaScript exceptions]({{< ref "bidi_api#javascript-exceptions" >}}) -and [WebDriver BiDi JavaScript exceptions]({{< ref "../webdriver_bidi/log#javascript-exceptions" >}}) - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -Use the [WebDriver BiDi JavaScript exceptions]({{< ref "../webdriver_bidi/log#javascript-exceptions" >}}) implementation -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/CdpApiTest.java#L133-L138" >}} -{{% /tab %}} -{{% tab header="Python" %}} -Use the [BiDi API JavaScript exceptions]({{< ref "bidi_api#javascript-exceptions" >}}) implementation -{{< badge-code >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -Use the [BiDi API JavaScript exceptions]({{< ref "bidi_api#javascript-exceptions" >}}) implementation -{{< badge-code >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -Use the [BiDi API JavaScript exceptions]({{< ref "bidi_api#javascript-exceptions" >}}) implementation -{{< badge-code >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-code >}} -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-code >}} -{{% /tab %}} -{{< /tabpane >}} - -### Download complete - -Wait for a download to finish before continuing. -Because getting download status requires setting a listener, this cannot be done with a CDP Endpoint implementation. - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/CdpApiTest.java#L150-L162" >}} -{{% /tab %}} -{{% tab header="Python" %}} -{{< badge-code >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -{{< badge-code >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/cdp_api_spec.rb#L66-L72" >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-code >}} -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-code >}} -{{% /tab %}} -{{< /tabpane >}} diff --git a/website_and_docs/content/documentation/webdriver/bidirectional/chrome_devtools/cdp_api.zh-cn.md b/website_and_docs/content/documentation/webdriver/bidirectional/chrome_devtools/cdp_api.zh-cn.md deleted file mode 100644 index 54cb54f6c961..000000000000 --- a/website_and_docs/content/documentation/webdriver/bidirectional/chrome_devtools/cdp_api.zh-cn.md +++ /dev/null @@ -1,208 +0,0 @@ ---- -title: "Chrome DevTools Protocol API" -linkTitle: "CDP API" -weight: 4 -description: > - Each of the Selenium bindings dynamically generates classes and methods for the various CDP domains and features; - these are tied to specific versions of Chrome. ---- - -{{% pageinfo color="warning" %}} -While Selenium 4 provides direct access to the Chrome DevTools Protocol (CDP), these -methods will eventually be removed. It is recommended to use the [WebDriver Bidi APIs]({{< ref "bidi_api.md" >}}) -methods where possible to ensure future compatibility. -{{% /pageinfo %}} - -## Usage - -If your use case has been implemented by [WebDriver Bidi]({{< ref "../webdriver_bidi/" >}}) or -the [BiDi API]({{< ref "bidi_api.md" >}}), you should use those implementations instead of this one. -Generally you should prefer this approach over executing with the [CDP Endpoint]({{< ref "cdp_endpoint.md" >}}), -especially in Ruby. - - -## Examples - -### Set Cookie - -An alternate implementation can be found at [CDP Endpoint Set Cookie]({{< ref "cdp_endpoint#set-cookie" >}}) - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -Because Java requires using all the parameters example, the Map approach used in -[CDP Endpoint Set Cookie]({{< ref "cdp_endpoint#set-cookie" >}}) might be more simple. -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/CdpApiTest.java#L47-L65" >}} -{{% /tab %}} -{{% tab header="Python" %}} -Because Python requires using async methods for this example, the synchronous approach found in -[CDP Endpoint Set Cookie]({{< ref "cdp_endpoint#set-cookie" >}}) might be easier. -{{< gh-codeblock path="/examples/python/tests/bidirectional/chrome_devtools/test_cdp_api.py#L10-L18" >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -Due to the added complexity in .NET of obtaining the domains and executing with awaits, the -[CDP Endpoint Set Cookie]({{< ref "cdp_endpoint#set-cookie" >}}) might be easier. -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/CdpApiTest.cs#L25-L37" >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/cdp_api_spec.rb#L9-L12" >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-code >}} -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-code >}} -{{% /tab %}} -{{< /tabpane >}} - -### Performance Metrics - -An alternate implementation can be found at [CDP Endpoint Performance Metrics]({{< ref "cdp_endpoint#performance-metrics" >}}) - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/CdpApiTest.java#L77-L81" >}} -{{% /tab %}} -{{% tab header="Python" %}} -Because Python requires using async methods for this example, the synchronous approach found in -[CDP Endpoint Performance Metrics]({{< ref "cdp_endpoint#performance-metrics" >}}) might be easier. -{{< gh-codeblock path="/examples/python/tests/bidirectional/chrome_devtools/test_cdp_api.py#L30-L33" >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -Due to the added complexity in .NET of obtaining the domains and executing with awaits, the -[CDP Endpoint Performance Metrics]({{< ref "cdp_endpoint#performance-metrics" >}}) might be easier. -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/CdpApiTest.cs#L49-L56" >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/cdp_api_spec.rb#L23-L25" >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-code >}} -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-code >}} -{{% /tab %}} -{{< /tabpane >}} - -### Basic authentication - -Alternate implementations can be found at -[CDP Endpoint Basic Authentication]({{< ref "cdp_endpoint#basic-authentication" >}}) -and [BiDi API Basic Authentication]({{< ref "bidi_api#basic-authentication" >}}) - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -The [BiDi API Basic Authentication]({{< ref "bidi_api#basic-authentication" >}}) implementation should be preferred -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/CdpApiTest.java#L94-L101" >}} -{{% /tab %}} -{{% tab header="Python" %}} -Because Python requires using async methods for this example, the synchronous approach found in -[CDP Endpoint Basic Authentication]({{< ref "cdp_endpoint#basic-authentication" >}}) might be easier. -{{< gh-codeblock path="/examples/python/tests/bidirectional/chrome_devtools/test_cdp_api.py#L43-L49" >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -Due to the added complexity in .NET of obtaining the domains and executing with awaits, the -[CDP Endpoint Basic Authentication]({{< ref "cdp_endpoint#basic-authentication" >}}) might be easier. -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/CdpApiTest.cs#L70-L83" >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -The [BiDi API Basic Authentication]({{< ref "bidi_api#basic-authentication" >}}) implementation should be preferred -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/cdp_api_spec.rb#L36-L40" >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-code >}} -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-code >}} -{{% /tab %}} -{{< /tabpane >}} - -### Console logs - -Because reading console logs requires setting an event listener, -this cannot be done with a CDP Endpoint implementation -Alternate implementations can be found at -[BiDi API Console logs and errors]({{< ref "bidi_api#console-logs-and-errors" >}}) -and [WebDriver BiDi Console logs]({{< ref "../webdriver_bidi/log#console-logs" >}}) - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -Use the [WebDriver BiDi Console logs]({{< ref "../webdriver_bidi/log#console-logs" >}}) implementation -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/CdpApiTest.java#L114-L121" >}} -{{% /tab %}} -{{% tab header="Python" %}} -Use the [BiDi API Console logs and errors]({{< ref "bidi_api#console-logs-and-errors" >}}) implementation -{{< badge-code >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -Use the [BiDi API Console logs and errors]({{< ref "bidi_api#console-logs-and-errors" >}}) implementation -{{< badge-code >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -The [BiDi API Console logs and errors]({{< ref "bidi_api#console-logs-and-errors" >}}) implementation should be preferred -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/cdp_api_spec.rb#L50-L55" >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-code >}} -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-code >}} -{{% /tab %}} -{{< /tabpane >}} - -### JavaScript exceptions - -Similar to console logs, but this listens for actual javascript exceptions not just logged errors -Alternate implementations can be found at -[BiDi API JavaScript exceptions]({{< ref "bidi_api#javascript-exceptions" >}}) -and [WebDriver BiDi JavaScript exceptions]({{< ref "../webdriver_bidi/log#javascript-exceptions" >}}) - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -Use the [WebDriver BiDi JavaScript exceptions]({{< ref "../webdriver_bidi/log#javascript-exceptions" >}}) implementation -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/CdpApiTest.java#L133-L138" >}} -{{% /tab %}} -{{% tab header="Python" %}} -Use the [BiDi API JavaScript exceptions]({{< ref "bidi_api#javascript-exceptions" >}}) implementation -{{< badge-code >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -Use the [BiDi API JavaScript exceptions]({{< ref "bidi_api#javascript-exceptions" >}}) implementation -{{< badge-code >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -Use the [BiDi API JavaScript exceptions]({{< ref "bidi_api#javascript-exceptions" >}}) implementation -{{< badge-code >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-code >}} -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-code >}} -{{% /tab %}} -{{< /tabpane >}} - -### Download complete - -Wait for a download to finish before continuing. -Because getting download status requires setting a listener, this cannot be done with a CDP Endpoint implementation. - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/CdpApiTest.java#L150-L162" >}} -{{% /tab %}} -{{% tab header="Python" %}} -{{< badge-code >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -{{< badge-code >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/cdp_api_spec.rb#L66-L72" >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-code >}} -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-code >}} -{{% /tab %}} -{{< /tabpane >}} diff --git a/website_and_docs/content/documentation/webdriver/bidirectional/chrome_devtools/cdp_endpoint.en.md b/website_and_docs/content/documentation/webdriver/bidirectional/chrome_devtools/cdp_endpoint.en.md deleted file mode 100644 index b388d2ccdbb7..000000000000 --- a/website_and_docs/content/documentation/webdriver/bidirectional/chrome_devtools/cdp_endpoint.en.md +++ /dev/null @@ -1,108 +0,0 @@ ---- -title: "Chrome DevTools Protocol Endpoint" -linkTitle: "CDP Endpoint" -weight: 2 -description: > - Google provides a `/cdp/execute` endpoint that can be accessed directly. Each Selenium binding provides a method that - allows you to pass the CDP domain as a String, and the required parameters as a simple Map. ---- - -{{% pageinfo color="warning" %}} -These methods will eventually be removed. It is recommended to use the [WebDriver-BiDi]({{< ref "../webdriver_bidi/" >}}) or [WebDriver Bidi APIs]({{< ref "bidi_api.md" >}}) -methods where possible to ensure future compatibility. -{{% /pageinfo %}} - - -## Usage - -Generally you should prefer the use of the [CDP API]({{< ref "cdp_api.md" >}}) over this approach, -but sometimes the syntax is cleaner or significantly more simple. - -Limitations include: -* It only works for use cases that are limited to setting or getting information; -any actual asynchronous interactions require another implementation -* You have to know the exactly correct "magic strings" for domains and keys -* It is possible that an update to Chrome will change the required parameters - -## Examples - -### Set Cookie - -An alternate implementation can be found at [CDP API Set Cookie]({{< ref "cdp_api#set-cookie" >}}) - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/CdpEndpointTest.java#L26-32" >}} -{{% /tab %}} -{{% tab header="Python" %}} -{{< gh-codeblock path="/examples/python/tests/bidirectional/chrome_devtools/test_cdp_endpoint.py#L7-L12" >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/CdpEndpointTest.cs#L25-L33" >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -The [CDP API Set Cookie]({{< ref "cdp_api#set-cookie" >}}) implementation should be preferred -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/cdp_endpoint_spec.rb#L9-L14" >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-code >}} -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-code >}} -{{% /tab %}} -{{< /tabpane >}} - -### Performance Metrics - -An alternate implementation can be found at [CDP API Performance Metrics]({{< ref "cdp_api#performance-metrics" >}}) - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -The [CDP API Performance Metrics]({{< ref "cdp_api#performance-metrics" >}}) implementation should be preferred -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/CdpEndpointTest.java#L43-L46" >}} -{{% /tab %}} -{{% tab header="Python" %}} -{{< gh-codeblock path="/examples/python/tests/bidirectional/chrome_devtools/test_cdp_endpoint.py#L23-L25" >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/CdpEndpointTest.cs#L46-L49" >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -The [CDP API Performance Metrics]({{< ref "cdp_api#performance-metrics" >}}) implementation should be preferred -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/cdp_endpoint_spec.rb#L25-L27" >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-code >}} -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-code >}} -{{% /tab %}} -{{< /tabpane >}} - -### Basic authentication - -Alternate implementations can be found at [CDP API Basic Authentication]({{< ref "cdp_api#basic-authentication" >}}) -and [BiDi API Basic Authentication]({{< ref "bidi_api#basic-authentication" >}}) - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -The [BiDi API Basic Authentication]({{< ref "bidi_api#basic-authentication" >}}) implementation should be preferred -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/CdpEndpointTest.java#L60-L66" >}} -{{% /tab %}} -{{% tab header="Python" %}} -{{< gh-codeblock path="/examples/python/tests/bidirectional/chrome_devtools/test_cdp_endpoint.py#L34-L39" >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/CdpEndpointTest.cs#L65-L73" >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -The [BiDi API Basic Authentication]({{< ref "bidi_api#basic-authentication" >}}) implementation should be preferred -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/cdp_endpoint_spec.rb#L38-L43" >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-code >}} -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-code >}} -{{% /tab %}} -{{< /tabpane >}} diff --git a/website_and_docs/content/documentation/webdriver/bidirectional/chrome_devtools/cdp_endpoint.ja.md b/website_and_docs/content/documentation/webdriver/bidirectional/chrome_devtools/cdp_endpoint.ja.md deleted file mode 100644 index b388d2ccdbb7..000000000000 --- a/website_and_docs/content/documentation/webdriver/bidirectional/chrome_devtools/cdp_endpoint.ja.md +++ /dev/null @@ -1,108 +0,0 @@ ---- -title: "Chrome DevTools Protocol Endpoint" -linkTitle: "CDP Endpoint" -weight: 2 -description: > - Google provides a `/cdp/execute` endpoint that can be accessed directly. Each Selenium binding provides a method that - allows you to pass the CDP domain as a String, and the required parameters as a simple Map. ---- - -{{% pageinfo color="warning" %}} -These methods will eventually be removed. It is recommended to use the [WebDriver-BiDi]({{< ref "../webdriver_bidi/" >}}) or [WebDriver Bidi APIs]({{< ref "bidi_api.md" >}}) -methods where possible to ensure future compatibility. -{{% /pageinfo %}} - - -## Usage - -Generally you should prefer the use of the [CDP API]({{< ref "cdp_api.md" >}}) over this approach, -but sometimes the syntax is cleaner or significantly more simple. - -Limitations include: -* It only works for use cases that are limited to setting or getting information; -any actual asynchronous interactions require another implementation -* You have to know the exactly correct "magic strings" for domains and keys -* It is possible that an update to Chrome will change the required parameters - -## Examples - -### Set Cookie - -An alternate implementation can be found at [CDP API Set Cookie]({{< ref "cdp_api#set-cookie" >}}) - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/CdpEndpointTest.java#L26-32" >}} -{{% /tab %}} -{{% tab header="Python" %}} -{{< gh-codeblock path="/examples/python/tests/bidirectional/chrome_devtools/test_cdp_endpoint.py#L7-L12" >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/CdpEndpointTest.cs#L25-L33" >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -The [CDP API Set Cookie]({{< ref "cdp_api#set-cookie" >}}) implementation should be preferred -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/cdp_endpoint_spec.rb#L9-L14" >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-code >}} -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-code >}} -{{% /tab %}} -{{< /tabpane >}} - -### Performance Metrics - -An alternate implementation can be found at [CDP API Performance Metrics]({{< ref "cdp_api#performance-metrics" >}}) - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -The [CDP API Performance Metrics]({{< ref "cdp_api#performance-metrics" >}}) implementation should be preferred -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/CdpEndpointTest.java#L43-L46" >}} -{{% /tab %}} -{{% tab header="Python" %}} -{{< gh-codeblock path="/examples/python/tests/bidirectional/chrome_devtools/test_cdp_endpoint.py#L23-L25" >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/CdpEndpointTest.cs#L46-L49" >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -The [CDP API Performance Metrics]({{< ref "cdp_api#performance-metrics" >}}) implementation should be preferred -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/cdp_endpoint_spec.rb#L25-L27" >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-code >}} -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-code >}} -{{% /tab %}} -{{< /tabpane >}} - -### Basic authentication - -Alternate implementations can be found at [CDP API Basic Authentication]({{< ref "cdp_api#basic-authentication" >}}) -and [BiDi API Basic Authentication]({{< ref "bidi_api#basic-authentication" >}}) - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -The [BiDi API Basic Authentication]({{< ref "bidi_api#basic-authentication" >}}) implementation should be preferred -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/CdpEndpointTest.java#L60-L66" >}} -{{% /tab %}} -{{% tab header="Python" %}} -{{< gh-codeblock path="/examples/python/tests/bidirectional/chrome_devtools/test_cdp_endpoint.py#L34-L39" >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/CdpEndpointTest.cs#L65-L73" >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -The [BiDi API Basic Authentication]({{< ref "bidi_api#basic-authentication" >}}) implementation should be preferred -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/cdp_endpoint_spec.rb#L38-L43" >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-code >}} -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-code >}} -{{% /tab %}} -{{< /tabpane >}} diff --git a/website_and_docs/content/documentation/webdriver/bidirectional/chrome_devtools/cdp_endpoint.pt-br.md b/website_and_docs/content/documentation/webdriver/bidirectional/chrome_devtools/cdp_endpoint.pt-br.md deleted file mode 100644 index b388d2ccdbb7..000000000000 --- a/website_and_docs/content/documentation/webdriver/bidirectional/chrome_devtools/cdp_endpoint.pt-br.md +++ /dev/null @@ -1,108 +0,0 @@ ---- -title: "Chrome DevTools Protocol Endpoint" -linkTitle: "CDP Endpoint" -weight: 2 -description: > - Google provides a `/cdp/execute` endpoint that can be accessed directly. Each Selenium binding provides a method that - allows you to pass the CDP domain as a String, and the required parameters as a simple Map. ---- - -{{% pageinfo color="warning" %}} -These methods will eventually be removed. It is recommended to use the [WebDriver-BiDi]({{< ref "../webdriver_bidi/" >}}) or [WebDriver Bidi APIs]({{< ref "bidi_api.md" >}}) -methods where possible to ensure future compatibility. -{{% /pageinfo %}} - - -## Usage - -Generally you should prefer the use of the [CDP API]({{< ref "cdp_api.md" >}}) over this approach, -but sometimes the syntax is cleaner or significantly more simple. - -Limitations include: -* It only works for use cases that are limited to setting or getting information; -any actual asynchronous interactions require another implementation -* You have to know the exactly correct "magic strings" for domains and keys -* It is possible that an update to Chrome will change the required parameters - -## Examples - -### Set Cookie - -An alternate implementation can be found at [CDP API Set Cookie]({{< ref "cdp_api#set-cookie" >}}) - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/CdpEndpointTest.java#L26-32" >}} -{{% /tab %}} -{{% tab header="Python" %}} -{{< gh-codeblock path="/examples/python/tests/bidirectional/chrome_devtools/test_cdp_endpoint.py#L7-L12" >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/CdpEndpointTest.cs#L25-L33" >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -The [CDP API Set Cookie]({{< ref "cdp_api#set-cookie" >}}) implementation should be preferred -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/cdp_endpoint_spec.rb#L9-L14" >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-code >}} -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-code >}} -{{% /tab %}} -{{< /tabpane >}} - -### Performance Metrics - -An alternate implementation can be found at [CDP API Performance Metrics]({{< ref "cdp_api#performance-metrics" >}}) - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -The [CDP API Performance Metrics]({{< ref "cdp_api#performance-metrics" >}}) implementation should be preferred -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/CdpEndpointTest.java#L43-L46" >}} -{{% /tab %}} -{{% tab header="Python" %}} -{{< gh-codeblock path="/examples/python/tests/bidirectional/chrome_devtools/test_cdp_endpoint.py#L23-L25" >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/CdpEndpointTest.cs#L46-L49" >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -The [CDP API Performance Metrics]({{< ref "cdp_api#performance-metrics" >}}) implementation should be preferred -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/cdp_endpoint_spec.rb#L25-L27" >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-code >}} -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-code >}} -{{% /tab %}} -{{< /tabpane >}} - -### Basic authentication - -Alternate implementations can be found at [CDP API Basic Authentication]({{< ref "cdp_api#basic-authentication" >}}) -and [BiDi API Basic Authentication]({{< ref "bidi_api#basic-authentication" >}}) - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -The [BiDi API Basic Authentication]({{< ref "bidi_api#basic-authentication" >}}) implementation should be preferred -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/CdpEndpointTest.java#L60-L66" >}} -{{% /tab %}} -{{% tab header="Python" %}} -{{< gh-codeblock path="/examples/python/tests/bidirectional/chrome_devtools/test_cdp_endpoint.py#L34-L39" >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/CdpEndpointTest.cs#L65-L73" >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -The [BiDi API Basic Authentication]({{< ref "bidi_api#basic-authentication" >}}) implementation should be preferred -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/cdp_endpoint_spec.rb#L38-L43" >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-code >}} -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-code >}} -{{% /tab %}} -{{< /tabpane >}} diff --git a/website_and_docs/content/documentation/webdriver/bidirectional/chrome_devtools/cdp_endpoint.zh-cn.md b/website_and_docs/content/documentation/webdriver/bidirectional/chrome_devtools/cdp_endpoint.zh-cn.md deleted file mode 100644 index b388d2ccdbb7..000000000000 --- a/website_and_docs/content/documentation/webdriver/bidirectional/chrome_devtools/cdp_endpoint.zh-cn.md +++ /dev/null @@ -1,108 +0,0 @@ ---- -title: "Chrome DevTools Protocol Endpoint" -linkTitle: "CDP Endpoint" -weight: 2 -description: > - Google provides a `/cdp/execute` endpoint that can be accessed directly. Each Selenium binding provides a method that - allows you to pass the CDP domain as a String, and the required parameters as a simple Map. ---- - -{{% pageinfo color="warning" %}} -These methods will eventually be removed. It is recommended to use the [WebDriver-BiDi]({{< ref "../webdriver_bidi/" >}}) or [WebDriver Bidi APIs]({{< ref "bidi_api.md" >}}) -methods where possible to ensure future compatibility. -{{% /pageinfo %}} - - -## Usage - -Generally you should prefer the use of the [CDP API]({{< ref "cdp_api.md" >}}) over this approach, -but sometimes the syntax is cleaner or significantly more simple. - -Limitations include: -* It only works for use cases that are limited to setting or getting information; -any actual asynchronous interactions require another implementation -* You have to know the exactly correct "magic strings" for domains and keys -* It is possible that an update to Chrome will change the required parameters - -## Examples - -### Set Cookie - -An alternate implementation can be found at [CDP API Set Cookie]({{< ref "cdp_api#set-cookie" >}}) - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/CdpEndpointTest.java#L26-32" >}} -{{% /tab %}} -{{% tab header="Python" %}} -{{< gh-codeblock path="/examples/python/tests/bidirectional/chrome_devtools/test_cdp_endpoint.py#L7-L12" >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/CdpEndpointTest.cs#L25-L33" >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -The [CDP API Set Cookie]({{< ref "cdp_api#set-cookie" >}}) implementation should be preferred -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/cdp_endpoint_spec.rb#L9-L14" >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-code >}} -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-code >}} -{{% /tab %}} -{{< /tabpane >}} - -### Performance Metrics - -An alternate implementation can be found at [CDP API Performance Metrics]({{< ref "cdp_api#performance-metrics" >}}) - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -The [CDP API Performance Metrics]({{< ref "cdp_api#performance-metrics" >}}) implementation should be preferred -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/CdpEndpointTest.java#L43-L46" >}} -{{% /tab %}} -{{% tab header="Python" %}} -{{< gh-codeblock path="/examples/python/tests/bidirectional/chrome_devtools/test_cdp_endpoint.py#L23-L25" >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/CdpEndpointTest.cs#L46-L49" >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -The [CDP API Performance Metrics]({{< ref "cdp_api#performance-metrics" >}}) implementation should be preferred -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/cdp_endpoint_spec.rb#L25-L27" >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-code >}} -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-code >}} -{{% /tab %}} -{{< /tabpane >}} - -### Basic authentication - -Alternate implementations can be found at [CDP API Basic Authentication]({{< ref "cdp_api#basic-authentication" >}}) -and [BiDi API Basic Authentication]({{< ref "bidi_api#basic-authentication" >}}) - -{{< tabpane text=true >}} -{{% tab header="Java" %}} -The [BiDi API Basic Authentication]({{< ref "bidi_api#basic-authentication" >}}) implementation should be preferred -{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/chrome_devtools/CdpEndpointTest.java#L60-L66" >}} -{{% /tab %}} -{{% tab header="Python" %}} -{{< gh-codeblock path="/examples/python/tests/bidirectional/chrome_devtools/test_cdp_endpoint.py#L34-L39" >}} -{{% /tab %}} -{{% tab header="CSharp" %}} -{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Bidirectional/ChromeDevtools/CdpEndpointTest.cs#L65-L73" >}} -{{% /tab %}} -{{% tab header="Ruby" %}} -The [BiDi API Basic Authentication]({{< ref "bidi_api#basic-authentication" >}}) implementation should be preferred -{{< gh-codeblock path="/examples/ruby/spec/bidirectional/chrome_devtools/cdp_endpoint_spec.rb#L38-L43" >}} -{{% /tab %}} -{{% tab header="JavaScript" %}} -{{< badge-code >}} -{{% /tab %}} -{{% tab header="Kotlin" %}} -{{< badge-code >}} -{{% /tab %}} -{{< /tabpane >}} diff --git a/website_and_docs/content/documentation/webdriver/browsers/chrome.en.md b/website_and_docs/content/documentation/webdriver/browsers/chrome.en.md index faced2ff9b09..1bae347db3d0 100644 --- a/website_and_docs/content/documentation/webdriver/browsers/chrome.en.md +++ b/website_and_docs/content/documentation/webdriver/browsers/chrome.en.md @@ -463,4 +463,4 @@ You can simulate various network conditions. ### DevTools -See the [Chrome DevTools]({{< ref "../bidirectional/chrome_devtools/cdp_api.md" >}}) section for more information about using Chrome DevTools +See the [Chrome DevTools]({{< ref "../bidi/cdp/" >}}) section for more information about using Chrome DevTools diff --git a/website_and_docs/content/documentation/webdriver/browsers/chrome.ja.md b/website_and_docs/content/documentation/webdriver/browsers/chrome.ja.md index c5499b8f7f2b..ae73388a0d65 100644 --- a/website_and_docs/content/documentation/webdriver/browsers/chrome.ja.md +++ b/website_and_docs/content/documentation/webdriver/browsers/chrome.ja.md @@ -469,4 +469,4 @@ please refer to the ### デベロッパー ツール -Chromeデベロッパーツールの使用に関する詳細については、[Chromeデベロッパー ツール]({{< ref "../bidirectional/chrome_devtools/cdp_api.md" >}})セクションを参照してください。 +Chromeデベロッパーツールの使用に関する詳細については、[Chromeデベロッパー ツール] セクションを参照してください。 diff --git a/website_and_docs/content/documentation/webdriver/browsers/chrome.pt-br.md b/website_and_docs/content/documentation/webdriver/browsers/chrome.pt-br.md index fc9f45ada9bb..29e7473eefae 100644 --- a/website_and_docs/content/documentation/webdriver/browsers/chrome.pt-br.md +++ b/website_and_docs/content/documentation/webdriver/browsers/chrome.pt-br.md @@ -466,4 +466,4 @@ please refer to the ### DevTools -Veja a secção [Chrome DevTools]({{< ref "../bidirectional/chrome_devtools/cdp_api.md" >}}) para mais informação em como usar Chrome DevTools +Veja a secção [Chrome DevTools] para mais informação em como usar Chrome DevTools diff --git a/website_and_docs/content/documentation/webdriver/browsers/chrome.zh-cn.md b/website_and_docs/content/documentation/webdriver/browsers/chrome.zh-cn.md index 4c64498c63bf..f5f70d6dc8a2 100644 --- a/website_and_docs/content/documentation/webdriver/browsers/chrome.zh-cn.md +++ b/website_and_docs/content/documentation/webdriver/browsers/chrome.zh-cn.md @@ -465,4 +465,4 @@ please refer to the ### DevTools -See the [Chrome DevTools]({{< ref "../bidirectional/chrome_devtools/cdp_api.md" >}}) section for more information about using Chrome DevTools +See the [Chrome DevTools] section for more information about using Chrome DevTools diff --git a/website_and_docs/content/documentation/webdriver/browsers/edge.en.md b/website_and_docs/content/documentation/webdriver/browsers/edge.en.md index 3ee56293f887..5964af0fefb5 100644 --- a/website_and_docs/content/documentation/webdriver/browsers/edge.en.md +++ b/website_and_docs/content/documentation/webdriver/browsers/edge.en.md @@ -463,4 +463,4 @@ You can simulate various network conditions. ### DevTools -See the [Chrome DevTools]({{< ref "../bidirectional/chrome_devtools/cdp_api.md" >}}) section for more information about using DevTools in Edge +See the [Chrome DevTools]({{< ref "../bidi/cdp/" >}}) section for more information about using DevTools in Edge diff --git a/website_and_docs/content/documentation/webdriver/browsers/edge.ja.md b/website_and_docs/content/documentation/webdriver/browsers/edge.ja.md index 207c0710c0a5..6a3afad92c2d 100644 --- a/website_and_docs/content/documentation/webdriver/browsers/edge.ja.md +++ b/website_and_docs/content/documentation/webdriver/browsers/edge.ja.md @@ -465,4 +465,4 @@ You can simulate various network conditions. ### DevTools -See the [Chrome DevTools]({{< ref "../bidirectional/chrome_devtools/cdp_api.md" >}}) section for more information about using DevTools in Edge +See the [Chrome DevTools] section for more information about using DevTools in Edge diff --git a/website_and_docs/content/documentation/webdriver/browsers/edge.pt-br.md b/website_and_docs/content/documentation/webdriver/browsers/edge.pt-br.md index a7f2b1c0a64f..c28ba3067a6c 100644 --- a/website_and_docs/content/documentation/webdriver/browsers/edge.pt-br.md +++ b/website_and_docs/content/documentation/webdriver/browsers/edge.pt-br.md @@ -465,4 +465,4 @@ You can simulate various network conditions. ### DevTools -See the [Chrome DevTools]({{< ref "../bidirectional/chrome_devtools/cdp_api.md" >}}) section for more information about using DevTools in Edge +See the [Chrome DevTools] section for more information about using DevTools in Edge diff --git a/website_and_docs/content/documentation/webdriver/browsers/edge.zh-cn.md b/website_and_docs/content/documentation/webdriver/browsers/edge.zh-cn.md index 618ca4257f9e..b8966197efdc 100644 --- a/website_and_docs/content/documentation/webdriver/browsers/edge.zh-cn.md +++ b/website_and_docs/content/documentation/webdriver/browsers/edge.zh-cn.md @@ -465,4 +465,4 @@ You can simulate various network conditions. ### DevTools -See the [Chrome DevTools]({{< ref "../bidirectional/chrome_devtools/cdp_api.md" >}}) section for more information about using DevTools in Edge +See the [Chrome DevTools] section for more information about using DevTools in Edge diff --git a/website_and_docs/layouts/downloads/list.html b/website_and_docs/layouts/downloads/list.html index a691621a48aa..65f974b2f8ed 100644 --- a/website_and_docs/layouts/downloads/list.html +++ b/website_and_docs/layouts/downloads/list.html @@ -107,7 +107,7 @@

C# NuGet

- Nuget latest release is 4.22.0 Released on Jun 21, 2024. + Nuget latest release is 4.22.0 Released on June 20, 2024.