How to use Message class of org.openqa.selenium.devtools package

Best Selenium code snippet using org.openqa.selenium.devtools.Message

Source:ChromeDevToolsNetworkTest.java Github

copy

Full Screen

...44import static org.openqa.selenium.devtools.v84.network.Network.deleteCookies;45import static org.openqa.selenium.devtools.v84.network.Network.disable;46import static org.openqa.selenium.devtools.v84.network.Network.emulateNetworkConditions;47import static org.openqa.selenium.devtools.v84.network.Network.enable;48import static org.openqa.selenium.devtools.v84.network.Network.eventSourceMessageReceived;49import static org.openqa.selenium.devtools.v84.network.Network.getAllCookies;50import static org.openqa.selenium.devtools.v84.network.Network.getCertificate;51import static org.openqa.selenium.devtools.v84.network.Network.getCookies;52import static org.openqa.selenium.devtools.v84.network.Network.getRequestPostData;53import static org.openqa.selenium.devtools.v84.network.Network.getResponseBody;54import static org.openqa.selenium.devtools.v84.network.Network.loadingFailed;55import static org.openqa.selenium.devtools.v84.network.Network.loadingFinished;56import static org.openqa.selenium.devtools.v84.network.Network.requestIntercepted;57import static org.openqa.selenium.devtools.v84.network.Network.requestServedFromCache;58import static org.openqa.selenium.devtools.v84.network.Network.requestWillBeSent;59import static org.openqa.selenium.devtools.v84.network.Network.resourceChangedPriority;60import static org.openqa.selenium.devtools.v84.network.Network.responseReceived;61import static org.openqa.selenium.devtools.v84.network.Network.searchInResponseBody;62import static org.openqa.selenium.devtools.v84.network.Network.setBlockedURLs;63import static org.openqa.selenium.devtools.v84.network.Network.setBypassServiceWorker;64import static org.openqa.selenium.devtools.v84.network.Network.setCacheDisabled;65import static org.openqa.selenium.devtools.v84.network.Network.setCookie;66import static org.openqa.selenium.devtools.v84.network.Network.setDataSizeLimitsForTest;67import static org.openqa.selenium.devtools.v84.network.Network.setExtraHTTPHeaders;68import static org.openqa.selenium.devtools.v84.network.Network.setRequestInterception;69import static org.openqa.selenium.devtools.v84.network.Network.setUserAgentOverride;70import static org.openqa.selenium.devtools.v84.network.Network.signedExchangeReceived;71import static org.openqa.selenium.devtools.v84.network.Network.webSocketClosed;72import static org.openqa.selenium.devtools.v84.network.Network.webSocketCreated;73import static org.openqa.selenium.devtools.v84.network.Network.webSocketFrameError;74import static org.openqa.selenium.devtools.v84.network.Network.webSocketFrameReceived;75import static org.openqa.selenium.devtools.v84.network.Network.webSocketFrameSent;76import static org.openqa.selenium.testing.drivers.Browser.CHROME;77public class ChromeDevToolsNetworkTest extends DevToolsTestBase {78 @Test79 public void getSetDeleteAndClearAllCookies() {80 devTools.send(enable(Optional.empty(), Optional.empty(), Optional.empty()));81 List<Cookie> allCookies = devTools.send(getAllCookies());82 assertEquals(0, allCookies.size());83 boolean setCookie = devTools.send(setCookie(84 "name",85 "value",86 Optional.of("http://localhost/devtools/test"),87 Optional.of("localhost"),88 Optional.of("/devtools/test"),89 Optional.empty(),90 Optional.empty(),91 Optional.empty(),92 Optional.empty(),93 Optional.empty()));94 assertTrue(setCookie);95 assertEquals(1, devTools.send(getAllCookies()).size());96 assertEquals(0, devTools.send(getCookies(Optional.empty())).size());97 devTools.send(deleteCookies("name", Optional.empty(), Optional.of("localhost"),98 Optional.of("/devtools/test")));99 devTools.send(clearBrowserCookies());100 assertEquals(0, devTools.send(getAllCookies()).size());101 setCookie = devTools.send(setCookie(102 "name",103 "value",104 Optional.of("http://localhost/devtools/test"),105 Optional.of("localhost"),106 Optional.of("/devtools/test"),107 Optional.empty(),108 Optional.empty(),109 Optional.empty(),110 Optional.empty(),111 Optional.empty()));112 assertTrue(setCookie);113 assertEquals(1, devTools.send(getAllCookies()).size());114 }115 @Test116 public void sendRequestWithUrlFiltersAndExtraHeadersAndVerifyRequests() {117 devTools.send(enable(Optional.empty(), Optional.empty(), Optional.empty()));118 devTools.send(setBlockedURLs(singletonList("*://*/*.css")));119 devTools.send(setExtraHTTPHeaders(new Headers(ImmutableMap.of("headerName", "headerValue"))));120 devTools.addListener(loadingFailed(), loadingFailed -> {121 if (loadingFailed.getType().equals(ResourceType.STYLESHEET)) {122 assertEquals(loadingFailed.getBlockedReason(), BlockedReason.INSPECTOR);123 }124 });125 devTools.addListener(requestWillBeSent(), requestWillBeSent -> assertEquals(requestWillBeSent.getRequest().getHeaders().get("headerName"),126 "headerValue"));127 devTools.addListener(dataReceived(),128 dataReceived -> Assert.assertNotNull(dataReceived.getRequestId()));129 driver.get(appServer.whereIs("js/skins/lightgray/content.min.css"));130 }131 @Test132 public void emulateNetworkConditionOffline() {133 devTools.send(enable(Optional.of(100000000), Optional.empty(), Optional.empty()));134 devTools.send(135 emulateNetworkConditions(true, 100, 1000, 2000, Optional.of(ConnectionType.CELLULAR3G)));136 devTools.addListener(loadingFailed(), loadingFailed -> assertEquals(loadingFailed.getErrorText(), "net::ERR_INTERNET_DISCONNECTED"));137 driver.get(appServer.whereIs("simpleTest.html"));138 }139 @Test140 public void verifyRequestReceivedFromCacheAndResponseBody() {141 final RequestId[] requestIdFromCache = new RequestId[1];142 devTools.send(enable(Optional.empty(), Optional.of(100000000), Optional.empty()));143 devTools.addListener(requestServedFromCache(), requestId -> {144 Assert.assertNotNull(requestId);145 requestIdFromCache[0] = requestId;146 });147 devTools.addListener(loadingFinished(),148 dataReceived -> Assert.assertNotNull(dataReceived.getRequestId()));149 driver.get(appServer.whereIsSecure("simpleTest.html"));150 driver.get(appServer.whereIsSecure("simpleTest.html"));151 Network.GetResponseBodyResponse responseBody = devTools.send(getResponseBody(requestIdFromCache[0]));152 Assert.assertNotNull(responseBody);153 }154 @Test155 public void verifySearchInResponseBody() {156 final RequestId[] requestIds = new RequestId[1];157 devTools.send(enable(Optional.empty(), Optional.of(100000000), Optional.empty()));158 devTools.addListener(responseReceived(), responseReceived -> {159 Assert.assertNotNull(responseReceived);160 Assert.assertNotNull(responseReceived.getResponse().getTiming());161 requestIds[0] = responseReceived.getRequestId();162 });163 driver.get(appServer.whereIs("simpleTest.html"));164 assertTrue(devTools.send(165 searchInResponseBody(requestIds[0], "/", Optional.empty(), Optional.empty())).size()166 > 0);167 }168 @Test169 public void verifyCacheDisabledAndClearCache() {170 devTools.send(enable(Optional.empty(), Optional.empty(), Optional.of(100000000)));171 driver.get(appServer.whereIs("simpleTest.html"));172 devTools.send(setCacheDisabled(true));173 devTools.addListener(responseReceived(), responseReceived -> assertEquals(false, responseReceived.getResponse().getFromDiskCache()));174 driver.get(appServer.whereIs("simpleTest.html"));175 devTools.send(clearBrowserCache());176 }177 @Test178 @NotYetImplemented(CHROME)179 public void verifyCertificatesAndOverrideUserAgent() {180 devTools.send(enable(Optional.empty(), Optional.empty(), Optional.empty()));181 devTools.send(setUserAgentOverride("userAgent", Optional.empty(), Optional.empty(), Optional.empty()));182 devTools.addListener(requestWillBeSent(),183 requestWillBeSent -> assertEquals("userAgent",184 requestWillBeSent185 .getRequest()186 .getHeaders()187 .get("User-Agent")));188 driver.get(appServer.whereIsSecure("simpleTest.html"));189 assertThat(devTools.send(getCertificate(appServer.whereIsSecure("simpleTest.html")))).isNotEmpty();190 }191 @Test192 public void verifyResponseReceivedEventAndNetworkDisable() {193 devTools.send(enable(Optional.empty(), Optional.empty(), Optional.empty()));194 devTools.addListener(responseReceived(), Assert::assertNotNull);195 driver.get(appServer.whereIs("simpleTest.html"));196 devTools.send(disable());197 }198 @Test199 public void verifyWebSocketOperations() {200 devTools.send(enable(Optional.empty(), Optional.empty(), Optional.empty()));201 devTools.addListener(webSocketCreated(), Assert::assertNotNull);202 devTools.addListener(webSocketFrameReceived(), Assert::assertNotNull);203 devTools.addListener(webSocketClosed(), Assert::assertNotNull);204 devTools.addListener(webSocketFrameError(), Assert::assertNotNull);205 devTools.addListener(webSocketFrameSent(), Assert::assertNotNull);206 driver.get(appServer.whereIs("simpleTest.html"));207 }208 @Test209 public void verifyRequestPostData() {210 devTools.send(enable(Optional.empty(), Optional.empty(), Optional.empty()));211 final RequestId[] requestIds = new RequestId[1];212 devTools.addListener(requestWillBeSent(), requestWillBeSent -> {213 Assert.assertNotNull(requestWillBeSent);214 if (requestWillBeSent.getRequest().getMethod().equalsIgnoreCase(HttpMethod.POST.name())) {215 requestIds[0] = requestWillBeSent.getRequestId();216 }217 });218 driver.get(appServer.whereIs("postForm.html"));219 driver.findElement(By.xpath("/html/body/form/input")).click();220 Assert.assertNotNull(devTools.send(getRequestPostData(requestIds[0])));221 }222 @Test223 public void byPassServiceWorker() {224 devTools.send(enable(Optional.empty(), Optional.empty(), Optional.empty()));225 devTools.send(setBypassServiceWorker(true));226 }227 @Test228 public void dataSizeLimitsForTest() {229 devTools.send(enable(Optional.empty(), Optional.empty(), Optional.empty()));230 devTools.send(setDataSizeLimitsForTest(10000, 100000));231 }232 @Test233 public void verifyEventSourceMessage() {234 devTools.send(enable(Optional.empty(), Optional.empty(), Optional.empty()));235 devTools.addListener(eventSourceMessageReceived(), Assert::assertNotNull);236 driver.get(appServer.whereIs("simpleTest.html"));237 }238 @Test239 public void verifySignedExchangeReceived() {240 devTools.send(enable(Optional.empty(), Optional.empty(), Optional.empty()));241 devTools.addListener(signedExchangeReceived(), Assert::assertNotNull);242 driver.get(appServer.whereIsSecure("simpleTest.html"));243 }244 @Test245 public void verifyResourceChangedPriority() {246 devTools.send(enable(Optional.empty(), Optional.empty(), Optional.empty()));247 devTools.addListener(resourceChangedPriority(), Assert::assertNotNull);248 driver.get(appServer.whereIsSecure("simpleTest.html"));249 }...

Full Screen

Full Screen

Source:Main.java Github

copy

Full Screen

...121// targetInfos.forEach(122// targetInfo -> {123// var sessionId = devTools.send(attachToTarget(targetInfo.getTargetId(), Optional.of(false)));124// devTools.send(125// Target.sendMessageToTarget(126// "{\"method\":\"Page.crash\"}",127// Optional.of(sessionId),128// Optional.of(targetInfo.getTargetId())));129// });130// devTools.send(Inspector.disable());131// }132//133//134// /**135// * Get Console Logs136// * @param chromeDevTools137// * @param message138// */139// private static void consoleLogs(DevTools chromeDevTools, String message) {140//141// chromeDevTools.send(Console.enable());142//143// //add listener to verify the console message144// chromeDevTools.addListener(Console.messageAdded(), consoleMessageFromDevTools ->145// assertEquals(true, consoleMessageFromDevTools.getText().equals(message)));146//147// }148//149// /**150// * Selenium Misc features151// * @param chromeDriver152// */153// private static void Selenium4MiscFetures(ChromeDriver chromeDriver){154//155// // New Tab156// var newTab = chromeDriver.switchTo().newWindow(WindowType.TAB);157// newTab.get("http://executeautomation.com/demosite/Login.html");158//159// //login...

Full Screen

Full Screen

Source:ChromeDevToolsTargetTest.java Github

copy

Full Screen

...16// under the License.17package org.openqa.selenium.devtools;18import org.junit.Assert;19import org.junit.Test;20import org.openqa.selenium.devtools.v84.target.model.ReceivedMessageFromTarget;21import org.openqa.selenium.devtools.v84.target.model.SessionID;22import org.openqa.selenium.devtools.v84.target.model.TargetCrashed;23import org.openqa.selenium.devtools.v84.target.model.TargetID;24import org.openqa.selenium.devtools.v84.target.model.TargetInfo;25import java.util.ArrayList;26import java.util.List;27import java.util.Optional;28import static org.junit.Assert.assertEquals;29import static org.junit.Assert.assertFalse;30import static org.junit.Assert.assertNotNull;31import static org.junit.Assert.assertTrue;32import static org.openqa.selenium.devtools.v84.target.Target.activateTarget;33import static org.openqa.selenium.devtools.v84.target.Target.attachToTarget;34import static org.openqa.selenium.devtools.v84.target.Target.attachedToTarget;35import static org.openqa.selenium.devtools.v84.target.Target.closeTarget;36import static org.openqa.selenium.devtools.v84.target.Target.createTarget;37import static org.openqa.selenium.devtools.v84.target.Target.getTargetInfo;38import static org.openqa.selenium.devtools.v84.target.Target.getTargets;39import static org.openqa.selenium.devtools.v84.target.Target.receivedMessageFromTarget;40import static org.openqa.selenium.devtools.v84.target.Target.sendMessageToTarget;41import static org.openqa.selenium.devtools.v84.target.Target.setDiscoverTargets;42import static org.openqa.selenium.devtools.v84.target.Target.targetCrashed;43import static org.openqa.selenium.devtools.v84.target.Target.targetCreated;44import static org.openqa.selenium.devtools.v84.target.Target.targetDestroyed;45import static org.openqa.selenium.devtools.v84.target.Target.targetInfoChanged;46public class ChromeDevToolsTargetTest extends DevToolsTestBase {47 private final int id = 123;48 @Test49 public void getTargetActivateAndAttach() {50 devTools.addListener(attachedToTarget(), Assert::assertNotNull);51 driver.get(appServer.whereIs("devToolsConsoleTest.html"));52 List<TargetInfo> allTargets = devTools.send(getTargets());53 for (TargetInfo target : allTargets) {54 validateTarget(target);55 devTools.send(activateTarget(target.getTargetId()));56 SessionID sessionId =57 devTools.send(attachToTarget(target.getTargetId(), Optional.of(Boolean.FALSE)));58 validateSession(sessionId);59 TargetInfo infods = devTools.send(getTargetInfo(Optional.of(target.getTargetId())));60 validateTargetInfo(infods);61 }62 }63 @Test64 public void getTargetAndSendMessageToTarget() {65 List<TargetInfo> allTargets = null;66 SessionID sessionId = null;67 TargetInfo targetInfo = null;68 driver.get(appServer.whereIs("devToolsConsoleTest.html"));69 devTools.addListener(receivedMessageFromTarget(), this::validateMessage);70 allTargets = devTools.send(getTargets());71 validateTargetsInfos(allTargets);72 ArrayList<TargetInfo> listTargets = new ArrayList<>(allTargets);73 validateTarget(listTargets.get(0));74 targetInfo = listTargets.get(0);75 devTools.send(activateTarget(targetInfo.getTargetId()));76 sessionId = devTools.send(attachToTarget(targetInfo.getTargetId(), Optional.of(false)));77 validateSession(sessionId);78 devTools.send(79 sendMessageToTarget(80 "{\"id\":" + id + ",\"method\":\"Page.bringToFront\"}",81 Optional.of(sessionId),82 Optional.of(targetInfo.getTargetId())));83 }84 @Test85 public void createAndContentLifeCycle() {86 devTools.addListener(targetCreated(), this::validateTargetInfo);87 devTools.addListener(targetCrashed(), this::validateTargetCrashed);88 devTools.addListener(targetDestroyed(), this::validateTargetId);89 devTools.addListener(targetInfoChanged(), this::validateTargetInfo);90 TargetID target =91 devTools.send(92 createTarget(93 appServer.whereIs("devToolsConsoleTest.html"),94 Optional.empty(),95 Optional.empty(),96 Optional.empty(),97 Optional.empty(),98 Optional.of(Boolean.TRUE),99 Optional.of(Boolean.FALSE)));100 validateTargetId(target);101 devTools.send(setDiscoverTargets(true));102 Boolean isClosed = devTools.send(closeTarget(target));103 assertNotNull(isClosed);104 assertTrue(isClosed);105 }106 private void validateTargetCrashed(TargetCrashed targetCrashed) {107 assertNotNull(targetCrashed);108 assertNotNull(targetCrashed.getStatus());109 assertNotNull(targetCrashed.getTargetId());110 }111 private void validateTargetId(TargetID targetId) {112 assertNotNull(targetId);113 }114 private void validateMessage(ReceivedMessageFromTarget messageFromTarget) {115 assertNotNull(messageFromTarget);116 assertNotNull(messageFromTarget.getMessage());117 assertNotNull(messageFromTarget.getSessionId());118 assertNotNull(messageFromTarget.getMessage());119 assertEquals("{\"id\":" + id + ",\"result\":{}}", messageFromTarget.getMessage());120 }121 private void validateTargetInfo(TargetInfo targetInfo) {122 assertNotNull(targetInfo);123 assertNotNull(targetInfo.getTargetId());124 assertNotNull(targetInfo.getTitle());125 assertNotNull(targetInfo.getType());126 assertNotNull(targetInfo.getUrl());127 }128 private void validateTargetsInfos(List<TargetInfo> targets) {129 assertNotNull(targets);130 assertFalse(targets.isEmpty());131 }132 private void validateTarget(TargetInfo targetInfo) {133 assertNotNull(targetInfo);...

Full Screen

Full Screen

Source:Selenium4CDPTest.java Github

copy

Full Screen

...8import org.junit.Test;9import org.openqa.selenium.chrome.ChromeDriver;10import org.openqa.selenium.devtools.Command;11import org.openqa.selenium.devtools.DevTools;12import org.openqa.selenium.devtools.Message;13import org.openqa.selenium.devtools.network.Network;14import org.openqa.selenium.devtools.network.model.ConnectionType;15import org.openqa.selenium.devtools.network.model.InterceptionStage;16import org.openqa.selenium.devtools.network.model.RequestPattern;17import org.openqa.selenium.devtools.network.model.ResourceType;18import org.openqa.selenium.devtools.performance.Performance;19import org.openqa.selenium.devtools.performance.model.TimeDomain;20import org.openqa.selenium.devtools.security.Security;21import org.openqa.selenium.logging.LogEntries;22import org.openqa.selenium.logging.LogEntry;23import org.openqa.selenium.logging.LogType;24import org.openqa.selenium.logging.LoggingPreferences;25import org.openqa.selenium.remote.CapabilityType;26import org.openqa.selenium.remote.DesiredCapabilities;27import java.io.File;28import java.nio.file.Paths;29import java.util.Optional;30import static org.openqa.selenium.devtools.network.Network.*;31import static org.openqa.selenium.devtools.security.Security.setIgnoreCertificateErrors;32public class Selenium4CDPTest {33 ChromeDriver driver;34 DevTools devTools;35 @Test36 public void simulateNetworkBandwidthTest() throws InterruptedException {37 driver.get("http://www.google.com");38 devTools.createSession();39 devTools.send(40 enable(Optional.of(100000000), Optional.empty(), Optional.empty()));41 devTools.send(emulateNetworkConditions(false, 100, 1000, 2000,42 Optional.of(ConnectionType.cellular3g)));43 driver.get("https://seleniumconf.co.uk");44 waitForWebsiteToLoad();45 }46 @Test47 public void simulateBandwidthWithExecCDPTest() throws InterruptedException {48 MessageBuilder message = Messages.enableNetwork();49 driver.get("http://www.google.com");50 driver.executeCdpCommand(message.method, message.params);51 MessageBuilder simulateNetwork = Messages.setNetworkBandWidth();52 driver.executeCdpCommand(simulateNetwork.method, simulateNetwork.params);53 driver.get("https://seleniumconf.co.uk");54 waitForWebsiteToLoad();55 }56 @Test57 public void setGeolocationTest() throws InterruptedException {58 String getLocationLocator = "//*[@id=\"content\"]/div/button";59 driver.get("https://the-internet.herokuapp.com/geolocation");60 MessageBuilder simulateLocation = Messages.overrideLocation();61 driver.executeCdpCommand(simulateLocation.method, simulateLocation.params);62 driver.findElementByXPath(getLocationLocator).click();63 waitForWebsiteToLoad();64 }65 @Test66 public void mockWebResponseTest() throws InterruptedException {67 devTools.createSession();68 devTools.send(69 enable(Optional.of(100000000), Optional.empty(), Optional.empty()));70 devTools71 .addListener(requestIntercepted(),72 requestIntercepted -> devTools.send(continueInterceptedRequest(73 requestIntercepted.getInterceptionId(), Optional.empty(),74 Optional.of("This is Mocked!!!!!"), Optional.empty(),...

Full Screen

Full Screen

Source:V89Events.java Github

copy

Full Screen

1// Licensed to the Software Freedom Conservancy (SFC) under one2// or more contributor license agreements. See the NOTICE file3// distributed with this work for additional information4// regarding copyright ownership. The SFC licenses this file5// to you under the Apache License, Version 2.0 (the6// "License"); you may not use this file except in compliance7// with the License. You may obtain a copy of the License at8//9// http://www.apache.org/licenses/LICENSE-2.010//11// Unless required by applicable law or agreed to in writing,12// software distributed under the License is distributed on an13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY14// KIND, either express or implied. See the License for the15// specific language governing permissions and limitations16// under the License.17package org.openqa.selenium.devtools.v89;18import com.google.common.collect.ImmutableList;19import org.openqa.selenium.JavascriptException;20import org.openqa.selenium.devtools.Command;21import org.openqa.selenium.devtools.DevTools;22import org.openqa.selenium.devtools.Event;23import org.openqa.selenium.devtools.events.ConsoleEvent;24import org.openqa.selenium.devtools.idealized.Events;25import org.openqa.selenium.devtools.idealized.runtime.model.RemoteObject;26import org.openqa.selenium.devtools.v89.runtime.Runtime;27import org.openqa.selenium.devtools.v89.runtime.model.ConsoleAPICalled;28import org.openqa.selenium.devtools.v89.runtime.model.ExceptionDetails;29import org.openqa.selenium.devtools.v89.runtime.model.ExceptionThrown;30import org.openqa.selenium.devtools.v89.runtime.model.StackTrace;31import java.math.BigDecimal;32import java.time.Instant;33import java.util.List;34import java.util.Optional;35public class V89Events extends Events<ConsoleAPICalled, ExceptionThrown> {36 public V89Events(DevTools devtools) {37 super(devtools);38 }39 @Override40 protected Command<Void> enableRuntime() {41 return Runtime.enable();42 }43 @Override44 protected Command<Void> disableRuntime() {45 return Runtime.disable();46 }47 @Override48 protected Event<ConsoleAPICalled> consoleEvent() {49 return Runtime.consoleAPICalled();50 }51 @Override52 protected Event<ExceptionThrown> exceptionThrownEvent() {53 return Runtime.exceptionThrown();54 }55 @Override56 protected ConsoleEvent toConsoleEvent(ConsoleAPICalled event) {57 long ts = new BigDecimal(event.getTimestamp().toJson()).longValue();58 List<Object> modifiedArgs = event.getArgs().stream()59 .map(obj -> new RemoteObject(60 obj.getType().toString(),61 obj.getValue().orElse(null)))62 .collect(ImmutableList.toImmutableList());63 return new ConsoleEvent(64 event.getType().toString(),65 Instant.ofEpochMilli(ts),66 modifiedArgs);67 }68 @Override69 protected JavascriptException toJsException(ExceptionThrown event) {70 ExceptionDetails details = event.getExceptionDetails();71 Optional<StackTrace> maybeTrace = details.getStackTrace();72 Optional<org.openqa.selenium.devtools.v89.runtime.model.RemoteObject>73 maybeException = details.getException();74 String message = maybeException75 .flatMap(obj -> obj.getDescription().map(String::toString))76 .orElseGet(details::getText);77 JavascriptException exception = new JavascriptException(message);78 if (!maybeTrace.isPresent()) {79 StackTraceElement element = new StackTraceElement(80 "unknown",81 "unknown",82 details.getUrl().orElse("unknown"),83 details.getLineNumber());84 exception.setStackTrace(new StackTraceElement[]{element});85 return exception;86 }87 StackTrace trace = maybeTrace.get();88 exception.setStackTrace(trace.getCallFrames().stream()89 .map(frame -> new StackTraceElement(90 "",91 frame.getFunctionName(),92 frame.getUrl(),93 frame.getLineNumber()))94 .toArray(StackTraceElement[]::new));95 return exception;96 }97}...

Full Screen

Full Screen

Source:V88Events.java Github

copy

Full Screen

1// Licensed to the Software Freedom Conservancy (SFC) under one2// or more contributor license agreements. See the NOTICE file3// distributed with this work for additional information4// regarding copyright ownership. The SFC licenses this file5// to you under the Apache License, Version 2.0 (the6// "License"); you may not use this file except in compliance7// with the License. You may obtain a copy of the License at8//9// http://www.apache.org/licenses/LICENSE-2.010//11// Unless required by applicable law or agreed to in writing,12// software distributed under the License is distributed on an13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY14// KIND, either express or implied. See the License for the15// specific language governing permissions and limitations16// under the License.17package org.openqa.selenium.devtools.v88;18import com.google.common.collect.ImmutableList;19import org.openqa.selenium.JavascriptException;20import org.openqa.selenium.devtools.Command;21import org.openqa.selenium.devtools.DevTools;22import org.openqa.selenium.devtools.Event;23import org.openqa.selenium.devtools.events.ConsoleEvent;24import org.openqa.selenium.devtools.idealized.Events;25import org.openqa.selenium.devtools.idealized.runtime.model.RemoteObject;26import org.openqa.selenium.devtools.v88.runtime.Runtime;27import org.openqa.selenium.devtools.v88.runtime.model.ConsoleAPICalled;28import org.openqa.selenium.devtools.v88.runtime.model.ExceptionDetails;29import org.openqa.selenium.devtools.v88.runtime.model.ExceptionThrown;30import org.openqa.selenium.devtools.v88.runtime.model.StackTrace;31import java.math.BigDecimal;32import java.time.Instant;33import java.util.List;34import java.util.Optional;35public class V88Events extends Events<ConsoleAPICalled, ExceptionThrown> {36 public V88Events(DevTools devtools) {37 super(devtools);38 }39 @Override40 protected Command<Void> enableRuntime() {41 return Runtime.enable();42 }43 @Override44 protected Command<Void> disableRuntime() {45 return Runtime.disable();46 }47 @Override48 protected Event<ConsoleAPICalled> consoleEvent() {49 return Runtime.consoleAPICalled();50 }51 @Override52 protected Event<ExceptionThrown> exceptionThrownEvent() {53 return Runtime.exceptionThrown();54 }55 @Override56 protected ConsoleEvent toConsoleEvent(ConsoleAPICalled event) {57 long ts = new BigDecimal(event.getTimestamp().toJson()).longValue();58 List<Object> modifiedArgs = event.getArgs().stream()59 .map(obj -> new RemoteObject(60 obj.getType().toString(),61 obj.getValue().orElse(null)))62 .collect(ImmutableList.toImmutableList());63 return new ConsoleEvent(64 event.getType().toString(),65 Instant.ofEpochMilli(ts),66 modifiedArgs);67 }68 @Override69 protected JavascriptException toJsException(ExceptionThrown event) {70 ExceptionDetails details = event.getExceptionDetails();71 Optional<StackTrace> maybeTrace = details.getStackTrace();72 Optional<org.openqa.selenium.devtools.v88.runtime.model.RemoteObject>73 maybeException = details.getException();74 String message = maybeException75 .flatMap(obj -> obj.getDescription().map(String::toString))76 .orElseGet(details::getText);77 JavascriptException exception = new JavascriptException(message);78 if (!maybeTrace.isPresent()) {79 StackTraceElement element = new StackTraceElement(80 "unknown",81 "unknown",82 details.getUrl().orElse("unknown"),83 details.getLineNumber());84 exception.setStackTrace(new StackTraceElement[]{element});85 return exception;86 }87 StackTrace trace = maybeTrace.get();88 exception.setStackTrace(trace.getCallFrames().stream()89 .map(frame -> new StackTraceElement(90 "",91 frame.getFunctionName(),92 frame.getUrl(),93 frame.getLineNumber()))94 .toArray(StackTraceElement[]::new));95 return exception;96 }97}...

Full Screen

Full Screen

Source:V90Events.java Github

copy

Full Screen

1// Licensed to the Software Freedom Conservancy (SFC) under one2// or more contributor license agreements. See the NOTICE file3// distributed with this work for additional information4// regarding copyright ownership. The SFC licenses this file5// to you under the Apache License, Version 2.0 (the6// "License"); you may not use this file except in compliance7// with the License. You may obtain a copy of the License at8//9// http://www.apache.org/licenses/LICENSE-2.010//11// Unless required by applicable law or agreed to in writing,12// software distributed under the License is distributed on an13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY14// KIND, either express or implied. See the License for the15// specific language governing permissions and limitations16// under the License.17package org.openqa.selenium.devtools.v90;18import com.google.common.collect.ImmutableList;19import org.openqa.selenium.JavascriptException;20import org.openqa.selenium.devtools.Command;21import org.openqa.selenium.devtools.DevTools;22import org.openqa.selenium.devtools.Event;23import org.openqa.selenium.devtools.events.ConsoleEvent;24import org.openqa.selenium.devtools.idealized.Events;25import org.openqa.selenium.devtools.idealized.runtime.model.RemoteObject;26import org.openqa.selenium.devtools.v90.runtime.Runtime;27import org.openqa.selenium.devtools.v90.runtime.model.ConsoleAPICalled;28import org.openqa.selenium.devtools.v90.runtime.model.ExceptionDetails;29import org.openqa.selenium.devtools.v90.runtime.model.ExceptionThrown;30import org.openqa.selenium.devtools.v90.runtime.model.StackTrace;31import java.math.BigDecimal;32import java.time.Instant;33import java.util.List;34import java.util.Optional;35public class V90Events extends Events<ConsoleAPICalled, ExceptionThrown> {36 public V90Events(DevTools devtools) {37 super(devtools);38 }39 @Override40 protected Command<Void> enableRuntime() {41 return Runtime.enable();42 }43 @Override44 protected Command<Void> disableRuntime() {45 return Runtime.disable();46 }47 @Override48 protected Event<ConsoleAPICalled> consoleEvent() {49 return Runtime.consoleAPICalled();50 }51 @Override52 protected Event<ExceptionThrown> exceptionThrownEvent() {53 return Runtime.exceptionThrown();54 }55 @Override56 protected ConsoleEvent toConsoleEvent(ConsoleAPICalled event) {57 long ts = new BigDecimal(event.getTimestamp().toJson()).longValue();58 List<Object> modifiedArgs = event.getArgs().stream()59 .map(obj -> new RemoteObject(60 obj.getType().toString(),61 obj.getValue().orElse(null)))62 .collect(ImmutableList.toImmutableList());63 return new ConsoleEvent(64 event.getType().toString(),65 Instant.ofEpochMilli(ts),66 modifiedArgs);67 }68 @Override69 protected JavascriptException toJsException(ExceptionThrown event) {70 ExceptionDetails details = event.getExceptionDetails();71 Optional<StackTrace> maybeTrace = details.getStackTrace();72 Optional<org.openqa.selenium.devtools.v90.runtime.model.RemoteObject>73 maybeException = details.getException();74 String message = maybeException75 .flatMap(obj -> obj.getDescription().map(String::toString))76 .orElseGet(details::getText);77 JavascriptException exception = new JavascriptException(message);78 if (!maybeTrace.isPresent()) {79 StackTraceElement element = new StackTraceElement(80 "unknown",81 "unknown",82 details.getUrl().orElse("unknown"),83 details.getLineNumber());84 exception.setStackTrace(new StackTraceElement[]{element});85 return exception;86 }87 StackTrace trace = maybeTrace.get();88 exception.setStackTrace(trace.getCallFrames().stream()89 .map(frame -> new StackTraceElement(90 "",91 frame.getFunctionName(),92 frame.getUrl(),93 frame.getLineNumber()))94 .toArray(StackTraceElement[]::new));95 return exception;96 }97}...

Full Screen

Full Screen

Message

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.devtools.v91.browser.Browser;2import org.openqa.selenium.devtools.v91.browser.model.Message;3import org.openqa.selenium.devtools.v91.browser.model.MessageSource;4import org.openqa.selenium.devtools.v91.browser.model.MessageLevel;5import org.openqa.selenium.devtools.v91.browser.model.MessageType;6import org.openqa.selenium.devtools.v91.browser.model.MessageRepeatCount;7import org.openqa.selenium.devtools.v91.browser.model.MessageLocation;8import org.openqa.selenium.devtools.v91.browser.model.MessageArgument;9import org.openqa.selenium.devtools.v91.browser.model.MessageStack;10import org.openqa.selenium.devtools.v91.browser.model.MessageParam;11import org.openqa.selenium.devtools.v91.browser.model.MessageParamType;12import org.openqa.selenium.devtools.v91.browser.model.MessageParamValue;13import org.openqa.selenium.devtools.v91.browser.model.MessageParamValueType;14import org.openqa.selenium.devtools.v91.browser.model.MessageParamValueSubtype;15import org.openqa.selenium.devtools.v91.browser.model.MessageParamValuePreview;16import org.openqa.selenium.devtools.v91.browser.model.MessageParamValuePreviewType;17import org.openqa.selenium.devtools.v91.browser.model.MessageParamValuePreviewSubtype;18import org.openqa.selenium.devtools.v91.browser.model.MessageParamValuePreviewValue;19import org.openqa.selenium.devtools.v91.browser.model.MessageParamValuePreviewValueSubtype;20import org.openqa.selenium.devtools.v91.browser.model.MessageParamValuePreviewValueDescription;21import org.openqa.selenium.devtools.v91.browser.model.MessageParamValuePreviewValueDescriptionSubtype;22import org.openqa.selenium.devtools.v91.browser.model.MessageParamValuePreviewValueDescriptionOverflow;23import org.openqa.selenium.devtools.v91.browser.model.MessageParamValuePreviewValueDescriptionOverflowSubtype;24import org.openqa.selenium.devtools.v91.browser.model.MessageParamValuePreviewValueDescriptionOverflowType;25import org.openqa.selenium.devtools.v91.browser.model.MessageParamValuePreviewValueDescriptionOverflowTypeSubtype;26import org.openqa.selenium.devtools.v91.browser.model.MessageParamValuePreviewValueDescriptionOverflowTypeSubtypeValue;27import org.openqa.selenium.devtools.v91.browser.model.MessageParamValuePreviewValueDescriptionOverflowTypeSubtypeValueSubtype;28import org.openqa.selenium.devtools.v91.browser.model.MessageParamValuePreviewValueDescriptionOverflowTypeSubtypeValueSubtypeValue;29import org.openqa.selenium.devtools.v91.browser.model.MessageParamValuePreviewValueDescriptionOverflowTypeSubtypeValueSubtypeValueSubtype;30import org.openqa.selenium.devtools.v91.browser.model.MessageParamValuePreviewValueDescriptionOverflow

Full Screen

Full Screen

Message

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.devtools.v91.browser.Browser;2import org.openqa.selenium.devtools.v91.browser.model.Message;3import org.openqa.selenium.devtools.v91.browser.model.MessageLevel;4import org.openqa.selenium.devtools.v91.browser.model.MessageSource;5import org.openqa.selenium.devtools.v91.browser.model.MessageType;6import org.openqa.selenium.devtools.v91.browser.model.MessageLevel;7import org.openqa.selenium.devtools.v91.browser.model.MessageSource;8import org.openqa.selenium.devtools.v91.browser.model.MessageType;9import org.openqa.selenium.devtools.v91.browser.model.MessageLevel;10import org.openqa.selenium.devtools.v91.browser.model.MessageSource;11import org.openqa.selenium.devtools.v91.browser.model.MessageType;12import org.openqa.selenium.devtools.v91.browser.model.MessageLevel;13import org.openqa.selenium.devtools.v91.browser.model.MessageSource;14import org.openqa.selenium.devtools.v91.browser.model.MessageType;15import org.openqa.selenium.devtools.v91.browser.model.MessageLevel;16import org.openqa.selenium.devtools.v91.browser.model.MessageSource;17import org.openqa.selenium.devtools.v91.browser.model.MessageType;18import org.openqa.selenium.devtools.v91.browser.model.MessageLevel;19import org.openqa.selenium.devtools.v91.browser.model.MessageSource;20import org.openqa.selenium.devtools.v91.browser.model.MessageType;21import org.openqa.selenium.devtools.v91.browser.model.MessageLevel;22import org.openqa.selenium.devtools.v91.browser.model.MessageSource;23import org.openqa.selenium.devtools.v91.browser.model.MessageType;24import org.openqa.selenium.devtools.v91.browser.model.MessageLevel;25import org.openqa.selenium.devtools.v91.browser.model.MessageSource;26import org.openqa.selenium.devtools.v91.browser.model.MessageType;27import org.openqa.selenium.devtools.v91.browser.model.MessageLevel;28import org.openqa.selenium.devtools.v91.browser.model.MessageSource;29import org.openqa.selenium.devtools.v91.browser.model.MessageType;30import org.openqa.selenium.devtools.v91.browser.model.MessageLevel;31import org.openqa.selenium.devtools.v91.browser.model.MessageSource;32import org.openqa.selenium.devtools.v91.browser.model.MessageType;33import org.openqa.selenium.devtools.v91.browser.model.MessageLevel;34import org.openqa.selenium.devtools.v91.browser.model.MessageSource;35import org.openqa.selenium.devtools.v91.browser.model.MessageType;36import org.openqa.selenium.devtools.v91.browser.model.MessageLevel;37import org.openqa.selenium.devtools.v91.browser.model.MessageSource;38import org.openqa.selenium.devtools.v91.browser.model.MessageType;39import org.openqa.selenium.devtools

Full Screen

Full Screen

Message

Using AI Code Generation

copy

Full Screen

1The DevTools API is accessed via a `DevToolsSession`. This is created by calling `openDevToolsSession()` on a `WebDriver` instance. The DevTools API is then accessed by sending messages to the browser and receiving responses. For example:2 import org.openqa.selenium.devtools.DevTools;3 import org.openqa.selenium.devtools.v85.page.Page;4 import org.openqa.selenium.devtools.v85.page.model.FrameId;5 import org.openqa.selenium.devtools.v85.page.model.FrameNavigated;6 import org.openqa.selenium.devtools.v85.page.model.FrameStartedLoading;7 import org.openqa.selenium.devtools.v85.page.model.FrameStoppedLoading;8 import org.openqa.selenium.devtools.v85.page.model.ScreencastFrame;9 import org.openqa.selenium.devtools.v85.page.model.Viewport;10 import org.openqa.selenium.devtools.v85.runtime.Runtime;11 import org.openqa.selenium.devtools.v85.runtime.model.ConsoleAPICalled;12 import org.openqa.selenium.devtools.v85.runtime.model.ConsoleAPICalledType;13 import org.openqa.selenium.devtools.v85.runtime.model.RemoteObject;14 import org.openqa.selenium.devtools.v85.runtime.model.ScriptId;15 import org.openqa.selenium.devtools.v85.runtime.model.StackTrace;16 import org.openqa.selenium.devtools.v85.runtime.model.StackTraceId;17 import org.openqa.selenium.devtools.v85.runtime.model.Timestamp;18 import org.openqa.selenium.devtools.v85.security.Security;19 import org.openqa.selenium.devtools.v85.security.model.SecurityStateChanged;20 import org.openqa.selenium.devtools.v85.security.model.SecurityStateExplanation;21 import org.openqa.selenium.devtools.v85.security.model.SecurityState;22 import org.openqa.selenium.devtools.v85.security.model.MixedContentType;23 import org.openqa.selenium.devtools.v85.security.model.SecurityState

Full Screen

Full Screen

Message

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.devtools.DevTools;2import org.openqa.selenium.devtools.v89.log.Log;3import org.openqa.selenium.devtools.v89.log.model.LogEntry;4import org.openqa.selenium.devtools.v89.log.model.LogEntryAdded;5import org.openqa.selenium.devtools.v89.log.model.LogEntrySource;6import org.openqa.selenium.devtools.v89.network.Network;7import org.openqa.selenium.devtools.v89.network.model.ConnectionType;8import org.openqa.selenium.devtools.v89.network.model.Request;9import org.openqa.selenium.devtools.v89.network.model.Response;10import org.openqa.selenium.devtools.v89.page.Page;11import org.openqa.selenium.devtools.v89.page.model.FrameId;12import org.openqa.selenium.devtools.v89.page.model.FrameNavigated;13import org.openqa.selenium.devtools.v89.page.model.InterstitialShown;14import org.openqa.selenium.devtools.v89.page.model.ScreencastFrame;15import org.openqa.selenium.devtools.v89.page.model.Viewport;16import org.openqa.selenium.devtools.v89.runtime.Runtime;17import org.openqa.selenium.devtools.v89.runtime.model.ConsoleAPICalled;18import org.openqa.selenium.devtools.v89.runtime.model.ConsoleAPICalledType;19import org.openqa.selenium.devtools.v89.runtime.model.RemoteObject;20import org.openqa.selenium.devtools.v89.runtime.model.RemoteObjectSubtype;21import org.openqa.selenium.devtools.v89.runtime.model.RemoteObjectType;22import org.openqa.selenium.devtools.v89.security.Security;23import org.openqa.selenium.devtools.v89.security.model.SecurityStateChanged;24import org.openqa.selenium.devtools.v89.security.model.SecurityStateExplanation;25import org.openqa.selenium.devtools.v89.security.model.SecurityState;26import org.openqa.selenium.devtools.v89.security.model.SecurityStateIssueId;27import org.openqa.selenium.devtools.v89.security.model.MixedContentType;28import org.openqa.selenium.devtools.v89.security.model.CertificateErrorAction;29import org.openqa.selenium.devtools.v89.security.model.CertificateError;30import org.openqa.selenium.devtools.v89.security.model.CertificateSecurityState;31import org.openqa.selenium.devtools.v89.security.model.CertificateId;32import org.openqa.selenium.devtools.v89.security.model.Certificate;33import org.openqa.selenium.devtools.v89.security

Full Screen

Full Screen
copy
1String data = "004-034556";2String[] output = data.split("-");3System.out.println(output[0]);4System.out.println(output[1]);5
Full Screen
copy
1String s = "TnGeneral|DOMESTIC";2String a[]=s.split("\\|");3System.out.println(a.toString());4System.out.println(a[0]);5System.out.println(a[1]);6
Full Screen
copy
1String s="004-034556";2for(int i=0;i<s.length();i++)3{4 if(s.charAt(i)=='-')5 {6 System.out.println(s.substring(0,i));7 System.out.println(s.substring(i+1));8 }9}10
Full Screen

Selenium 4 Tutorial:

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.

Chapters:

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. 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.

  7. 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.

Selenium 101 certifications:

LambdaTest also provides certification for Selenium testing to accelerate your career in Selenium automation testing.

Run Selenium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in Message

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful