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

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

Source:MainPageTest.java Github

copy

Full Screen

...4import com.codeborne.selenide.WebDriverRunner;5import org.junit.jupiter.api.*;6import org.openqa.selenium.Capabilities;7import org.openqa.selenium.chrome.ChromeDriver;8import org.openqa.selenium.devtools.CdpInfo;9import org.openqa.selenium.devtools.CdpVersionFinder;10import org.openqa.selenium.devtools.Connection;11import org.openqa.selenium.devtools.DevTools;12import org.openqa.selenium.devtools.noop.NoOpCdpInfo;13import org.openqa.selenium.devtools.v91.fetch.Fetch;14import org.openqa.selenium.devtools.v91.fetch.model.HeaderEntry;15import org.openqa.selenium.devtools.v91.network.Network;16import org.openqa.selenium.devtools.v91.network.model.AuthChallengeResponse;17import org.openqa.selenium.devtools.v91.network.model.Request;18import org.openqa.selenium.devtools.v91.network.model.RequestId;19import org.openqa.selenium.devtools.v91.network.model.RequestWillBeSent;20import org.openqa.selenium.devtools.v91.performance.Performance;21import org.openqa.selenium.devtools.v91.performance.model.Metric;22import org.openqa.selenium.remote.RemoteWebDriver;23import org.openqa.selenium.remote.http.ClientConfig;24import org.openqa.selenium.remote.http.HttpClient;25import java.net.MalformedURLException;26import java.net.URI;27import java.net.URISyntaxException;28import java.net.URL;29import java.util.ArrayList;30import java.util.Base64;31import java.util.List;32import java.util.Map;33import java.util.Optional;34import java.util.concurrent.ConcurrentHashMap;35import java.util.concurrent.TimeUnit;36import static java.util.Optional.empty;37import static org.awaitility.Awaitility.await;38import static org.junit.jupiter.api.Assertions.*;39import static com.codeborne.selenide.Condition.attribute;40import static com.codeborne.selenide.Selenide.*;41public class MainPageTest {42 @BeforeAll43 public static void setUpAll() {44 Configuration.browserSize = "1280x800";45 }46 @Test47 public void metricsTest() {48 DevTools devTools = getLocalDevTools();49 devTools.send(Performance.enable(empty()));50 open("https://www.jetbrains.com/");51 List<Metric> send = devTools.send(Performance.getMetrics());52 assertTrue(send.size() > 0);53 send.forEach(it -> System.out.printf("%s: %s%n", it.getName(), it.getValue()));54 }55 @Test56 public void getResponseTest() {57 DevTools devTools = getLocalDevTools();58 devTools.send(Network.enable(empty(), empty(), empty()));59 final List<RequestWillBeSent> requests = new ArrayList<>();60 final List<String> responses = new ArrayList<>();61 devTools.addListener(Network.requestWillBeSent(), req -> {62 if (req.getRequest().getUrl().contains("proxy/services/credit-application/async/api/external/v1/request/parameters")) {63 requests.add(req);64 }65 });66 devTools.addListener(Network.responseReceived(),67 entry -> {68 if (requests.size() == 0) {69 return;70 }71 RequestWillBeSent request = requests.get(0);72 if (request != null && entry.getRequestId().toString().equals(request.getRequestId().toString())) {73 Network.GetResponseBodyResponse send = devTools.send(Network.getResponseBody(request.getRequestId()));74 responses.add(send.getBody());75 }76 });77 open("https://www.sberbank.ru/ru/person/credits/money/consumer_unsecured/zayavka");78 await().pollThread(Thread::new)79 .atMost(10, TimeUnit.SECONDS)80 .until(() -> responses.size() == 1);81 System.out.println(responses.get(0));82 }83 @Test84 public void interceptRequestTest() {85 DevTools devTools = getLocalDevTools();86 devTools.send(Fetch.enable(empty(), empty()));87 String content = "[{\"title\":\"Todo 1\",\"order\":null,\"completed\":false},{\"title\":\"Todo 2\",\"order\":null,\"completed\":true}]";88 devTools.addListener(Fetch.requestPaused(), request -> {89 String url = request.getRequest().getUrl();90 String query = getUrl(url);91 if (url.contains("/todos/") && query == null) {92 List<HeaderEntry> corsHeaders = new ArrayList<>();93 corsHeaders.add(new HeaderEntry("Access-Control-Allow-Origin", "*"));94 corsHeaders.add(new HeaderEntry("Access-Control-Allow-Methods", "GET, POST, OPTIONS, DELETE"));95 devTools.send(Fetch.fulfillRequest(96 request.getRequestId(),97 200,98 Optional.of(corsHeaders),99 Optional.empty(),100 Optional.of(Base64.getEncoder().encodeToString(content.getBytes())),101 Optional.of("OK"))102 );103 } else {104 devTools.send(Fetch.continueRequest(105 request.getRequestId(),106 Optional.of(url),107 Optional.of(request.getRequest().getMethod()),108 request.getRequest().getPostData(),109 request.getResponseHeaders()));110 }111 });112 open("https://todobackend.com/client/index.html?https://todo-backend-spring4-java8.herokuapp.com/todos/");113 $$("#todo-list li").shouldHave(CollectionCondition.size(2));114 $$("#todo-list label").shouldHave(CollectionCondition.texts("Todo 1", "Todo 2"));115 }116 private String getUrl(String url) {117 try {118 return new URL(url).getQuery();119 } catch (MalformedURLException e) {120 throw new RuntimeException(e.getMessage(), e);121 }122 }123 private DevTools getLocalDevTools() {124 open();125 ChromeDriver driver = (ChromeDriver) WebDriverRunner.getWebDriver();126 DevTools devTools = driver.getDevTools();127 devTools.createSession();128 return devTools;129 }130 @Test131 public void devtoolsWithSelenoid() throws URISyntaxException {132 Configuration.remote = "http://localhost:4444/wd/hub";133 open();134 RemoteWebDriver webDriver = (RemoteWebDriver) WebDriverRunner.getWebDriver();135 Capabilities capabilities = webDriver.getCapabilities();136 CdpInfo cdpInfo = new CdpVersionFinder()137 .match(capabilities.getBrowserVersion())138 .orElseGet(NoOpCdpInfo::new);139 HttpClient.Factory factory = HttpClient.Factory.createDefault();140 URI uri = new URI(String.format("ws://localhost:4444/devtools/%s", webDriver.getSessionId()));141 Connection connection = new Connection(142 factory.createClient(ClientConfig.defaultConfig().baseUri(uri)),143 uri.toString());144 DevTools devTools = new DevTools(cdpInfo::getDomains, connection);145 devTools.createSession();146 devTools.send(Performance.enable(empty()));147 open("https://www.jetbrains.com/");148 List<Metric> send = devTools.send(Performance.getMetrics());149 assertTrue(send.size() > 0);150 send.forEach(it -> System.out.printf("%s: %s%n", it.getName(), it.getValue()));151 }152}...

