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

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

Source:FirefoxDriver.java Github

copy

Full Screen

...26import org.openqa.selenium.Proxy;27import org.openqa.selenium.WebDriverException;28import org.openqa.selenium.devtools.CdpEndpointFinder;29import org.openqa.selenium.devtools.CdpInfo;30import org.openqa.selenium.devtools.CdpVersionFinder;31import org.openqa.selenium.devtools.Connection;32import org.openqa.selenium.devtools.DevTools;33import org.openqa.selenium.devtools.DevToolsException;34import org.openqa.selenium.devtools.HasDevTools;35import org.openqa.selenium.devtools.noop.NoOpCdpInfo;36import org.openqa.selenium.html5.LocalStorage;37import org.openqa.selenium.html5.SessionStorage;38import org.openqa.selenium.html5.WebStorage;39import org.openqa.selenium.internal.Require;40import org.openqa.selenium.remote.CommandInfo;41import org.openqa.selenium.remote.FileDetector;42import org.openqa.selenium.remote.RemoteWebDriver;43import org.openqa.selenium.remote.Response;44import org.openqa.selenium.remote.html5.RemoteWebStorage;45import org.openqa.selenium.remote.http.ClientConfig;46import org.openqa.selenium.remote.http.HttpClient;47import org.openqa.selenium.remote.http.HttpMethod;48import org.openqa.selenium.remote.service.DriverCommandExecutor;49import org.openqa.selenium.remote.service.DriverService;50import java.net.URI;51import java.nio.file.Path;52import java.util.Optional;53import java.util.ServiceLoader;54import java.util.Set;55import java.util.stream.StreamSupport;56import static java.nio.charset.StandardCharsets.UTF_8;57import static java.util.Collections.singletonMap;58import static org.openqa.selenium.remote.CapabilityType.PROXY;59/**60 * An implementation of the {#link WebDriver} interface that drives Firefox.61 * <p>62 * The best way to construct a {@code FirefoxDriver} with various options is to make use of the63 * {@link FirefoxOptions}, like so:64 *65 * <pre>66 * FirefoxOptions options = new FirefoxOptions()67 * .addPreference("browser.startup.page", 1)68 * .addPreference("browser.startup.homepage", "https://www.google.co.uk")69 * .setAcceptInsecureCerts(true)70 * .setHeadless(true);71 * WebDriver driver = new FirefoxDriver(options);72 * </pre>73 */74public class FirefoxDriver extends RemoteWebDriver75 implements WebStorage, HasExtensions, HasDevTools {76 public static final class SystemProperty {77 /**78 * System property that defines the location of the Firefox executable file.79 */80 public static final String BROWSER_BINARY = "webdriver.firefox.bin";81 /**82 * System property that defines the location of the file where Firefox log should be stored.83 */84 public static final String BROWSER_LOGFILE = "webdriver.firefox.logfile";85 /**86 * System property that defines the additional library path (Linux only).87 */88 public static final String BROWSER_LIBRARY_PATH = "webdriver.firefox.library.path";89 /**90 * System property that defines the profile that should be used as a template.91 * When the driver starts, it will make a copy of the profile it is using,92 * rather than using that profile directly.93 */94 public static final String BROWSER_PROFILE = "webdriver.firefox.profile";95 /**96 * System property that defines the location of the webdriver.xpi browser extension to install97 * in the browser. If not set, the prebuilt extension bundled with this class will be used.98 */99 public static final String DRIVER_XPI_PROPERTY = "webdriver.firefox.driver";100 /**101 * Boolean system property that instructs FirefoxDriver to use Marionette backend,102 * overrides any capabilities specified by the user103 */104 public static final String DRIVER_USE_MARIONETTE = "webdriver.firefox.marionette";105 }106 /**107 * @deprecated Use {@link Capability#BINARY}108 */109 @Deprecated110 public static final String BINARY = Capability.BINARY;111 /**112 * @deprecated Use {@link Capability#PROFILE}113 */114 @Deprecated115 public static final String PROFILE = Capability.PROFILE;116 /**117 * @deprecated Use {@link Capability#MARIONETTE}118 */119 @Deprecated120 public static final String MARIONETTE = Capability.MARIONETTE;121 public static final class Capability {122 public static final String BINARY = "firefox_binary";123 public static final String PROFILE = "firefox_profile";124 public static final String MARIONETTE = "marionette";125 }126 private static class ExtraCommands {127 static String INSTALL_EXTENSION = "installExtension";128 static String UNINSTALL_EXTENSION = "uninstallExtension";129 static String FULL_PAGE_SCREENSHOT = "fullPageScreenshot";130 }131 private static final ImmutableMap<String, CommandInfo> EXTRA_COMMANDS = ImmutableMap.of(132 ExtraCommands.INSTALL_EXTENSION,133 new CommandInfo("/session/:sessionId/moz/addon/install", HttpMethod.POST),134 ExtraCommands.UNINSTALL_EXTENSION,135 new CommandInfo("/session/:sessionId/moz/addon/uninstall", HttpMethod.POST),136 ExtraCommands.FULL_PAGE_SCREENSHOT,137 new CommandInfo("/session/:sessionId/moz/screenshot/full", HttpMethod.GET)138 );139 private static class FirefoxDriverCommandExecutor extends DriverCommandExecutor {140 public FirefoxDriverCommandExecutor(DriverService service) {141 super(service, EXTRA_COMMANDS);142 }143 }144 private final Capabilities capabilities;145 protected FirefoxBinary binary;146 private final RemoteWebStorage webStorage;147 private final Optional<URI> cdpUri;148 private DevTools devTools;149 public FirefoxDriver() {150 this(new FirefoxOptions());151 }152 /**153 * @deprecated Use {@link #FirefoxDriver(FirefoxOptions)}.154 */155 @Deprecated156 public FirefoxDriver(Capabilities desiredCapabilities) {157 this(new FirefoxOptions(Require.nonNull("Capabilities", desiredCapabilities)));158 }159 /**160 * @deprecated Use {@link #FirefoxDriver(FirefoxDriverService, FirefoxOptions)}.161 */162 @Deprecated163 public FirefoxDriver(FirefoxDriverService service, Capabilities desiredCapabilities) {164 this(165 Require.nonNull("Driver service", service),166 new FirefoxOptions(desiredCapabilities));167 }168 public FirefoxDriver(FirefoxOptions options) {169 this(toExecutor(options), options);170 }171 public FirefoxDriver(FirefoxDriverService service) {172 this(service, new FirefoxOptions());173 }174 public FirefoxDriver(FirefoxDriverService service, FirefoxOptions options) {175 this(new FirefoxDriverCommandExecutor(service), options);176 }177 private FirefoxDriver(FirefoxDriverCommandExecutor executor, FirefoxOptions options) {178 super(executor, dropCapabilities(options));179 webStorage = new RemoteWebStorage(getExecuteMethod());180 Capabilities capabilities = super.getCapabilities();181 HttpClient.Factory clientFactory = HttpClient.Factory.createDefault();182 Optional<URI> cdpUri = CdpEndpointFinder.getReportedUri("moz:debuggerAddress", capabilities)183 .flatMap(reported -> CdpEndpointFinder.getCdpEndPoint(clientFactory, reported));184 this.cdpUri = cdpUri;185 this.capabilities = cdpUri.map(uri ->186 new ImmutableCapabilities(187 new PersistentCapabilities(capabilities)188 .setCapability("se:cdp", uri.toString())189 .setCapability("se:cdpVersion", "85")))190 .orElse(new ImmutableCapabilities(capabilities));191 }192 private static FirefoxDriverCommandExecutor toExecutor(FirefoxOptions options) {193 Require.nonNull("Options to construct executor from", options);194 String sysProperty = System.getProperty(SystemProperty.DRIVER_USE_MARIONETTE);195 boolean isLegacy = (sysProperty != null && ! Boolean.parseBoolean(sysProperty))196 || options.isLegacy();197 FirefoxDriverService.Builder<?, ?> builder =198 StreamSupport.stream(ServiceLoader.load(DriverService.Builder.class).spliterator(), false)199 .filter(b -> b instanceof FirefoxDriverService.Builder)200 .map(FirefoxDriverService.Builder.class::cast)201 .filter(b -> b.isLegacy() == isLegacy)202 .findFirst().orElseThrow(WebDriverException::new);203 return new FirefoxDriverCommandExecutor(builder.withOptions(options).build());204 }205 @Override206 public Capabilities getCapabilities() {207 return capabilities;208 }209 @Override210 public void setFileDetector(FileDetector detector) {211 throw new WebDriverException(212 "Setting the file detector only works on remote webdriver instances obtained " +213 "via RemoteWebDriver");214 }215 @Override216 public LocalStorage getLocalStorage() {217 return webStorage.getLocalStorage();218 }219 @Override220 public SessionStorage getSessionStorage() {221 return webStorage.getSessionStorage();222 }223 private static boolean isLegacy(Capabilities desiredCapabilities) {224 Boolean forceMarionette = forceMarionetteFromSystemProperty();225 if (forceMarionette != null) {226 return !forceMarionette;227 }228 Object marionette = desiredCapabilities.getCapability(Capability.MARIONETTE);229 return marionette instanceof Boolean && ! (Boolean) marionette;230 }231 @Override232 public String installExtension(Path path) {233 return (String) execute(ExtraCommands.INSTALL_EXTENSION,234 ImmutableMap.of("path", path.toAbsolutePath().toString(),235 "temporary", false)).getValue();236 }237 @Override238 public void uninstallExtension(String extensionId) {239 execute(ExtraCommands.UNINSTALL_EXTENSION, singletonMap("id", extensionId));240 }241 /**242 * Capture the full page screenshot and store it in the specified location.243 *244 * @param <X> Return type for getFullPageScreenshotAs.245 * @param outputType target type, @see OutputType246 * @return Object in which is stored information about the screenshot.247 * @throws WebDriverException on failure.248 */249 public <X> X getFullPageScreenshotAs(OutputType<X> outputType) throws WebDriverException {250 Response response = execute(ExtraCommands.FULL_PAGE_SCREENSHOT);251 Object result = response.getValue();252 if (result instanceof String) {253 String base64EncodedPng = (String) result;254 return outputType.convertFromBase64Png(base64EncodedPng);255 } else if (result instanceof byte[]) {256 String base64EncodedPng = new String((byte[]) result, UTF_8);257 return outputType.convertFromBase64Png(base64EncodedPng);258 } else {259 throw new RuntimeException(String.format("Unexpected result for %s command: %s",260 ExtraCommands.FULL_PAGE_SCREENSHOT,261 result == null ? "null" : result.getClass().getName() + " instance"));262 }263 }264 private static Boolean forceMarionetteFromSystemProperty() {265 String useMarionette = System.getProperty(SystemProperty.DRIVER_USE_MARIONETTE);266 if (useMarionette == null) {267 return null;268 }269 return Boolean.valueOf(useMarionette);270 }271 /**272 * Drops capabilities that we shouldn't send over the wire.273 *274 * Used for capabilities which aren't BeanToJson-convertable, and are only used by the local275 * launcher.276 */277 private static Capabilities dropCapabilities(Capabilities capabilities) {278 if (capabilities == null) {279 return new ImmutableCapabilities();280 }281 MutableCapabilities caps;282 if (isLegacy(capabilities)) {283 final Set<String> toRemove = Sets.newHashSet(Capability.BINARY, Capability.PROFILE);284 caps = new MutableCapabilities(285 Maps.filterKeys(capabilities.asMap(), key -> !toRemove.contains(key)));286 } else {287 caps = new MutableCapabilities(capabilities);288 }289 // Ensure that the proxy is in a state fit to be sent to the extension290 Proxy proxy = Proxy.extractFrom(capabilities);291 if (proxy != null) {292 caps.setCapability(PROXY, proxy);293 }294 return caps;295 }296 @Override297 public DevTools getDevTools() {298 if (devTools == null) {299 URI wsUri = cdpUri.orElseThrow(() ->300 new DevToolsException("This version of Firefox or geckodriver does not support CDP"));301 HttpClient.Factory clientFactory = HttpClient.Factory.createDefault();302 ClientConfig wsConfig = ClientConfig.defaultConfig().baseUri(wsUri);303 HttpClient wsClient = clientFactory.createClient(wsConfig);304 Connection connection = new Connection(wsClient, wsUri.toString());305 CdpInfo cdpInfo = new CdpVersionFinder().match("85.0").orElseGet(NoOpCdpInfo::new);306 devTools = new DevTools(cdpInfo::getDomains, connection);307 }308 return devTools;309 }310}...

Full Screen

Full Screen

Source:ChromiumDriver.java Github

copy

Full Screen

...25import org.openqa.selenium.WebDriver;26import org.openqa.selenium.WebDriverException;27import org.openqa.selenium.devtools.CdpEndpointFinder;28import org.openqa.selenium.devtools.CdpInfo;29import org.openqa.selenium.devtools.CdpVersionFinder;30import org.openqa.selenium.devtools.Connection;31import org.openqa.selenium.devtools.DevTools;32import org.openqa.selenium.devtools.HasDevTools;33import org.openqa.selenium.devtools.noop.NoOpCdpInfo;34import org.openqa.selenium.html5.LocalStorage;35import org.openqa.selenium.html5.Location;36import org.openqa.selenium.html5.LocationContext;37import org.openqa.selenium.html5.SessionStorage;38import org.openqa.selenium.html5.WebStorage;39import org.openqa.selenium.interactions.HasTouchScreen;40import org.openqa.selenium.interactions.TouchScreen;41import org.openqa.selenium.internal.Require;42import org.openqa.selenium.logging.EventType;43import org.openqa.selenium.logging.HasLogEvents;44import org.openqa.selenium.mobile.NetworkConnection;45import org.openqa.selenium.remote.CommandExecutor;46import org.openqa.selenium.remote.FileDetector;47import org.openqa.selenium.remote.RemoteTouchScreen;48import org.openqa.selenium.remote.RemoteWebDriver;49import org.openqa.selenium.remote.html5.RemoteLocationContext;50import org.openqa.selenium.remote.html5.RemoteWebStorage;51import org.openqa.selenium.remote.http.ClientConfig;52import org.openqa.selenium.remote.http.HttpClient;53import org.openqa.selenium.remote.mobile.RemoteNetworkConnection;54import java.net.URI;55import java.util.Map;56import java.util.Optional;57import java.util.function.Predicate;58import java.util.function.Supplier;59import java.util.logging.Logger;60/**61 * A {@link WebDriver} implementation that controls a Chromium browser running on the local machine.62 * It is used as the base class for Chromium-based browser drivers (Chrome, Edgium).63 */64public class ChromiumDriver extends RemoteWebDriver implements65 HasAuthentication,66 HasDevTools,67 HasLogEvents,68 HasTouchScreen,69 LocationContext,70 NetworkConnection,71 WebStorage {72 private static final Logger LOG = Logger.getLogger(ChromiumDriver.class.getName());73 private final Capabilities capabilities;74 private final RemoteLocationContext locationContext;75 private final RemoteWebStorage webStorage;76 private final TouchScreen touchScreen;77 private final RemoteNetworkConnection networkConnection;78 private final Optional<Connection> connection;79 private final Optional<DevTools> devTools;80 protected ChromiumDriver(CommandExecutor commandExecutor, Capabilities capabilities, String capabilityKey) {81 super(commandExecutor, capabilities);82 locationContext = new RemoteLocationContext(getExecuteMethod());83 webStorage = new RemoteWebStorage(getExecuteMethod());84 touchScreen = new RemoteTouchScreen(getExecuteMethod());85 networkConnection = new RemoteNetworkConnection(getExecuteMethod());86 HttpClient.Factory factory = HttpClient.Factory.createDefault();87 Capabilities originalCapabilities = super.getCapabilities();88 Optional<URI> cdpUri = CdpEndpointFinder.getReportedUri(capabilityKey, originalCapabilities)89 .flatMap(uri -> CdpEndpointFinder.getCdpEndPoint(factory, uri));90 connection = cdpUri.map(uri -> new Connection(91 factory.createClient(ClientConfig.defaultConfig().baseUri(uri)),92 uri.toString()));93 CdpInfo cdpInfo = new CdpVersionFinder().match(originalCapabilities.getBrowserVersion())94 .orElseGet(() -> {95 LOG.warning(96 String.format(97 "Unable to find version of CDP to use for %s. You may need to " +98 "include a dependency on a specific version of the CDP using " +99 "something similar to " +100 "`org.seleniumhq.selenium:selenium-devtools-v86:%s` where the " +101 "version (\"v86\") matches the version of the chromium-based browser " +102 "you're using and the version number of the artifact is the same " +103 "as Selenium's.",104 capabilities.getBrowserVersion(),105 new BuildInfo().getReleaseLabel()));106 return new NoOpCdpInfo();107 });...

Full Screen

Full Screen

Source:MainPageTest.java Github

copy

Full Screen

...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()));...

Full Screen

Full Screen

Source:CdpVersionFinderTest.java Github

copy

Full Screen

...22import java.util.Map;23import java.util.Optional;24import static org.assertj.core.api.Assertions.assertThat;25import static org.openqa.selenium.json.Json.MAP_TYPE;26public class CdpVersionFinderTest {27 private Map<String, Object> chrome85;28 private Map<String, Object> edge84;29 @Before30 public void setUp() {31 Json json = new Json();32 chrome85 = json.toType(33 "{ \n" +34 " \"Browser\": \"Chrome/85.0.4183.69\",\n" +35 " \"Protocol-Version\": \"1.3\",\n" +36 " \"User-Agent\": \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.69 Safari/537.36\",\n" +37 " \"V8-Version\": \"8.5.210.19\",\n" +38 " \"WebKit-Version\": \"537.36 (@4554ea1a1171bd8d06951a4b7d9336afe6c59967)\",\n" +39 " \"webSocketDebuggerUrl\": \"ws://localhost:9222/devtools/browser/c0ef43a1-7bb0-48e3-9cec-d6bb048cb720\"\n" +40 "}",41 MAP_TYPE);42 edge84 = json.toType(43 "{\n" +44 " \"Browser\": \"Edg/84.0.522.59\",\n" +45 " \"Protocol-Version\": \"1.3\",\n" +46 " \"User-Agent\": \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36 Edg/84.0.522.59\",\n" +47 " \"V8-Version\": \"8.4.371.23\",\n" +48 " \"WebKit-Version\": \"537.36 (@52ea6e40afcc988eef78d29d50f9077893fa1a12)\",\n" +49 " \"webSocketDebuggerUrl\": \"ws://localhost:9222/devtools/browser/c7922624-12e8-4301-8b08-fa446944c5cc\"\n" +50 "}",51 MAP_TYPE);52 }53 @Test54 public void shouldReturnAnExactMatchIfFound() {55 CdpInfo v84 = new CdpInfo(84, dt -> null){};56 CdpInfo v85 = new CdpInfo(85, dt -> null){};57 CdpVersionFinder finder = new CdpVersionFinder(5, ImmutableList.of(v84, v85));58 Optional<CdpInfo> info = finder.match(chrome85);59 assertThat(info).isEqualTo(Optional.of(v85));60 info = finder.match(edge84);61 assertThat(info).isEqualTo(Optional.of(v84));62 }63 @Test64 public void shouldReturnThePreviousLowestMatchIfNoExactMatchFoundWithinFuzzFactor() {65 CdpInfo v84 = new CdpInfo(84, dt -> null){};66 CdpVersionFinder finder = new CdpVersionFinder(5, ImmutableList.of(v84));67 Optional<CdpInfo> info = finder.match(chrome85);68 assertThat(info).isEqualTo(Optional.of(v84));69 }70 @Test71 public void shouldReturnEmptyIfNothingIsFoundThatMatches() {72 CdpInfo v90 = new CdpInfo(90, dt -> null){};73 CdpVersionFinder finder = new CdpVersionFinder(5, ImmutableList.of(v90));74 assertThat(finder.match(edge84)).isEmpty();75 assertThat(finder.match(chrome85)).isEmpty();76 }77 @Test78 public void canUseBrowserVersionIfNecessary() {79 String chromeVersion = "85.0.4183.69";80 String edgeVersion = "84.0.522.59";81 CdpInfo v84 = new CdpInfo(84, dt -> null){};82 CdpInfo v85 = new CdpInfo(85, dt -> null){};83 CdpVersionFinder finder = new CdpVersionFinder(5, ImmutableList.of(v84, v85));84 Optional<CdpInfo> info = finder.match(chromeVersion);85 assertThat(info).isEqualTo(Optional.of(v85));86 info = finder.match(edgeVersion);87 assertThat(info).isEqualTo(Optional.of(v84));88 }89}...

Full Screen

Full Screen

Source:DevToolsProvider.java Github

copy

Full Screen

...34 return HasDevTools.class;35 }36 @Override37 public HasDevTools getImplementation(Capabilities caps, ExecuteMethod executeMethod) {38 CdpInfo info = new CdpVersionFinder().match(caps.getBrowserVersion()).orElseGet(NoOpCdpInfo::new);39 Optional<DevTools> devTools = SeleniumCdpConnection.create(caps).map(conn -> new DevTools(info::getDomains, conn));40 return () -> devTools.orElseThrow(() -> new IllegalStateException("Unable to create connection to " + caps));41 }42 private String getCdpUrl(Capabilities caps) {43 Object options = caps.getCapability("se:options");44 if (!(options instanceof Map)) {45 return null;46 }47 Object cdp = ((Map<?, ?>) options).get("cdp");48 return cdp == null ? null : String.valueOf(cdp);49 }50}...

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

