Best Selenium code snippet using org.openqa.selenium.devtools.DevToolsException
org.openqa.selenium.devtools.DevToolsException
The DevToolsException
usually found when any command is not supported by CDP (chrome devtool protocol
) implementation which is a major part of Selenium 4
Recently this isssue surfaced with
Java 16
as the underlying reflection machanism changes in Java 16 for selenium 4.0.0 alpha and beta which has been resolved in latest selenium versions
In Java 11, It only displays the Warning
INFO: Found CDP implementation for version 92 of 91 WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by org.openqa.selenium.json.InstanceCoercer (file://org/seleniumhq/selenium/selenium-json/4.0.0-beta-4/selenium-json-4.0.0-beta-4.jar) to constructor java.lang.Void() WARNING: Please consider reporting this to the maintainers of org.openqa.selenium.json.InstanceCoercer WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations WARNING: All illegal access operations will be denied in a future release
It is an example code for capturing performance logs
using Selenium 4
using Java 16
.
1import com.qa.selenium4.demo.base.BaseDriver;
2import com.qa.selenium4.demo.helper.WaitHelper;
3import org.apache.logging.log4j.LogManager;
4import org.apache.logging.log4j.Logger;
5import org.openqa.selenium.chrome.ChromeDriver;
6import org.openqa.selenium.devtools.DevTools;
7import org.openqa.selenium.devtools.v91.performance.Performance;
8import org.openqa.selenium.devtools.v91.performance.model.Metric;
9import org.testng.annotations.Test;
10
11import java.util.List;
12import java.util.Optional;
13
14public class CapturingPerformanceMetricTests extends BaseDriver {
15 private static final Logger logger = LogManager.getLogger(CapturingPerformanceMetricTests.class.getName());
16
17 @Test(priority = 0, description = "Capture Performance Metrics Using Chrome Dev Tools")
18 public void getPerformanceMetricsUsingCDPTest() {
19 // Get Dev Tools
20 DevTools chromeDevTools = ((ChromeDriver) driver).getDevTools();
21
22 // Create Session
23 chromeDevTools.createSession(); // Calling this throws an exception
24
25 // Enable Performance
26 chromeDevTools.send(Performance.enable(Optional.of(Performance.EnableTimeDomain.TIMETICKS)));
27
28 // Load URL
29 driver.get("https://www.amazon.in/");
30 WaitHelper.hardWait(5);
31 List<Metric> performanceMatrix = chromeDevTools.send(Performance.getMetrics());
32
33 chromeDevTools.send(Performance.disable());
34
35 performanceMatrix.forEach(matrix -> {
36 logger.info(matrix.getName() + " : " + matrix.getValue());
37 });
38 }
39}
the output of error will looks as follow
1org.openqa.selenium.remote.http.ConnectionFailedException: Unable to establish websocket connection to http://localhost:60650/devtools/browser/9faa33dd-c789-47f4-acab-261acc7045e7 2Build info: version: '4.0.0-beta-3', revision: '5d108f9a67' 3System info: host: 'xxx', ip: 'xxx', os.name: 'Windows Server 2016', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_202' 4Driver info: driver.version: ChromeDriver 5 at org.openqa.selenium.remote.http.netty.NettyWebSocket.<init>(NettyWebSocket.java:104) 6 at org.openqa.selenium.remote.http.netty.NettyWebSocket.lambda$create$3(NettyWebSocket.java:136) 7 at org.openqa.selenium.remote.http.netty.NettyClient.openSocket(NettyClient.java:111) 8 at org.openqa.selenium.devtools.Connection.<init>(Connection.java:73) 9 at org.openqa.selenium.chromium.ChromiumDriver.lambda$new$1(ChromiumDriver.java:102) 10 at java.util.Optional.map(Unknown Source) 11 at org.openqa.selenium.chromium.ChromiumDriver.<init>(ChromiumDriver.java:100) 12 at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:99) 13 at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:86) 14 at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:75) 15 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 16 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 17 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 18 at java.lang.reflect.Method.invoke(Unknown Source) 19 org.openqa.selenium.remote.http.ConnectionFailedException: Unable to establish websocket connection to http://localhost:60650/devtools/browser/9faa33dd-c789-47f4-acab-261acc7045e7 20Build info: version: '4.0.0-beta-3', revision: '5d108f9a67' 21System info: host: 'xxx', ip: 'xxx', os.name: 'Windows Server 2016', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_202' 22Driver info: driver.version: ChromeDriver 23 at org.openqa.selenium.remote.http.netty.NettyWebSocket.<init>(NettyWebSocket.java:104) 24 at org.openqa.selenium.remote.http.netty.NettyWebSocket.lambda$create$3(NettyWebSocket.java:136) 25 at org.openqa.selenium.remote.http.netty.NettyClient.openSocket(NettyClient.java:111) 26 at org.openqa.selenium.devtools.Connection.<init>(Connection.java:73) 27 at org.openqa.selenium.chromium.ChromiumDriver.lambda$new$1(ChromiumDriver.java:102) 28 at java.util.Optional.map(Unknown Source) 29 at org.openqa.selenium.chromium.ChromiumDriver.<init>(ChromiumDriver.java:100) 30 at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:99) 31 at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:86) 32 at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:75) 33 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 34 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 35 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 36 at java.lang.reflect.Method.invoke(Unknown Source)
It throws below errors with jdk 16
1ChromeDriver was started successfully. 2Jul 22, 2021 1:24:28 PM org.openqa.selenium.remote.ProtocolHandshake createSession 3INFO: Detected dialect: W3C 4Jul 22, 2021 1:24:28 PM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch 5WARNING: Unable to find an exact match for CDP version 92, so returning the closest version found: 91 6Jul 22, 2021 1:24:28 PM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch 7INFO: Found CDP implementation for version 92 of 91 8Jul 22, 2021 1:24:29 PM org.openqa.selenium.devtools.Connection lambda$send$1 9WARNING: Unable to map result for Target.setAutoAttach 10java.lang.reflect.InaccessibleObjectException: Unable to make private java.lang.Void() accessible: module java.base does not "opens java.lang" to unnamed module @6537cf78 11 at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:357 undefined) 12 at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297 undefined) 13 at java.base/java.lang.reflect.Constructor.checkCanSetAccessible(Constructor.java:188 undefined) 14 at java.base/java.lang.reflect.Constructor.setAccessible(Constructor.java:181 undefined) 15 at org.openqa.selenium.json.InstanceCoercer.getConstructor(InstanceCoercer.java:155 undefined) 16 at org.openqa.selenium.json.InstanceCoercer.test(InstanceCoercer.java:48 undefined) 17 at org.openqa.selenium.json.JsonTypeCoercer.lambda$buildCoercer$4(JsonTypeCoercer.java:134 undefined) 18 at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:178 undefined) 19 at java.base/java.util.Spliterators$IteratorSpliterator.tryAdvance(Spliterators.java:1812 undefined) 20 at java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:129 undefined) 21 at java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:502 undefined) 22 at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:488 undefined) 23 at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474 undefined) 24 at java.base/java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:150 undefined) 25 at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234 undefined) 26 at java.base/java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:647 undefined) 27 at org.openqa.selenium.json.JsonTypeCoercer.buildCoercer(JsonTypeCoercer.java:135 undefined) 28 at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1708 undefined) 29 at org.openqa.selenium.json.JsonTypeCoercer.coerce(JsonTypeCoercer.java:124 undefined) 30 at org.openqa.selenium.json.JsonInput.read(JsonInput.java:289 undefined) 31 at org.openqa.selenium.devtools.Command.lambda$new$0(Command.java:41 undefined) 32 at org.openqa.selenium.devtools.Connection.lambda$send$1(Connection.java:109 undefined) 33 at org.openqa.selenium.devtools.Connection$NamedConsumer.accept(Connection.java:92 undefined) 34 at org.openqa.selenium.devtools.Connection.handle(Connection.java:218 undefined) 35 at org.openqa.selenium.devtools.Connection.access$200(Connection.java:55 undefined) 36 at org.openqa.selenium.devtools.Connection$Listener.lambda$onText$0(Connection.java:187 undefined) 37 at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130 undefined) 38 at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630 undefined) 39 at java.base/java.lang.Thread.run(Thread.java:831 undefined) 40Jul 22, 2021 1:24:29 PM org.openqa.selenium.devtools.Connection lambda$send$1 41WARNING: Unable to map result for Log.clear 42java.lang.reflect.InaccessibleObjectException: Unable to make private java.lang.Void() accessible: module java.base does not "opens java.lang" to unnamed module @6537cf78 43 at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:357 undefined) 44 at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297 undefined) 45 at java.base/java.lang.reflect.Constructor.checkCanSetAccessible(Constructor.java:188 undefined) 46 at java.base/java.lang.reflect.Constructor.setAccessible(Constructor.java:181 undefined) 47 at org.openqa.selenium.json.InstanceCoercer.getConstructor(InstanceCoercer.java:155 undefined) 48 at org.openqa.selenium.json.InstanceCoercer.test(InstanceCoercer.java:48 undefined) 49 at org.openqa.selenium.json.JsonTypeCoercer.lambda$buildCoercer$4(JsonTypeCoercer.java:134 undefined) 50 at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:178 undefined) 51 at java.base/java.util.Spliterators$IteratorSpliterator.tryAdvance(Spliterators.java:1812 undefined) 52 at java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:129 undefined) 53 at java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:502 undefined) 54 at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:488 undefined) 55 at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474 undefined) 56 at java.base/java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:150 undefined) 57 at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234 undefined) 58 at java.base/java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:647 undefined) 59 at org.openqa.selenium.json.JsonTypeCoercer.buildCoercer(JsonTypeCoercer.java:135 undefined) 60 at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1708 undefined) 61 at org.openqa.selenium.json.JsonTypeCoercer.coerce(JsonTypeCoercer.java:124 undefined) 62 at org.openqa.selenium.json.JsonInput.read(JsonInput.java:289 undefined) 63 at org.openqa.selenium.devtools.Command.lambda$new$0(Command.java:41 undefined) 64 at org.openqa.selenium.devtools.Connection.lambda$send$1(Connection.java:109 undefined) 65 at org.openqa.selenium.devtools.Connection$NamedConsumer.accept(Connection.java:92 undefined) 66 at org.openqa.selenium.devtools.Connection.handle(Connection.java:218 undefined) 67 at org.openqa.selenium.devtools.Connection.access$200(Connection.java:55 undefined) 68 at org.openqa.selenium.devtools.Connection$Listener.lambda$onText$0(Connection.java:187 undefined) 69 at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130 undefined) 70 at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630 undefined) 71 at java.base/java.lang.Thread.run(Thread.java:831 undefined) 72java.lang.reflect.InaccessibleObjectException: Unable to make private java.lang.Void() accessible: module java.base does not "opens java.lang" to unnamed module @6537cf78 73 at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:357 undefined) 74 at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297 undefined) 75 at java.base/java.lang.reflect.Constructor.checkCanSetAccessible(Constructor.java:188 undefined) 76 at java.base/java.lang.reflect.Constructor.setAccessible(Constructor.java:181 undefined) 77 at org.openqa.selenium.json.InstanceCoercer.getConstructor(InstanceCoercer.java:155 undefined) 78 at org.openqa.selenium.json.InstanceCoercer.test(InstanceCoercer.java:48 undefined) 79 at org.openqa.selenium.json.JsonTypeCoercer.lambda$buildCoercer$4(JsonTypeCoercer.java:134 undefined) 80 at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:178 undefined) 81 at java.base/java.util.Spliterators$IteratorSpliterator.tryAdvance(Spliterators.java:1812 undefined) 82 at java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:129 undefined) 83 at java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:502 undefined) 84 at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:488 undefined) 85 at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474 undefined) 86 at java.base/java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:150 undefined) 87 at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234 undefined) 88 at java.base/java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:647 undefined) 89 at org.openqa.selenium.json.JsonTypeCoercer.buildCoercer(JsonTypeCoercer.java:135 undefined) 90 at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1708 undefined) 91 at org.openqa.selenium.json.JsonTypeCoercer.coerce(JsonTypeCoercer.java:124 undefined) 92 at org.openqa.selenium.json.JsonInput.read(JsonInput.java:289 undefined) 93 at org.openqa.selenium.devtools.Command.lambda$new$0(Command.java:41 undefined) 94 at org.openqa.selenium.devtools.Connection.lambda$send$1(Connection.java:109 undefined) 95 at org.openqa.selenium.devtools.Connection$NamedConsumer.accept(Connection.java:92 undefined) 96 at org.openqa.selenium.devtools.Connection.handle(Connection.java:218 undefined) 97 at org.openqa.selenium.devtools.Connection.access$200(Connection.java:55 undefined) 98 at org.openqa.selenium.devtools.Connection$Listener.lambda$onText$0(Connection.java:187 undefined) 99 at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130 undefined) 100 at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630 undefined) 101 at java.base/java.lang.Thread.run(Thread.java:831 undefined) 102Jul 22, 2021 1:24:29 PM org.openqa.selenium.devtools.Connection$Listener lambda$onText$0 103WARNING: Unable to process: {"id":3,"result":{},"sessionId":"6385B3D3C023139BAB5BA89925C94EF0"} 104org.openqa.selenium.json.JsonException: Expected to read a NAME but instead have: START_MAP. Last 17 characters read: {"id":3,"result": 105Build info: version: '4.0.0-beta-4', revision: '29f46d02dd' 106System info: host: 'PMCLAP1338', ip: '192.168.207.2', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '16.0.1' 107Driver info: driver.version: unknown 108 at org.openqa.selenium.json.JsonInput.expect(JsonInput.java:300 undefined) 109 at org.openqa.selenium.json.JsonInput.nextName(JsonInput.java:136 undefined) 110 at org.openqa.selenium.devtools.Connection.handle(Connection.java:216 undefined) 111 at org.openqa.selenium.devtools.Connection.access$200(Connection.java:55 undefined) 112 at org.openqa.selenium.devtools.Connection$Listener.lambda$onText$0(Connection.java:187 undefined) 113 at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130 undefined) 114 at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630 undefined) 115 at java.base/java.lang.Thread.run(Thread.java:831 undefined) 116Exception in thread "CDP Connection" org.openqa.selenium.devtools.DevToolsException: Expected to read a NAME but instead have: START_MAP. Last 17 characters read: {"id":3,"result": 117Build info: version: '4.0.0-beta-4', revision: '29f46d02dd' 118System info: host: 'PMCLAP1338', ip: '192.168.207.2', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '16.0.1' 119Driver info: driver.version: unknown 120 at org.openqa.selenium.devtools.Connection$Listener.lambda$onText$0(Connection.java:190 undefined) 121 at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130 undefined) 122 at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630 undefined) 123 at java.base/java.lang.Thread.run(Thread.java:831 undefined) 124Caused by: org.openqa.selenium.json.JsonException: Expected to read a NAME but instead have: START_MAP. Last 17 characters read: {"id":3,"result": 125Build info: version: '4.0.0-beta-4', revision: '29f46d02dd' 126System info: host: 'PMCLAP1338', ip: '192.168.207.2', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '16.0.1' 127Driver info: driver.version: unknown 128 at org.openqa.selenium.json.JsonInput.expect(JsonInput.java:300 undefined) 129 at org.openqa.selenium.json.JsonInput.nextName(JsonInput.java:136 undefined) 130 at org.openqa.selenium.devtools.Connection.handle(Connection.java:216 undefined) 131 at org.openqa.selenium.devtools.Connection.access$200(Connection.java:55 undefined) 132 at org.openqa.selenium.devtools.Connection$Listener.lambda$onText$0(Connection.java:187 undefined) 133 ... 3 more 134Jul 22, 2021 1:24:29 PM org.openqa.selenium.devtools.Connection$Listener lambda$onText$0 135WARNING: Unable to process: {"id":4,"result":{},"sessionId":"6385B3D3C023139BAB5BA89925C94EF0"} 136org.openqa.selenium.json.JsonException: Expected to read a NAME but instead have: START_MAP. Last 17 characters read: {"id":4,"result": 137Build info: version: '4.0.0-beta-4', revision: '29f46d02dd' 138System info: host: 'PMCLAP1338', ip: '192.168.207.2', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '16.0.1' 139Driver info: driver.version: unknown 140 at org.openqa.selenium.json.JsonInput.expect(JsonInput.java:300 undefined) 141 at org.openqa.selenium.json.JsonInput.nextName(JsonInput.java:136 undefined) 142 at org.openqa.selenium.devtools.Connection.handle(Connection.java:216 undefined) 143 at org.openqa.selenium.devtools.Connection.access$200(Connection.java:55 undefined) 144 at org.openqa.selenium.devtools.Connection$Listener.lambda$onText$0(Connection.java:187 undefined) 145 at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130 undefined) 146 at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630 undefined) 147 at java.base/java.lang.Thread.run(Thread.java:831 undefined) 148Exception in thread "CDP Connection" org.openqa.selenium.devtools.DevToolsException: Expected to read a NAME but instead have: START_MAP. Last 17 characters read: {"id":4,"result": 149Build info: version: '4.0.0-beta-4', revision: '29f46d02dd' 150System info: host: 'PMCLAP1338', ip: '192.168.207.2', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '16.0.1' 151Driver info: driver.version: unknown 152 at org.openqa.selenium.devtools.Connection$Listener.lambda$onText$0(Connection.java:190 undefined) 153 at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130 undefined) 154 at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630 undefined) 155 at java.base/java.lang.Thread.run(Thread.java:831 undefined) 156Caused by: org.openqa.selenium.json.JsonException: Expected to read a NAME but instead have: START_MAP. Last 17 characters read: {"id":4,"result": 157Build info: version: '4.0.0-beta-4', revision: '29f46d02dd' 158System info: host: 'PMCLAP1338', ip: '192.168.207.2', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '16.0.1' 159Driver info: driver.version: unknown 160 at org.openqa.selenium.json.JsonInput.expect(JsonInput.java:300 undefined) 161 at org.openqa.selenium.json.JsonInput.nextName(JsonInput.java:136 undefined) 162 at org.openqa.selenium.devtools.Connection.handle(Connection.java:216 undefined) 163 at org.openqa.selenium.devtools.Connection.access$200(Connection.java:55 undefined) 164 at org.openqa.selenium.devtools.Connection$Listener.lambda$onText$0(Connection.java:187 undefined) 165 ... 3 more 166org.openqa.selenium.devtools.DevToolsException: Unable to make private java.lang.Void() accessible: module java.base does not "opens java.lang" to unnamed module @6537cf78 167Build info: version: '4.0.0-beta-4', revision: '29f46d02dd' 168System info: host: 'PMCLAP1338', ip: '192.168.207.2', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '16.0.1' 169Driver info: DevTools Connection 170 at org.openqa.selenium.devtools.DevTools.createSession(DevTools.java:125 undefined) 171 at com.qa.selenium4.demo.devtools.CapturingPerformanceMetricTests.getPerformanceMetricsUsingCDPTest(CapturingPerformanceMetricTests.java:24 undefined) 172 at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 173 at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78 undefined) 174 at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43 undefined) 175 at java.base/java.lang.reflect.Method.invoke(Method.java:567 undefined) 176 at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:132 undefined) 177 at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:599 undefined) 178 at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:174 undefined) 179 at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46 undefined) 180 at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:822 undefined) 181 at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:147 undefined) 182 at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146 undefined) 183 at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128 undefined) 184 at java.base/java.util.ArrayList.forEach(ArrayList.java:1511 undefined) 185 at org.testng.TestRunner.privateRun(TestRunner.java:764 undefined) 186 at org.testng.TestRunner.run(TestRunner.java:585 undefined) 187 at org.testng.SuiteRunner.runTest(SuiteRunner.java:384 undefined) 188 at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:378 undefined) 189 at org.testng.SuiteRunner.privateRun(SuiteRunner.java:337 undefined) 190 at org.testng.SuiteRunner.run(SuiteRunner.java:286 undefined) 191 at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53 undefined) 192 at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96 undefined) 193 at org.testng.TestNG.runSuitesSequentially(TestNG.java:1218 undefined) 194 at org.testng.TestNG.runSuitesLocally(TestNG.java:1140 undefined) 195 at org.testng.TestNG.runSuites(TestNG.java:1069 undefined) 196 at org.testng.TestNG.run(TestNG.java:1037 undefined) 197 at com.intellij.rt.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:66 undefined) 198 at com.intellij.rt.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:109 undefined) 199Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make private java.lang.Void() accessible: module java.base does not "opens java.lang" to unnamed module @6537cf78 200 at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:357 undefined) 201 at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297 undefined) 202 at java.base/java.lang.reflect.Constructor.checkCanSetAccessible(Constructor.java:188 undefined) 203 at java.base/java.lang.reflect.Constructor.setAccessible(Constructor.java:181 undefined) 204 at org.openqa.selenium.json.InstanceCoercer.getConstructor(InstanceCoercer.java:155 undefined) 205 at org.openqa.selenium.json.InstanceCoercer.test(InstanceCoercer.java:48 undefined) 206 at org.openqa.selenium.json.JsonTypeCoercer.lambda$buildCoercer$4(JsonTypeCoercer.java:134 undefined) 207 at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:178 undefined) 208 at java.base/java.util.Spliterators$IteratorSpliterator.tryAdvance(Spliterators.java:1812 undefined) 209 at java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:129 undefined) 210 at java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:502 undefined) 211 at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:488 undefined) 212 at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474 undefined) 213 at java.base/java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:150 undefined) 214 at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234 undefined) 215 at java.base/java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:647 undefined) 216 at org.openqa.selenium.json.JsonTypeCoercer.buildCoercer(JsonTypeCoercer.java:135 undefined) 217 at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1708 undefined) 218 at org.openqa.selenium.json.JsonTypeCoercer.coerce(JsonTypeCoercer.java:124 undefined) 219 at org.openqa.selenium.json.JsonInput.read(JsonInput.java:289 undefined) 220 at org.openqa.selenium.devtools.Command.lambda$new$0(Command.java:41 undefined) 221 at org.openqa.selenium.devtools.Connection.lambda$send$1(Connection.java:109 undefined) 222 at org.openqa.selenium.devtools.Connection$NamedConsumer.accept(Connection.java:92 undefined) 223 at org.openqa.selenium.devtools.Connection.handle(Connection.java:218 undefined) 224 at org.openqa.selenium.devtools.Connection.access$200(Connection.java:55 undefined) 225 at org.openqa.selenium.devtools.Connection$Listener.lambda$onText$0(Connection.java:187 undefined) 226 at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130 undefined) 227 at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630 undefined) 228 at java.base/java.lang.Thread.run(Thread.java:831 undefined) 229Jul 22, 2021 1:24:31 PM org.openqa.selenium.remote.http.WebSocket$Listener onError 230WARNING: Connection reset 231java.net.SocketException: Connection reset 232 at java.base/sun.nio.ch.SocketChannelImpl.throwConnectionReset(SocketChannelImpl.java:394 undefined) 233 at java.base/sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:426 undefined) 234 at io.netty.buffer.PooledByteBuf.setBytes(PooledByteBuf.java:253 undefined) 235 at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1132 undefined) 236 at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:350 undefined) 237 at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:151 undefined) 238 at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:719 undefined) 239 at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:655 undefined) 240 at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:581 undefined) 241 at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493 undefined) 242 at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989 undefined) 243 at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74 undefined) 244 at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30 undefined) 245 at java.base/java.lang.Thread.run(Thread.java:831 undefined)
jdk 16
to jdk 11
Here are code snippets that can help you understand more how developers are using
Source:RuntimeDevToolsTest.java
...11import org.openqa.selenium.chrome.ChromeDriver;12import org.openqa.selenium.chrome.ChromeOptions;13import org.openqa.selenium.chromium.ChromiumDriver;14import org.openqa.selenium.devtools.DevTools;15import org.openqa.selenium.devtools.DevToolsException;16import org.openqa.selenium.devtools.HasDevTools;17import org.openqa.selenium.devtools.v97.runtime.Runtime;18import org.openqa.selenium.devtools.v97.runtime.Runtime.EvaluateResponse;19import org.openqa.selenium.devtools.v97.runtime.model.ExecutionContextId;20import org.openqa.selenium.devtools.v97.runtime.model.RemoteObject;21import org.openqa.selenium.devtools.v97.runtime.model.TimeDelta;22import org.openqa.selenium.json.JsonException;23/**24 * Selected test scenarios for Selenium Chrome Developer Tools Selenium 4 bridge25 * https://chromedevtools.github.io/devtools-protocol/1-3/Runtime/#method-evaluate26 * 27 * @author: Serguei Kouzmine (kouzmine_serguei@yahoo.com)28 */29public class RuntimeDevToolsTest {30 private static boolean runHeadless = false;31 private static String osName = Utils.getOSName();32 private static ChromiumDriver driver;33 private static DevTools chromeDevTools;34 private static String expression = null;35 private final static String baseURL = "https://www.google.com";36 @BeforeClass37 public static void setUp() throws Exception {38 if (System.getenv().containsKey("HEADLESS")39 && System.getenv("HEADLESS").matches("(?:true|yes|1)")) {40 runHeadless = true;41 }42 // force the headless flag to be true to support Unix console execution43 if (!(Utils.getOSName().equals("windows"))44 && !(System.getenv().containsKey("DISPLAY"))) {45 runHeadless = true;46 }47 System48 .setProperty("webdriver.chrome.driver",49 Paths.get(System.getProperty("user.home"))50 .resolve("Downloads").resolve(osName.equals("windows")51 ? "chromedriver.exe" : "chromedriver")52 .toAbsolutePath().toString());53 if (runHeadless) {54 ChromeOptions options = new ChromeOptions();55 options.addArguments("--headless", "--disable-gpu");56 driver = new ChromeDriver(options);57 } else {58 driver = new ChromeDriver();59 }60 Utils.setDriver(driver);61 chromeDevTools = ((HasDevTools) driver).getDevTools();62 // compiles but fails in runtime63 chromeDevTools.createSession();64 }65 @BeforeClass66 public static void beforeClass() throws Exception {67 driver.get(baseURL);68 }69 @AfterClass70 public static void tearDown() {71 if (driver != null) {72 driver.quit();73 }74 }75 // NOTE: some arguments *must* be empty76 @Test(expected = DevToolsException.class)77 public void test1() {78 // evaluate79 chromeDevTools.send(Runtime.enable());80 try {81 expression = "var y = 123; y;";82 EvaluateResponse response = chromeDevTools83 .send(Runtime.evaluate(expression, Optional.of(""), // objectGroup84 Optional.of(false), // includeCommandLineAPI85 Optional.of(false), // silent86 Optional.of(new ExecutionContextId(100)), // contextId87 Optional.of(false), // returnByValue88 Optional.of(false), // generatePreview89 Optional.of(false), // userGesture90 Optional.of(false), // awaitPromise91 Optional.of(false), // throwOnSideEffect92 Optional.of(new TimeDelta(new Double(1000))), // timeout93 Optional.of(false), // disableBreaks94 Optional.of(false), // replMode95 Optional.of(false), // allowUnsafeEvalBlockedByCSP96 Optional.of("") // uniqueContextId97 ));98 // org.openqa.selenium.devtools.DevToolsException:99 // {"id":6,"error":{"code":-32602,"message":"Invalid100 // parameters","data":"Failed to deserialize params.ti101 RemoteObject result = response.getResult();102 assertThat(result, notNullValue());103 System.err.println(String.format("test 1 Result type: %s Value: %s",104 result.getType(), result.getValue()));105 } catch (JsonException e) {106 System.err.println(107 "Exception in test 1 reading result (ignored): " + e.toString());108 }109 }110 @Test111 public void test2() {112 chromeDevTools.send(Runtime.enable());113 try {114 expression = "var y = 456; y;";115 EvaluateResponse response = chromeDevTools116 .send(Runtime.evaluate(expression, Optional.empty(), Optional.empty(),117 Optional.empty(), Optional.empty(), Optional.empty(),118 Optional.empty(), Optional.empty(), Optional.empty(),119 Optional.empty(), Optional.empty(), Optional.empty(),120 Optional.empty(), Optional.empty(), Optional.empty()));121 Object result = response.getResult();122 System.err123 .println(String.format("test 2 Result raw %s:", result.toString()));124 } catch (JsonException e) {125 System.err.println(126 "Exception in test 2 reading result (ignored): " + e.toString());127 }128 }129 @Test130 public void test3() {131 // evaluate132 chromeDevTools.send(Runtime.enable());133 try {134 expression = "var y = 456; y;";135 Object response = chromeDevTools136 .send(Runtime.evaluate(expression, Optional.empty(), Optional.empty(),137 Optional.empty(), Optional.empty(), Optional.empty(),138 Optional.empty(), Optional.empty(), Optional.empty(),139 Optional.empty(), Optional.empty(), Optional.empty(),140 Optional.empty(), Optional.empty(), Optional.empty()));141 assertThat(response, notNullValue());142 System.err.println(143 String.format("test 3 Response type is %s", response.getClass()));144 } catch (JsonException e) {145 System.err.println(146 "Exception in test 3 reading result (ignored): " + e.toString());147 } catch (DevToolsException e) {148 // Caused by: org.openqa.selenium.json.JsonException: Unable to create149 // instance of class150 // org.openqa.selenium.devtools.runtime.model.RemoteObject151 System.err.println(152 "Exception in test 3 generating result (ignored): " + e.toString());153 throw e;154 }155 }156 @Test(expected = java.lang.NullPointerException.class)157 public void test4() {158 // evaluate159 chromeDevTools.send(Runtime.enable());160 expression = "var y = 42; y;";161 chromeDevTools.send(Runtime.evaluate(expression, null, null, null, null,162 null, null, null, null, null, null, null, null, null, null));163 /*164 chromeDevTools.send(165 Runtime.evaluate(expression, null, null, null, null, null, null, null,166 null, null, null, null, null, Optional.empty(), Optional.empty()));167 */168 }169 @Test(expected = org.openqa.selenium.devtools.DevToolsException.class)170 public void test5() {171 // evaluate172 chromeDevTools.send(Runtime.enable());173 try {174 expression = "var y = 123; y;";175 EvaluateResponse response = chromeDevTools176 .send(Runtime.evaluate(expression, Optional.of(""), // objectGroup177 Optional.of(false), // includeCommandLineAPI178 Optional.of(false), // silent179 Optional.of(new ExecutionContextId(0)), // contextId180 Optional.of(false), // returnByValue181 Optional.of(false), // generatePreview182 Optional.of(false), // userGesture183 Optional.of(false), // awaitPromise184 Optional.of(false), // throwOnSideEffect185 Optional.of(new TimeDelta(new Double(0))), // timeout186 Optional.of(false), // disableBreaks187 Optional.of(false), // replMode188 Optional.of(false), // allowUnsafeEvalBlockedByCSP189 Optional.empty() // uniqueContextId190 ));191 response.getResult();192 } catch (JsonException e) {193 System.err.println("Exception reading result (ignored): " + e.toString());194 }195 }196 @Test(expected = org.openqa.selenium.devtools.DevToolsException.class)197 public void test6() {198 // evaluate199 chromeDevTools.send(Runtime.enable());200 try {201 expression = "var y = 123; y;";202 EvaluateResponse response = chromeDevTools203 .send(Runtime.evaluate(expression, Optional.of(""), // objectGroup204 Optional.of(false), // includeCommandLineAPI205 Optional.of(false), // silent206 Optional.of(new ExecutionContextId(0)), // contextId,207 // can also pass Optional.empty() here208 Optional.of(false), // returnByValue209 Optional.of(false), // generatePreview210 Optional.of(false), // userGesture211 Optional.of(false), // awaitPromise212 Optional.of(false), // throwOnSideEffect213 Optional.of(new TimeDelta(new Double(100))), // timeout214 Optional.of(false), // disableBreaks215 Optional.of(false), // replMode216 Optional.of(false), // allowUnsafeEvalBlockedByCSP217 Optional.empty())); // uniqueContextId218 response.getResult();219 } catch (JsonException e) {220 System.err.println("Exception reading result (ignored): " + e.toString());221 }222 // {"code":-32602,"message":"Invalid parameters","data":"Failed to223 // deserialize params.timeout - BINDINGS: double value expected at position224 // 175"},"sessionId":"91EA16790E5732D1D741B5996757CE2"}(..)225 }226 // NOTE: replacing Optiona.empty() with nulls would lead to NPE227 @Test228 public void test7() {229 chromeDevTools.send(Runtime.enable());230 try {231 expression = "const letters = ['a', 'b', 'c']; letters.push('d'); letters";232 EvaluateResponse response = chromeDevTools233 .send(Runtime.evaluate(expression, Optional.empty(), Optional.empty(),234 Optional.empty(), Optional.empty(), Optional.empty(),235 Optional.empty(), Optional.empty(), Optional.empty(),236 Optional.empty(), Optional.empty(), Optional.empty(),237 Optional.empty(), Optional.empty(), Optional.empty()));238 Object rawResult = response.getResult();239 System.err.println(String.format("Result raw %s:", rawResult.toString()));240 RemoteObject result = response.getResult();241 assertThat(result.getType().toString(), is("object"));242 assertThat(result.getSubtype().toString(), is("Optional[array]"));243 assertThat(result.getDescription().toString(), is("Optional[Array(4)]"));244 } catch (JsonException e) {245 System.err.println("Exception reading result (ignored): " + e.toString());246 } catch (DevToolsException e) {247 // Caused by: org.openqa.selenium.json.JsonException: Unable to create248 // instance of class249 // org.openqa.selenium.devtools.runtime.model.RemoteObject250 System.err251 .println("Exception generating result (ignored): " + e.toString());252 throw (e);253 }254 }255}...
Source:WindowSizeDevToolsTest.java
...3import org.junit.Test;4import org.openqa.selenium.WebElement;5import org.openqa.selenium.devtools.Command;6import org.openqa.selenium.devtools.ConverterFunctions;7import org.openqa.selenium.devtools.DevToolsException;8import org.openqa.selenium.devtools.v97.browser.Browser;9import org.openqa.selenium.devtools.v97.browser.Browser.GetWindowForTargetResponse;10import org.openqa.selenium.devtools.v97.browser.model.Bounds;11import org.openqa.selenium.devtools.v97.browser.model.WindowID;12import org.openqa.selenium.devtools.v97.browser.model.WindowState;13import com.google.common.collect.ImmutableMap;14/**15 * Selected test scenarios for Selenium Chrome Developer Tools Selenium 4 bridge16 * see:17 * https://chromedevtools.github.io/devtools-protocol/tot/Browser/#method-setWindowBounds18 * https://chromedevtools.github.io/devtools-protocol/tot/Browser/#method-getWindowBounds19 * https://chromedevtools.github.io/devtools-protocol/tot/Browser/#method-getWindowForTarget20 * @author: Serguei Kouzmine (kouzmine_serguei@yahoo.com)21 */22public class WindowSizeDevToolsTest extends BaseDevToolsTest {23 private static boolean debug = false;24 private static WebElement element = null;25 private static WindowID windowId;26 private static Bounds bounds;27 @Test28 public void test1() {29 System.err.println("test1");30 // Act31 try {32 final GetWindowForTargetResponse result = chromeDevTools33 .send(Browser.getWindowForTarget(Optional.empty()));34 windowId = result.getWindowId();35 System.err.println(String.format(36 "top: %d left: %d width: %d height: %d state: %s",37 result.getBounds().getTop().get(), result.getBounds().getLeft().get(),38 result.getBounds().getWidth().get(),39 result.getBounds().getHeight().get(),40 result.getBounds().getWindowState().get()));41 } catch (DevToolsException e) {42 System.err.println("DevToolsException exception " + "in test2"43 + " (ignored): " + Utils.processExceptionMessage(e.getMessage()));44 }45 }46 // origin:47 // https://github.com/rookieInTraining/selenium-cdp-examples/blob/main/src/test/java/com/rookieintraining/cdp/alternative_examples/Browser.java#L3448 @Test49 public void test2() {50 System.err.println("test2");51 // Act52 try {53 Bounds bounds2 = chromeDevTools.send(new Command<>(54 "Browser.getWindowBounds", ImmutableMap.of("windowId", windowId),55 ConverterFunctions.map("bounds", Bounds.class)));56 System.err.println(57 String.format("top: %d left: %d width: %d height: %d state: %s",58 bounds2.getTop().get(), bounds2.getLeft().get(),59 bounds2.getWidth().get(), bounds2.getHeight().get(),60 bounds2.getWindowState().get()));61 } catch (DevToolsException e) {62 System.err.println("DevToolsException exception " + "in test2"63 + " (ignored): " + Utils.processExceptionMessage(e.getMessage()));64 }65 }66 @Test67 public void test3() {68 System.err.println("test3");69 // Act70 try {71 // java.lang.NullPointerException: windowId is required72 bounds = chromeDevTools.send(Browser.getWindowBounds(windowId));73 System.err.println(74 String.format("top: %d left: %d width: %d height: %d state: %s",75 bounds.getTop().get(), bounds.getLeft().get(),76 bounds.getWidth().get(), bounds.getHeight().get(),77 bounds.getWindowState().get()));78 } catch (DevToolsException e) {79 System.err.println("DevToolsException exception " + "in test3"80 + " (ignored): " + Utils.processExceptionMessage(e.getMessage()));81 }82 }83 @Test84 public void test4() {85 System.err.println("test4");86 // Act87 try {88 Bounds bounds2 = new Bounds(Optional.empty(), Optional.empty(),89 Optional.empty(), Optional.empty(),90 Optional.of(WindowState.FULLSCREEN));91 chromeDevTools.send(Browser.setWindowBounds(windowId, bounds2));92 bounds2 = chromeDevTools.send(Browser.getWindowBounds(windowId));93 System.err.println(94 String.format("top: %d left: %d width: %d height: %d state: %s",95 bounds2.getTop().get(), bounds2.getLeft().get(),96 bounds2.getWidth().get(), bounds2.getHeight().get(),97 bounds2.getWindowState().get()));98 } catch (DevToolsException e) {99 System.err.println("DevToolsException exception " + "in test4"100 + " (ignored): " + Utils.processExceptionMessage(e.getMessage()));101 }102 }103 @Test104 public void test5() {105 System.err.println("test5");106 // Act107 try {108 Bounds bounds2 = new Bounds(Optional.of(bounds.getTop().get() + 100),109 bounds.getLeft(), bounds.getWidth(), bounds.getHeight(),110 Optional.of(WindowState.NORMAL));111 System.err.println(112 String.format("top: %d left: %d width: %d height: %d state: %s",113 bounds2.getTop().get(), bounds2.getLeft().get(),114 bounds2.getWidth().get(), bounds2.getHeight().get(),115 bounds2.getWindowState().get()));116 chromeDevTools.send(Browser.setWindowBounds(windowId, bounds2));117 } catch (DevToolsException e) {118 /*119 * DevToolsException exception in test5 (ignored): {"id":11,"error":{"code":-32000,120 "message":"The 'minimized', 'maximized' and 'fullscreen' states cannot be combin121 ed with 'left', 'top', 'width' or 'height'"},"sessionId":"DBB8A2BC3A6EDBB228EEA5122 E26F34D42D"}123 */124 System.err.println("DevToolsException exception " + "in test5"125 + " (ignored): " + Utils.processExceptionMessage(e.getMessage()));126 }127 }128}...
Source:XHRTest.java
...9import org.openqa.selenium.By;10import org.openqa.selenium.WebDriverException;11import org.openqa.selenium.WebElement;12import org.openqa.selenium.interactions.Actions;13import org.openqa.selenium.devtools.DevToolsException;14import org.openqa.selenium.devtools.v94.fetch.Fetch;15import org.openqa.selenium.devtools.v94.fetch.model.HeaderEntry;16import org.openqa.selenium.devtools.v94.fetch.model.RequestPattern;17import org.openqa.selenium.devtools.v94.fetch.model.RequestPaused;18import org.openqa.selenium.devtools.v94.fetch.model.RequestStage;19import org.openqa.selenium.devtools.v94.network.model.ResourceType;20import org.testng.annotations.Test;21import com.google.gson.Gson;22import example.base.BaseTest;23public class XHRTest extends BaseTest {24 public Actions actions;25 private final static String url = "https://en.wikipedia.org/wiki/XMLHttpRequest";26 private final int count = 5;27 @Test28 public void test() {29 // Arrange30 List<RequestPattern> reqPattern = new ArrayList<>();31 RequestPattern xhrReqPattern = new RequestPattern(Optional.of("*"),32 Optional.of(ResourceType.XHR), Optional.of(RequestStage.RESPONSE));33 reqPattern.add(xhrReqPattern);34 devTools.send(Fetch.enable(Optional.of(reqPattern), Optional.of(false)));35 final Gson gson = new Gson();36 try {37 devTools.addListener(Fetch.requestPaused(), (RequestPaused event) -> {38 try {39 List<HeaderEntry> headerEntries = event.getResponseHeaders()40 .isPresent() ? event.getResponseHeaders().get()41 : new ArrayList<>();42 List<String> headers = headerEntries.stream()43 .map((HeaderEntry entry) -> String.format("%s: %s",44 entry.getName(), entry.getValue()))45 .collect(Collectors.toList());46 System.err.println(String.format(47 "request id: %s" + "\t" + "resource type: %s" + "\t" + "URL: %s"48 + "\n" + "response headers:\n%s" + "\n"49 + "response status: %d",50 event.getRequestId().toString(),51 event.getResourceType().toString(), event.getRequest().getUrl(),52 headers, event.getResponseStatusCode().get()));53 event.getRequest().getPostData().ifPresent((data) -> {54 System.err.println("Post Data:\n" + data + "\n");55 });56 Fetch.GetResponseBodyResponse response = devTools57 .send(Fetch.getResponseBody(event.getRequestId()));58 String body = null;59 if (response.getBase64Encoded()) {60 try {61 body = new String(62 Base64.decodeBase64(response.getBody().getBytes("UTF8")));63 } catch (UnsupportedEncodingException e) {64 System.err.println(65 "UnsupportedEncoding exception (ignored): " + e.toString());66 }67 } else {68 body = response.getBody();69 }70 System.err.println("response body:\n" + body);71 @SuppressWarnings("unchecked")72 Map<String, Object> payload = (Map<String, Object>) gson73 .fromJson(body, Map.class);74 System.err.println("response extract:\n" + payload.get("extract"));75 // NOTE: this command is returning void76 devTools.send(Fetch.continueRequest(event.getRequestId(),77 Optional.empty(), Optional.empty(), Optional.empty(),78 Optional.empty(), Optional.empty()));79 } catch (DevToolsException e) {80 System.err.println("DevTools exception (ignored): " + e.getMessage());81 }82 });83 // Act84 // hover the links in the main wikipedia document85 driver.get(url);86 sleep(1000);87 List<WebElement> elements = driver.findElement(By.id("mw-content-text"))88 .findElements(By.tagName("a"));89 actions = new Actions(driver);90 elements.stream().limit(count).forEach(element -> {91 actions.moveToElement(element).build().perform();92 sleep(1000);93 });...
Source:DevTools.java
...67 TargetID targetId = infos.stream()68 .filter(info -> "page".equals(info.getType()))69 .map(TargetInfo::getTargetId)70 .findAny()71 .orElseThrow(() -> new DevToolsException("Unable to find target id of a page"));72 // Start the session.73 cdpSession =74 connection75 .sendAndWait(cdpSession, Target.attachToTarget(targetId, Optional.of(true)), timeout);76 try {77 // We can do all of these in parallel, and we don't care about the result.78 CompletableFuture.allOf(79 // Set auto-attach to true and run for the hills.80 connection.send(cdpSession, Target.setAutoAttach(true, false, Optional.empty())),81 // Clear the existing logs82 connection.send(cdpSession, Log.clear()))83 .get(timeout.toMillis(), MILLISECONDS);84 } catch (InterruptedException e) {85 Thread.currentThread().interrupt();86 throw new IllegalStateException("Thread has been interrupted", e);87 } catch (ExecutionException e) {88 Throwable cause = e;89 if (e.getCause() != null) {90 cause = e.getCause();91 }92 throw new DevToolsException(cause);93 } catch (TimeoutException e) {94 throw new org.openqa.selenium.TimeoutException(e);95 }96 }97 public SessionID getCdpSession() {98 return cdpSession;99 }100}...
Source:FramesDevToolsTest.java
...3import java.util.Optional;4import org.junit.Before;5import org.junit.Ignore;6import org.junit.Test;7import org.openqa.selenium.devtools.DevToolsException;8import org.openqa.selenium.devtools.v97.dom.DOM;9import org.openqa.selenium.devtools.v97.dom.model.BackendNodeId;10import org.openqa.selenium.devtools.v97.dom.model.NodeId;11import org.openqa.selenium.devtools.v97.dom.model.RGBA;12import org.openqa.selenium.devtools.v97.overlay.Overlay;13import org.openqa.selenium.devtools.v97.page.Page;14import org.openqa.selenium.devtools.v97.page.model.FrameId;15import org.openqa.selenium.devtools.v97.page.model.FrameTree;16/**17 * Selected test scenarios for Selenium Chrome Developer Tools Selenium 4 bridge18 * see:19 * https://chromedevtools.github.io/devtools-protocol/tot/Page/#method-getFrameTree20 * https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-getFrameOwner21 * https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-getOuterHTML22 * https://chromedevtools.github.io/devtools-protocol/tot/Page/#type-Frame23 * https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-enable24 * https://chromedevtools.github.io/devtools-protocol/tot/Overlay/#method-enable25 * https://chromedevtools.github.io/devtools-protocol/tot/Overlay/#method-highlightFrame26 * https://chromedevtools.github.io/devtools-protocol/tot/DOM/#type-RGBA27 *28 * @author: Serguei Kouzmine (kouzmine_serguei@yahoo.com)29 */30public class FramesDevToolsTest extends BaseDevToolsTest {31 private FrameTree response = null;32 private FrameId frameId = null;33 private RGBA color = null;34 private String html = null;35 Optional<List<FrameTree>> frames = null;36 private BackendNodeId backendNodeId = null;37 private NodeId nodeId = null;38 // @Ignore39 @Before40 public void before() throws Exception {41 }42 // @Ignore43 @Test44 public void test1() {45 // Act46 // Arrange47 baseURL = "https://cloud.google.com/products/calculator";48 driver.get(baseURL);49 response = chromeDevTools.send(Page.getFrameTree());50 frames = response.getChildFrames();51 if (frames.isPresent()) {52 frames.get().stream().map(o -> o.getFrame())53 .map(frame -> String.format("Frame %s id: %s url: %s",54 frame.getName().isPresent()55 ? String.format("name: %s", frame.getName().get()) : "",56 frame.getId(), frame.getUrl()))57 .forEach(System.err::println);58 frames.get().stream().map(o -> o.getFrame()).forEach(frame -> {59 try {60 frameId = frame.getId();61 DOM.GetFrameOwnerResponse response2 = chromeDevTools62 .send(DOM.getFrameOwner(frameId));63 if (response2.getNodeId().isPresent()) {64 nodeId = response2.getNodeId().get();65 System.err.println("Frame owner node id: " + nodeId);66 }67 backendNodeId = response2.getBackendNodeId();68 System.err.println("Frame owner backend node id: " + backendNodeId);69 html = chromeDevTools.send(DOM.getOuterHTML(response2.getNodeId(),70 Optional.of(response2.getBackendNodeId()), Optional.empty()));71 System.err.println("Frame owner outer HTML: " + html);72 } catch (DevToolsException e) {73 System.err.println("Exception (ignored): " + e.toString());74 }75 });76 } else {77 System.err.println("No Frames found on " + baseURL);78 }79 }80 // @Ignore81 @Test82 public void test2() {83 // Act84 baseURL = "https://www.javatpoint.com/oprweb/test.jsp?filename=htmliframes";85 driver.get(baseURL);86 frames = chromeDevTools.send(Page.getFrameTree()).getChildFrames();87 chromeDevTools.send(DOM.enable());88 chromeDevTools.send(Overlay.enable());89 frames.get().stream().map(o -> o.getFrame()).forEach(frame -> {90 try {91 color = new RGBA(Utils.getRandomColor(), Utils.getRandomColor(),92 Utils.getRandomColor(), Optional.empty());93 frameId = frame.getId();94 chromeDevTools.send(Overlay.highlightFrame(frameId, Optional.of(color),95 Optional.empty()));96 System.err.println("Attempted to highlight frame " + frameId);97 Utils.sleep(1000);98 } catch (DevToolsException e) {99 System.err.println("Exception (ignored): " + e.toString());100 }101 });102 }103}...
Source:WindowsTabsDevToolsTest.java
...3import java.util.List;4import java.util.Optional;5import org.junit.Before;6import org.junit.Test;7import org.openqa.selenium.devtools.DevToolsException;8// NOTE letter case in the class name 9import org.openqa.selenium.devtools.v97.target.Target;10import org.openqa.selenium.devtools.v97.target.model.SessionID;11import org.openqa.selenium.devtools.v97.target.model.TargetID;12import org.openqa.selenium.devtools.v97.target.model.TargetInfo;13public class WindowsTabsDevToolsTest extends BaseDevToolsTest {14 private TargetID targetId = null;15 private SessionID sessionId = null;16 private TargetInfo targetInfo = null;17 private List<TargetInfo> targetInfos = new ArrayList<>();18 @Before19 public void before() throws Exception {20 }21 // @Ignore22 @Test23 public void test1() {24 // Arrange25 // Act26 baseURL = "https://en.wikipedia.org/wiki/Main_Page";27 targetId = chromeDevTools.send(Target.createTarget(baseURL,28 Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(),29 Optional.of(true), Optional.of(false)));30 Utils.sleep(1000);31 System.err.println("TargetID: " + targetId);32 sessionId = chromeDevTools33 .send(Target.attachToTarget(targetId, Optional.empty()));34 System.err.println("SessionId: " + sessionId);35 targetInfo = chromeDevTools36 .send(Target.getTargetInfo(Optional.of(targetId)));37 System.err.println("TargetInfo: ");38 System.err.println("TargetId: " + targetInfo.getTargetId());39 System.err.println("Title: " + targetInfo.getTitle());40 System.err.println("Type: " + targetInfo.getType());41 System.err.println("Url: " + targetInfo.getUrl());42 System.err.println("Attached: " + targetInfo.getAttached());43 targetInfos = chromeDevTools.send(Target.getTargets());44 System.err.println("TargetInfos: " + targetInfos.toString());45 targetInfos.stream()46 .forEach(o -> System.err.println("TargetInfo:" + "\n" + "TargetId: "47 + o.getTargetId() + "\n" + "Title: " + o.getTitle() + "\n"48 + "Type: " + o.getType() + "\n" + "Url: " + o.getUrl() + "\n"49 + "Attached: " + o.getAttached()));50 }51 // @Ignore52 @Test53 public void test2() {54 // Arrange55 // Act56 try {57 targetInfo = chromeDevTools.send(Target.getTargetInfo(Optional.empty()));58 System.err.println("TargetInfo: ");59 System.err.println("TargetId: " + targetInfo.getTargetId());60 System.err.println("Title: " + targetInfo.getTitle());61 System.err.println("Type: " + targetInfo.getType());62 System.err.println("Url: " + targetInfo.getUrl());63 System.err.println("Attached: " + targetInfo.getAttached());64 } catch (DevToolsException e) {65 System.err.println("DevToolsException exception " + "in test2"66 + " (ignored): " + Utils.processExceptionMessage(e.getMessage()));67 }68 targetInfos = chromeDevTools.send(Target.getTargets());69 System.err.println("TargetInfos: " + targetInfos.toString());70 }71 @Test72 public void test3() {73 // Arrange74 baseURL = "https://www.google.com";75 driver.get(baseURL);76 Utils.sleep(1000);77 // Act78 try {79 sessionId = chromeDevTools.send(Target.attachToBrowserTarget());80 System.err.println("SessionId: " + sessionId);81 } catch (DevToolsException e) {82 System.err.println("DevToolsException exception " + "in test3"83 + " (ignored): " + Utils.processExceptionMessage(e.getMessage()));84 }85 }86}...
Source:GridFactory.java
23import org.openqa.selenium.Platform;4import org.openqa.selenium.WebDriver;5import org.openqa.selenium.devtools.DevTools;6import org.openqa.selenium.devtools.DevToolsException;7import org.openqa.selenium.devtools.HasDevTools;8import org.openqa.selenium.remote.Augmenter;9import org.openqa.selenium.remote.DesiredCapabilities;10import org.openqa.selenium.remote.RemoteWebDriver;1112import java.net.MalformedURLException;13import java.net.URL;14import java.util.HashMap;15import java.util.Map;16import java.util.logging.Level;1718import org.slf4j.Logger;19import org.slf4j.LoggerFactory;2021public class GridFactory {2223 private ThreadLocal<WebDriver> driver = new ThreadLocal<>();24 private ThreadLocal<DevTools> devTools = new ThreadLocal<>();25 private String browser;26 private String platform;27 private Logger logger = LoggerFactory.getLogger(GridFactory.class);28 private Map<String, Object> results = new HashMap<>();2930 public GridFactory(String browser, String platform, Logger logger) {31 this.browser = browser.toLowerCase();32 this.platform = platform;33 this.logger = logger;34 }3536 public Map<String, Object> createDriver() {37 logger.info("Connecting to the node with: : " + browser);3839 DesiredCapabilities capabilities = new DesiredCapabilities();4041 switch (browser) {42 case "chrome":43 capabilities.setBrowserName("chrome");44 break;4546 case "firefox":47 capabilities.setBrowserName("firefox");48 break;4950 default:51 capabilities.setBrowserName("chrome");52 break;53 }5455 switch (platform) {56 case "WINDOWS":57 capabilities.setPlatform(Platform.WINDOWS);58 break;5960 case "MAC":61 capabilities.setPlatform(Platform.MAC);62 break;6364 case "LINUX":65 capabilities.setPlatform(Platform.LINUX);66 break;6768 default:69 capabilities.setPlatform(Platform.LINUX);70 break;71 }7273 try {74 URL url = new URL("http://localhost:4444");75 WebDriver webDriver = new RemoteWebDriver(url, capabilities);76 webDriver = new Augmenter().augment(webDriver);77 driver.set(webDriver);78 results.put("driver", driver.get());79 try {80 DevTools chromeDevTools = ((HasDevTools) webDriver).getDevTools();81 devTools.set(chromeDevTools);82 results.put("devtools", devTools.get());8384 } catch (DevToolsException e) {85 logger.info(86 "Exception: " + e.toString() + "\n" + e.getAdditionalInformation()87 + "\n" + e.getRawMessage() + "\n" + e.getStackTrace());8889 results.put("devtools", null);90 }91 // set additional logging in Selenium92 java.util.logging.Logger.getLogger("org.openqa.selenium")93 .setLevel(Level.SEVERE);94 } catch (MalformedURLException e) {95 e.printStackTrace();96 }97 return results;98 }
...
Source:NoOpDomains.java
...15// specific language governing permissions and limitations16// under the License.17package org.openqa.selenium.devtools.noop;18import org.openqa.selenium.BuildInfo;19import org.openqa.selenium.devtools.DevToolsException;20import org.openqa.selenium.devtools.idealized.Domains;21import org.openqa.selenium.devtools.idealized.Events;22import org.openqa.selenium.devtools.idealized.Javascript;23import org.openqa.selenium.devtools.idealized.Network;24import org.openqa.selenium.devtools.idealized.log.Log;25import org.openqa.selenium.devtools.idealized.target.Target;26public class NoOpDomains implements Domains {27 private static BuildInfo INFO = new BuildInfo();28 private final static String WARNING = String.format(29 "You are using a no-op implementation of the CDP. The most likely reason" +30 " for this is that Selenium was unable to find an implementation of the " +31 "CDP protocol that matches your browser. Please be sure to include an " +32 "implementation on the classpath, possibly by adding a new (maven) " +33 "dependency of `org.seleniumhq.selenium:selenium-devtools-vNN:%s` where " +34 "`NN` matches the major version of the browser you're using.",35 INFO.getReleaseLabel());36 @Override37 public Events<?, ?> events() {38 throw new DevToolsException(WARNING);39 }40 @Override41 public Javascript<?, ?> javascript() {42 throw new DevToolsException(WARNING);43 }44 @Override45 public Network<?, ?> network() {46 throw new DevToolsException(WARNING);47 }48 @Override49 public Target target() {50 throw new DevToolsException(WARNING);51 }52 @Override53 public Log log() {54 throw new DevToolsException(WARNING);55 }56 @Override57 public void disableAll() {58 throw new DevToolsException(WARNING);59 }60}
DevToolsException
Using AI Code Generation
1import org.openqa.selenium.devtools.DevToolsException;2import org.openqa.selenium.devtools.v91.browser.Browser;3import org.openqa.selenium.devtools.v91.browser.model.BrowserContextID;4import org.openqa.selenium.devtools.v91.browser.model.BrowserContextInfo;5import org.openqa.selenium.devtools.v91.browser.model.BrowserInfo;6import org.openqa.selenium.devtools.v91.browser.model.BrowserVersion;7import org.openqa.selenium.devtools.v91.browser.model.WindowBounds;8import org.openqa.selenium.devtools.v91.browser.model.WindowID;9import org.openqa.selenium.devtools.v91.browser.model.WindowState;10import org.openqa.selenium.devtools.v91.browser.model.WindowType;11import java.util.List;12import java.util.concurrent.TimeUnit;13public class BrowserTest {14 public static void main(String[] args) {15 try (var driver = new ChromeDriver()) {16 var devTools = driver.getDevTools();17 devTools.createSession();18 BrowserInfo browserInfo = devTools.send(Browser.getVersion());19 System.out.println("Browser Name: " + browserInfo.getName());20 System.out.println("Browser Version: " + browserInfo.getVersion());21 System.out.println("Browser User Agent: " + browserInfo.getUserAgent());22 System.out.println("Browser Protocol Version: " + browserInfo.getProtocolVersion());23 BrowserVersion browserVersion = devTools.send(Browser.getBrowserCommandLine());24 System.out.println("Browser Executable Path: " + browserVersion.getExecutablePath());25 System.out.println("Browser Version: " + browserVersion.getVersion());26 System.out.println("Browser Product: " + browserVersion.getProduct());27 System.out.println("Browser User Agent: " + browserVersion.getUserAgent());28 System.out.println("Browser V8 Version: " + browserVersion.getV8Version());29 System.out.println("Browser WebKit Version: " + browserVersion.getWebKitVersion());30 System.out.println("Browser Blink Version: " + browserVersion.getBlinkVersion());31 List<BrowserContextInfo> browserContextInfoList = devTools.send(Browser.getBrowserContexts());32 System.out.println("Browser Contexts: " + browserContextInfoList);33 WindowID windowId = devTools.send(Browser.getWindowForTarget());34 System.out.println("Window ID: " + windowId);35 WindowBounds windowBounds = devTools.send(Browser.getWindowBounds(windowId));36 System.out.println("Window Bounds: " + windowBounds);37 WindowState windowState = devTools.send(Browser.getWindowState
DevToolsException
Using AI Code Generation
1import org.openqa.selenium.devtools.DevToolsException;2import org.openqa.selenium.devtools.v91.browser.Browser;3import org.openqa.selenium.devtools.v91.browser.model.BrowserContextID;4import org.openqa.selenium.devtools.v91.browser.model.Bounds;5import org.openqa.selenium.devtools.v91.browser.model.PermissionType;6import org.openqa.selenium.devtools.v91.browser.model.WindowID;7import org.openqa.selenium.devtools.v91.browser.model.WindowState;8import org.openqa.selenium.devtools.v91.browser.model.WindowType;9import org.openqa.selenium.devtools.v91.browser.model.WindowTypeChanged;10import org.openqa.selenium.devtools.v91.browser.model.WindowTypes;11import org.openqa.selenium.devtools.v91.browser.model.WindowViewBoundsChanged;12import org.openqa.selenium.devtools.v91.browser.model.WindowViewBoundsChangedEvent;13import org.openqa.selenium.devtools.v91.browser.model.WindowViewBoundsChangedEventBounds;14import org.openqa.selenium.devtools.v91.browser.model.WindowViewBoundsChangedEventBoundsBounds;15import org.openqa.selenium.devtools.v91.browser.model.WindowViewBoundsChangedEventBoundsBoundsOrigin;16import org.openqa.selenium.devtools.v91.browser.model.WindowViewBoundsChangedEventBoundsBoundsSize;17import org.openqa.selenium.devtools.v91.browser.model.WindowViewBoundsChangedEventBoundsBoundsSizeDimension;18import org.openqa.selenium.devtools.v91.browser.model.WindowViewBoundsChangedEventBoundsBoundsSizeDimensionDimension;19import org.openqa.selenium.devtools.v91.browser.model.WindowViewBoundsChangedEventBoundsBoundsSizeDimensionDimensionDimension;20import org.openqa.selenium.devtools.v91.browser.model.WindowViewBoundsChangedEventBoundsBoundsSizeDimensionDimensionDimensionDimension;21import org.openqa.selenium.devtools.v91.browser.model.WindowViewBoundsChangedEventBoundsBoundsSizeDimensionDimensionDimensionDimensionDimension;22import org.openqa.selenium.devtools.v91.browser.model.WindowViewBoundsChangedEventBoundsBoundsSizeDimensionDimensionDimensionDimensionDimensionDimension;23import org.openqa.selenium.devtools.v91.browser.model.WindowViewBoundsChangedEventBoundsBoundsSizeDimensionDimensionDimensionDimensionDimensionDimensionDimension;24import org.openqa.selenium.devtools.v91.browser.model.WindowViewBoundsChangedEventBoundsBoundsSizeDimensionDimensionDimensionDimensionDimensionDimensionDimensionDimension;25import org.openqa.selenium.devtools.v91.browser.model.WindowViewBoundsChangedEventBoundsBoundsSizeDimensionDimensionDimensionDimensionDimensionDimensionDimensionDimensionDimension;26import org.openqa.selenium.devtools.v91.browser.model.WindowViewBoundsChangedEventBoundsBoundsSizeDimensionDimensionDimensionDimensionDimensionDimensionDimensionDimensionDimensionDimension;27import org.openqa.selenium.devtools.v91.browser.model.WindowViewBoundsChangedEventBoundsBoundsSizeDimensionDimensionDimension
DevToolsException
Using AI Code Generation
1package org.openqa.selenium.devtools;2import org.openqa.selenium.WebDriverException;3public class DevToolsException extends WebDriverException {4 public DevToolsException(String message) {5 super(message);6 }7 public DevToolsException(String message, Throwable cause) {8 super(message, cause);9 }10}11package org.openqa.selenium.devtools;12import org.openqa.selenium.WebDriverException;13public class DevToolsException extends WebDriverException {14 public DevToolsException(String message) {15 super(message);16 }17 public DevToolsException(String message, Throwable cause) {18 super(message, cause);19 }20}21package org.openqa.selenium.devtools;22import org.openqa.selenium.WebDriverException;23public class DevToolsException extends WebDriverException {24 public DevToolsException(String message) {25 super(message);26 }27 public DevToolsException(String message, Throwable cause) {28 super(message, cause);29 }30}31package org.openqa.selenium.devtools;32import org.openqa.selenium.WebDriverException;33public class DevToolsException extends WebDriverException {34 public DevToolsException(String message) {35 super(message);36 }37 public DevToolsException(String message, Throwable cause) {38 super(message, cause);39 }40}41package org.openqa.selenium.devtools;42import org.openqa.selenium.WebDriverException;43public class DevToolsException extends WebDriverException {44 public DevToolsException(String message) {45 super(message);46 }47 public DevToolsException(String message, Throwable cause) {48 super(message, cause);49 }50}51package org.openqa.selenium.devtools;52import org.openqa.selenium.WebDriverException;53public class DevToolsException extends WebDriverException {
DevToolsException
Using AI Code Generation
1import org.openqa.selenium.devtools.DevToolsException;2public class DevToolsExceptionExample {3public static void main(String[] args) {4try {5} catch (DevToolsException e) {6System.out.println(e.getMessage());7}8}9}10import org.openqa.selenium.devtools.DevToolsException;11public class DevToolsExceptionExample {12public static void main(String[] args) {13try {14} catch (DevToolsException e) {15System.out.println(e.getMessage());16}17}18}19import org.openqa.selenium.devtools.DevToolsException;20public class DevToolsExceptionExample {21public static void main(String[] args) {22try {23} catch (DevToolsException e) {24System.out.println(e.getMessage());25}26}27}28import org.openqa.selenium.devtools.DevToolsException;29public class DevToolsExceptionExample {30public static void main(String[] args) {31try {32} catch (DevToolsException e) {33System.out.println(e.getMessage());34}35}36}37import org.openqa.selenium.devtools.DevToolsException;38public class DevToolsExceptionExample {39public static void main(String[] args) {40try {41} catch (DevToolsException e) {42System.out.println(e.getMessage());43}44}45}46import org.openqa.selenium.devtools.DevToolsException;
DevToolsException
Using AI Code Generation
1devTools.createSession();2devTools.send(Network.enable(Optional.empty(), Optional.empty(), Optional.empty()));3devTools.send(Network.emulateNetworkConditions(false, 0, 0, 0, Optional.empty()));4devTools.send(Network.emulateNetworkConditions(true, 0, 0, 0, Optional.empty()));5devTools.send(Network.emulateNetworkConditions(false, 0, 0, 0, Optional.empty()));6devTools.send(Network.emulateNetworkConditions(true, 0, 0, 0, Optional.empty()));7devTools.send(Network.disable());8devTools.close();9driver.close();10driver.quit();
DevToolsException
Using AI Code Generation
1public class DevToolsExceptionExample {2 public static void main(String[] args) {3 WebDriver driver = new ChromeDriver();4 DevTools devTools = ((ChromeDriver) driver).getDevTools();5 DevToolsException devToolsException = new DevToolsException("DevToolsException");6 System.out.println(devToolsException.getMessage());7 driver.close();8 }9}
LambdaTest’s Selenium 4 tutorial is covering every aspects of Selenium 4 testing with examples and best practices. Here you will learn basics, such as how to upgrade from Selenium 3 to Selenium 4, to some advanced concepts, such as Relative locators and Selenium Grid 4 for Distributed testing. Also will learn new features of Selenium 4, such as capturing screenshots of specific elements, opening a new tab or window on the browser, and new protocol adoptions.
Upgrading From Selenium 3 To Selenium 4?: In this chapter, learn in detail how to update Selenium 3 to Selenium 4 for Java binding. Also, learn how to upgrade while using different build tools such as Maven or Gradle and get comprehensive guidance for upgrading Selenium.
What’s New In Selenium 4 & What’s Being Deprecated? : Get all information about new implementations in Selenium 4, such as W3S protocol adaption, Optimized Selenium Grid, and Enhanced Selenium IDE. Also, learn what is deprecated for Selenium 4, such as DesiredCapabilites and FindsBy methods, etc.
Selenium 4 With Python: Selenium supports all major languages, such as Python, C#, Ruby, and JavaScript. In this chapter, learn how to install Selenium 4 for Python and the features of Python in Selenium 4, such as Relative locators, Browser manipulation, and Chrom DevTool protocol.
Selenium 4 Is Now W3C Compliant: JSON Wireframe protocol is retiring from Selenium 4, and they are adopting W3C protocol to learn in detail about the advantages and impact of these changes.
How To Use Selenium 4 Relative Locator? : Selenium 4 came with new features such as Relative Locators that allow constructing locators with reference and easily located constructors nearby. Get to know its different use cases with examples.
Selenium Grid 4 Tutorial For Distributed Testing: Selenium Grid 4 allows you to perform tests over different browsers, OS, and device combinations. It also enables parallel execution browser testing, reads up on various features of Selenium Grid 4 and how to download it, and runs a test on Selenium Grid 4 with best practices.
Selenium Video Tutorials: Binge on video tutorials on Selenium by industry experts to get step-by-step direction from automating basic to complex test scenarios with Selenium.
LambdaTest also provides certification for Selenium testing to accelerate your career in Selenium automation testing.
Get 100 minutes of automation test minutes FREE!!