Full Screen

Full Screen

Source:DevtoolsUtils.java Github

copy

Full Screen

1package ch.qarts.tattool.webplatform.util;2import lombok.SneakyThrows;3import org.openqa.selenium.Capabilities;4import org.openqa.selenium.devtools.CdpVersionFinder;5import org.openqa.selenium.devtools.DevTools;6import org.openqa.selenium.devtools.SeleniumCdpConnection;7import org.openqa.selenium.remote.DesiredCapabilities;8import org.openqa.selenium.remote.RemoteWebDriver;9import java.net.URL;10import java.util.Map;11import java.util.function.Supplier;12public class DevtoolsUtils {13 @SneakyThrows14 public static DevTools getDevtools(RemoteWebDriver driver, URL url) {15 // TODO remove when there is a viable / documented option from selenium16 Supplier<Capabilities> fixCdp = () -> {17 Capabilities other = new DesiredCapabilities();18 var seCdp = (String) driver.getCapabilities().getCapability("se:cdp");19 var sessionPos = seCdp.indexOf("/session");20 var seCdpFixed = String.format("ws://%s:%s%s", url.getHost(), url.getPort(), seCdp.substring(sessionPos));21 return driver.getCapabilities().merge(new DesiredCapabilities(Map.of("se:cdp", seCdpFixed)));22 };23 var cdpInfo = new CdpVersionFinder().match(driver.getCapabilities().getBrowserVersion()).orElseThrow(IllegalAccessException::new);24 return new DevTools(cdpInfo::getDomains, SeleniumCdpConnection.create(fixCdp.get()).orElseThrow(IllegalAccessException::new));25 }26 @SneakyThrows27 public static DevTools getDevtools(RemoteWebDriver driver) {28 var cdpInfo = new CdpVersionFinder().match(driver.getCapabilities().getBrowserVersion()).orElseThrow(IllegalStateException::new);29 return new DevTools(cdpInfo::getDomains, SeleniumCdpConnection.create(driver).orElseThrow(IllegalAccessException::new));30 }31}...

Full Screen

Full Screen

Source:V86CdpInfo.java Github

copy

Full Screen

...15// specific language governing permissions and limitations16// under the License.17package org.openqa.selenium.devtools.v86;18import com.google.auto.service.AutoService;19import org.openqa.selenium.devtools.CdpInfo;20@AutoService(CdpInfo.class)21public class V86CdpInfo extends CdpInfo {22 public V86CdpInfo() {23 super(86, V86Domains::new);24 }25}...

Full Screen

Full Screen

Source:V85CdpInfo.java Github

copy

Full Screen

...15// specific language governing permissions and limitations16// under the License.17package org.openqa.selenium.devtools.v85;18import com.google.auto.service.AutoService;19import org.openqa.selenium.devtools.CdpInfo;20@AutoService(CdpInfo.class)21public class V85CdpInfo extends CdpInfo {22 public V85CdpInfo() {23 super(85, V85Domains::new);24 }25}...

Full Screen

Full Screen

Source:V84CdpInfo.java Github

copy

Full Screen

...15// specific language governing permissions and limitations16// under the License.17package org.openqa.selenium.devtools.v84;18import com.google.auto.service.AutoService;19import org.openqa.selenium.devtools.CdpInfo;20@AutoService(CdpInfo.class)21public class V84CdpInfo extends CdpInfo {22 public V84CdpInfo() {23 super(84, V84Domains::new);24 }25}...

Full Screen

Full Screen

Source:V89CdpInfo.java Github

copy

Full Screen

...15// specific language governing permissions and limitations16// under the License.17package org.openqa.selenium.devtools.v89;18import com.google.auto.service.AutoService;19import org.openqa.selenium.devtools.CdpInfo;20@AutoService(CdpInfo.class)21public class V89CdpInfo extends CdpInfo {22 public V89CdpInfo() {23 super(89, V89Domains::new);24 }25}...

Full Screen

Full Screen

Source:V91CdpInfo.java Github

copy

Full Screen

...15// specific language governing permissions and limitations16// under the License.17package org.openqa.selenium.devtools.v91;18import com.google.auto.service.AutoService;19import org.openqa.selenium.devtools.CdpInfo;20@AutoService(CdpInfo.class)21public class V91CdpInfo extends CdpInfo {22 public V91CdpInfo() {23 super(91, V91Domains::new);24 }25}...

Full Screen

Full Screen

Source:V88CdpInfo.java Github

copy

Full Screen

...15// specific language governing permissions and limitations16// under the License.17package org.openqa.selenium.devtools.v88;18import com.google.auto.service.AutoService;19import org.openqa.selenium.devtools.CdpInfo;20@AutoService(CdpInfo.class)21public class V88CdpInfo extends CdpInfo {22 public V88CdpInfo() {23 super(88, V88Domains::new);24 }25}...

Full Screen

Full Screen

CdpInfo

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.devtools.DevTools;2import org.openqa.selenium.devtools.v91.network.Network;3import org.openqa.selenium.devtools.v91.network.model.CdpInfo;4import org.openqa.selenium.devtools.v91.network.model.ConnectionType;5import org.openqa.selenium.devtools.v91.network.model.Initiator;6import org.openqa.selenium.devtools.v91.network.model.Request;7import org.openqa.selenium.devtools.v91.network.model.ResourceType;8import org.openqa.selenium.devtools.v91.network.model.Response;9import org.openqa.selenium.devtools.v91.network.model.SignedExchangeInfo;10import org.openqa.selenium.devtools.v91.network.model.Timestamp;11import org.openqa.selenium.devtools.v91.network.model.WallTime;12public class NetworkEvents {13 public static void main(String[] args) {14 WebDriver driver = new ChromeDriver();15 DevTools devTools = ((ChromeDriver) driver).getDevTools();16 devTools.createSession();17 devTools.send(Network.enable(Optional.empty(), Optional.empty(), Optional.empty()));18 devTools.addListener(Network.requestWillBeSent(), request -> {19 System.out.println(request.getRequestId());20 System.out.println(request.getLoaderId());21 System.out.println(request.getDocumentURL());22 System.out.println(request.getRequest().getUrl());23 System.out.println(request.getRequest().getMethod());24 System.out.println(request.getRequest().getHeaders());25 System.out.println(request.getRequest().getInitialPriority());26 System.out.println(request.getRequest().getReferrerPolicy());27 System.out.println(request.getTimestamp());28 System.out.println(request.getWallTime());29 System.out.println(request.getInitiator().getType());30 System.out.println(request.getInitiator().getStack().getCallFrames());31 System.out.println(request.getRedirectResponse());32 System.out.println(request.getType());33 System.out.println(request.getFrameId());34 System.out.println(request.hasUserGesture());35 });36 devTools.addListener(Network.requestServedFromCache(), requestServedFromCache -> {37 System.out.println(requestServedFromCache.getRequestId());38 });39 devTools.addListener(Network.responseReceived(), responseReceived -> {40 System.out.println(responseReceived.getRequestId());41 System.out.println(responseReceived.getLoaderId());42 System.out.println(responseReceived.getTimestamp());43 System.out.println(responseReceived.getType());44 System.out.println(responseReceived.getResponse().getUrl());45 System.out.println(responseReceived.getResponse().getStatus());46 System.out.println(responseReceived.getResponse().getStatusText());47 System.out.println(responseReceived.getResponse().getHeaders());48 System.out.println(responseReceived.getResponse().get

Full Screen

Full Screen

CdpInfo

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.devtools.DevTools;2import org.openqa.selenium.devtools.v92.cdp.CdpInfo;3import org.openqa.selenium.devtools.v92.cdp.CdpInfo.Version;4import org.openqa.selenium.devtools.v92.cdp.CdpInfo.VersionInfo;5import org.openqa.selenium.devtools.v92.cdp.CdpInfo.VersionInfo.VersionInfoBuilder;6import org.openqa.selenium.devtools.v92.cdp.CdpInfo.VersionInfo.VersionInfoBuilder.VersionInfoBuilderImpl;7import org.openqa.selenium.devtools.v92.cdp.CdpInfo.VersionInfo.VersionInfoImpl;8import org.openqa.selenium.devtools.v92.cdp.CdpInfo.VersionInfo.VersionInfoImpl.VersionInfoImplBuilder;9import org.openqa.selenium.devtools.v92.cdp.CdpInfo.VersionInfo.VersionInfoImpl.VersionInfoImplBuilderImpl;10import org.openqa.selenium.devtools.v92.cdp.CdpInfo.VersionInfo.VersionInfoImpl.VersionInfoImplImpl;11import org.openqa.selenium.devtools.v92.cdp.CdpInfo.VersionInfo.VersionInfoImpl.VersionInfoImplImpl.VersionInfoImplImplBuilder;12import org.openqa.selenium.devtools.v92.cdp.CdpInfo.VersionInfo.VersionInfoImpl.VersionInfoImplImpl.VersionInfoImplImplBuilderImpl;13import org.openqa.selenium.devtools.v92.cdp.CdpInfo.VersionInfo.VersionInfoImpl.VersionInfoImplImpl.VersionInfoImplImplImpl;14import org.openqa.selenium.devtools.v92.cdp.CdpInfo.VersionInfo.VersionInfoImpl.VersionInfoImplImpl.VersionInfoImplImplImpl.VersionInfoImplImplImplBuilder;15import org.openqa.selenium.devtools.v92.cdp.CdpInfo.VersionInfo.VersionInfoImpl.VersionInfoImplImpl.VersionInfoImplImplImpl.VersionInfoImplImplImplBuilderImpl;16import org.openqa.selenium.devtools.v92.cdp.CdpInfo.VersionInfo.VersionInfoImpl.VersionInfoImplImpl.VersionInfoImplImplImpl.VersionInfoImplImplImplImpl;17import org.openqa.selenium.devtools.v92.cdp.CdpInfo.VersionInfo.VersionInfoImpl.VersionInfoImplImpl.VersionInfoImplImplImpl.VersionInfoImplImplImplImpl.VersionInfoImplImplImplImplBuilder;18import org.openqa.selenium.devtools.v92.cdp.CdpInfo.VersionInfo.VersionInfoImpl.VersionInfoImplImpl.VersionInfoImplImplImpl.VersionInfoImplImplImplImpl.VersionInfoImplImplImplImplBuilderImpl;19import org.openqa.selenium.devtools.v92.cdp.CdpInfo.VersionInfo.VersionInfoImpl.VersionInfoImplImpl.VersionInfoImplImplImpl.VersionInfoImplImplImplImpl.VersionInfoImplImplImplImplImpl;20import

Full Screen

Full Screen

CdpInfo

Using AI Code Generation

copy

Full Screen

1ChromeDriver driver = new ChromeDriver(); 2ChromeDevTools devTools = driver.getDevTools();3CdpInfo cdpInfo = new CdpInfo();4cdpInfo.setDomain("Network");5cdpInfo.setCommand("requestWillBeSent");6cdpInfo.setParams("requestId", "requestId");7cdpInfo.setEvent("responseReceived");8cdpInfo.setParams("requestId", "requestId");9devTools.addCdpInfo(cdpInfo);10devTools.send(Network.enable());11devTools.send(Network.disable());12driver.quit();

Full Screen

Full Screen

CdpInfo

Using AI Code Generation

copy

Full Screen

1System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");2ChromeOptions options = new ChromeOptions();3options.setExperimentalOption("debuggerAddress", "localhost:9222");4WebDriver driver = new ChromeDriver(options);5CdpInfo cdpInfo = ((ChromeDriver)driver).getDevTools().getInfo();6System.out.println(cdpInfo.getBrowserVersion());

Full Screen

Full Screen

CdpInfo

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.devtools.DevTools;2import org.openqa.selenium.devtools.v91.browser.Browser;3import org.openqa.selenium.devtools.v91.browser.model.CdpInfo;4import org.openqa.selenium.devtools.v91.browser.model.GetBrowserCommandLine;5import org.openqa.selenium.devtools.v91.browser.model.GetVersionResponse;6import org.openqa.selenium.devtools.v91.browser.model.GetWindowBoundsResponse;7import org.openqa.selenium.devtools.v91.browser.model.SetWindowBounds;8import org.openqa.selenium.devtools.v91.browser.model.WindowState;9import org.openqa.selenium.devtools.v91.emulation.Emulation;10import org.openqa.selenium.devtools.v91.emulation.model.ScreenOrientation;11import org.openqa.selenium.devtools.v91.emulation.model.VirtualTimePolicy;12import org.openqa.selenium.devtools.v91.fetch.Fetch;13import org.openqa.selenium.devtools.v91.fetch.model.AuthChallengeResponseResponse;14import org.openqa.selenium.devtools.v91.fetch.model.RequestPaused;15import org.openqa.selenium.devtools.v91.fetch.model.RequestPattern;16import org.openqa.selenium.devtools.v91.network.Network;17import org.openqa.selenium.devtools.v91.network.model.Headers;18import org.openqa.selenium.devtools.v91.network.model.Request;19import org.openqa.selenium.devtools.v91.network.model.Response;20import org.openqa.selenium.devtools.v91.page.Page;21import org.openqa.selenium.devtools.v91.page.model.Viewport;22import org.openqa.selenium.devtools.v91.runtime.Runtime;23import org.openqa.selenium.devtools.v91.runtime.model.ConsoleAPICalled;24import org.openqa.selenium.devtools.v91.runtime.model.RemoteObject;25import org.openqa.selenium.devtools.v91.storage.Storage;26import org.openqa.selenium.devtools.v91.storage.model.CacheStorageContentUpdated;27import org.openqa.selenium.devtools.v91.storage.model.CacheStorageDataEntry;28import org.openqa.selenium.devtools.v91.storage.model.CacheStorageListUpdated;29import org.openqa.selenium.devtools.v91.storage.model.CacheStorageResponse;30import org.openqa.selenium.devtools.v91.storage.model.CacheStorageUpdated;31import org.openqa.selenium.devtools.v91.storage.model.Cookie;32import org.openqa.selenium.devtools.v91.storage.model.CookieParam;33import org.openqa.selenium.devtools.v91.storage.model.Storage

Full Screen

Full Screen
copy
1String value=""1000000.00""2DecimalFormat myFormatter = new DecimalFormat("###,###.##");3String output = myFormatter.format(value);4WebElement webElement= driver.findElement(By.ById("req8input"));5webElement.sendKeys("100);6assertEquals(output, webElement.getAttribute("value"));7
Full Screen
copy
1WebElement el = driver.findElement(By.id("req8input"));2
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 CdpInfo

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