CdpVersionFinder

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.devtools.CdpVersionFinder;2import org.openqa.selenium.devtools.DevTools;3import org.openqa.selenium.devtools.v91.browser.Browser;4import org.openqa.selenium.devtools.v91.browser.model.BrowserContextID;5import org.openqa.selenium.devtools.v91.browser.model.Bounds;6import org.openqa.selenium.devtools.v91.browser.model.WindowID;7import org.openqa.selenium.devtools.v91.browser.model.WindowState;8import org.openqa.selenium.devtools.v91.page.Page;9import org.openqa.selenium.devtools.v91.page.model.Viewport;10import org.openqa.selenium.devtools.v91.runtime.Runtime;11import org.openqa.selenium.devtools.v91.runtime.model.RemoteObject;12import org.openqa.selenium.chrome.ChromeDriver;13import org.openqa.selenium.chrome.ChromeOptions;14import org.openqa.selenium.devtools.Command;15import org.openqa.selenium.devtools.HasDevTools;16import org.openqa.selenium.devtools.Session;17import org.openqa.selenium.devtools.v91.network.Network;18import org.openqa.selenium.devtools.v91.network.model.ConnectionType;19import org.openqa.selenium.devtools.v91.network.model.Request;20import org.openqa.selenium.devtools.v91.network.model.Response;21import org.openqa.selenium.devtools.v91.network.model.ResourceType;22import org.openqa.selenium.devtools.v91.network.model.RequestPattern;23import org.openqa.selenium.devtools.v91.network.model.ResourcePriority;24import org.openqa.selenium.devtools.v91.network.model.InterceptionStage;25import org.openqa.selenium.devtools.v91.network.model.InterceptionId;26import org.openqa.selenium.devtools.v91.network.model.AuthChallenge;27import org.openqa.selenium.devtools.v91.network.model.AuthChallengeResponse;28import org.openqa.selenium.devtools.v91.security.Security;29import org.openqa.selenium.devtools.v91.security.model.SecurityState;30import org.openqa.selenium.devtools.v91.security.model.MixedContentType;31import org.openqa.selenium.devtools.v91.security.model.CertificateErrorAction;32import org.openqa.selenium.devtools.v91.security.model.CertificateError;33import org.openqa.selenium.devtools.v91.security.model.CertificateSecurityState;34import org.openqa.selenium.devtools.v91.security.model.SecurityStateChangedEvent;35import org.openqa.selenium.devtools.v91.security.model.InsecureContentStatus;36import org.openqa.selenium.devtools.v91.security.model.SecurityStateExplanation;37import org.openqa.selenium.devtools.v91.security.model.SecurityStateDetails;38import org.openqa.selenium.devtools.v91.security.model.MixedContentIssueDetails;39import org.openqa.selenium.devtools.v91.security.model.SignedExchangeError;40import org.openqa.selenium.devtools.v91.security.model.S

Full Screen

Full Screen

CdpVersionFinder

Using AI Code Generation

copy

Full Screen

1CdpVersionFinder versionFinder = new CdpVersionFinder();2String cdpVersion = versionFinder.findCdpVersion();3System.out.println("CDP Version is: " + cdpVersion);4CdpVersionFinder versionFinder = new CdpVersionFinder();5String cdpVersion = versionFinder.findCdpVersion();6System.out.println("CDP Version is: " + cdpVersion);7CdpVersionFinder versionFinder = new CdpVersionFinder();8String cdpVersion = versionFinder.findCdpVersion();9System.out.println("CDP Version is: " + cdpVersion);10CdpVersionFinder versionFinder = new CdpVersionFinder();11String cdpVersion = versionFinder.findCdpVersion();12System.out.println("CDP Version is: " + cdpVersion);13CdpVersionFinder versionFinder = new CdpVersionFinder();14String cdpVersion = versionFinder.findCdpVersion();15System.out.println("CDP Version is: " + cdpVersion);16CdpVersionFinder versionFinder = new CdpVersionFinder();17String cdpVersion = versionFinder.findCdpVersion();18System.out.println("CDP Version is: " + cdpVersion);19CdpVersionFinder versionFinder = new CdpVersionFinder();20String cdpVersion = versionFinder.findCdpVersion();21System.out.println("CDP Version is: " + cdpVersion);22CdpVersionFinder versionFinder = new CdpVersionFinder();23String cdpVersion = versionFinder.findCdpVersion();24System.out.println("CDP Version is: " + cdpVersion);25CdpVersionFinder versionFinder = new CdpVersionFinder();26String cdpVersion = versionFinder.findCdpVersion();27System.out.println("CDP Version is: " + cdpVersion);

Full Screen

Full Screen

CdpVersionFinder

Using AI Code Generation

copy

Full Screen

1CdpVersionFinder cdpVersionFinder = new CdpVersionFinder();2CdpVersionFinder cdpVersionFinder = new CdpVersionFinder();3CdpVersionFinder cdpVersionFinder = new CdpVersionFinder();4CdpVersionFinder cdpVersionFinder = new CdpVersionFinder();5CdpVersionFinder cdpVersionFinder = new CdpVersionFinder();6CdpVersionFinder cdpVersionFinder = new CdpVersionFinder();7CdpVersionFinder cdpVersionFinder = new CdpVersionFinder();8CdpVersionFinder cdpVersionFinder = new CdpVersionFinder();9CdpVersionFinder cdpVersionFinder = new CdpVersionFinder();10CdpVersionFinder cdpVersionFinder = new CdpVersionFinder();

Full Screen

Full Screen

CdpVersionFinder

Using AI Code Generation

copy

Full Screen

1package com.chromedriver;2import org.openqa.selenium.devtools.CdpVersionFinder;3public class ChromeVersionFinder {4 public static void main(String[] args) {5 System.out.println(CdpVersionFinder.getChromeVersion());6 }7}

Full Screen

Full Screen

CdpVersionFinder

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.devtools.DevTools;2import org.openqa.selenium.devtools.v85.browser.CdpVersionFinder;3public class DevToolsVersion {4 public static void main(String[] args) {5 System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");6 DevTools devTools = new DevTools();7 devTools.createSession();8 System.out.println("Chrome version: " + CdpVersionFinder.findVersion(devTools));9 devTools.close();10 }11}12DevTools devTools = new DevTools();13devTools.createSession();14System.out.println("Chrome version: " + CdpVersionFinder.findVersion(devTools));15devTools.close();

Full Screen

Full Screen

CdpVersionFinder

Using AI Code Generation

copy

Full Screen

1package com.automation;2import org.openqa.selenium.devtools.DevTools;3import org.openqa.selenium.devtools.v85.browser.Browser;4import org.openqa.selenium.devtools.v85.browser.model.Version;5import org.openqa.selenium.devtools.v85.browser.model.VersionResponse;6import org.openqa.selenium.remote.RemoteWebDriver;7public class CdpVersionFinder {8 public static void main(String[] args) {9 DevTools devTools = driver.getDevTools();10 devTools.createSession();11 VersionResponse versionResponse = devTools.send(Browser.getVersion());12 Version version = versionResponse.getVersion();13 System.out.println("ChromeDriver version " + version.getBrowser());14 System.out.println("Chrome version " + version.getProtocolVersion());15 devTools.close();16 driver.quit();17 }18}

Full Screen

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 CdpVersionFinder

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