How to use Interface HasDevTools class of org.openqa.selenium.devtools package

Best Selenium code snippet using org.openqa.selenium.devtools.Interface HasDevTools

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

Full Screen

Full Screen

Source:ChromiumDriver.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.chromium;18import com.google.common.collect.ImmutableMap;19import org.openqa.selenium.BuildInfo;20import org.openqa.selenium.Capabilities;21import org.openqa.selenium.Credentials;22import org.openqa.selenium.HasAuthentication;23import org.openqa.selenium.WebDriver;24import org.openqa.selenium.WebDriverException;25import org.openqa.selenium.devtools.CdpInfo;26import org.openqa.selenium.devtools.CdpVersionFinder;27import org.openqa.selenium.devtools.Connection;28import org.openqa.selenium.devtools.DevTools;29import org.openqa.selenium.devtools.HasDevTools;30import org.openqa.selenium.devtools.noop.NoOpCdpInfo;31import org.openqa.selenium.html5.LocalStorage;32import org.openqa.selenium.html5.Location;33import org.openqa.selenium.html5.LocationContext;34import org.openqa.selenium.html5.SessionStorage;35import org.openqa.selenium.html5.WebStorage;36import org.openqa.selenium.interactions.HasTouchScreen;37import org.openqa.selenium.interactions.TouchScreen;38import org.openqa.selenium.internal.Require;39import org.openqa.selenium.logging.EventType;40import org.openqa.selenium.logging.HasLogEvents;41import org.openqa.selenium.mobile.NetworkConnection;42import org.openqa.selenium.remote.CommandExecutor;43import org.openqa.selenium.remote.FileDetector;44import org.openqa.selenium.remote.RemoteTouchScreen;45import org.openqa.selenium.remote.RemoteWebDriver;46import org.openqa.selenium.remote.html5.RemoteLocationContext;47import org.openqa.selenium.remote.html5.RemoteWebStorage;48import org.openqa.selenium.remote.http.HttpClient;49import org.openqa.selenium.remote.mobile.RemoteNetworkConnection;50import java.net.URI;51import java.util.Map;52import java.util.Optional;53import java.util.function.Predicate;54import java.util.function.Supplier;55import java.util.logging.Logger;56/**57 * A {@link WebDriver} implementation that controls a Chromium browser running on the local machine.58 * This class is provided as a convenience for easily testing the Chromium browser. The control server59 * which each instance communicates with will live and die with the instance.60 * <p>61 * To avoid unnecessarily restarting the ChromiumDriver server with each instance, use a62 * {@link RemoteWebDriver} coupled with the desired WebDriverService, which is managed63 * separately.64 * <p>65 * Note that unlike ChromiumDriver, RemoteWebDriver doesn't directly implement66 * role interfaces such as {@link LocationContext} and {@link WebStorage}.67 * Therefore, to access that functionality, it needs to be68 * {@link org.openqa.selenium.remote.Augmenter augmented} and then cast69 * to the appropriate interface.70 */71public class ChromiumDriver extends RemoteWebDriver implements72 HasAuthentication,73 HasDevTools,74 HasLogEvents,75 HasTouchScreen,76 LocationContext,77 NetworkConnection,78 WebStorage {79 private static final Logger LOG = Logger.getLogger(ChromiumDriver.class.getName());80 private final RemoteLocationContext locationContext;81 private final RemoteWebStorage webStorage;82 private final TouchScreen touchScreen;83 private final RemoteNetworkConnection networkConnection;84 private final Optional<Connection> connection;85 private final Optional<DevTools> devTools;86 protected ChromiumDriver(CommandExecutor commandExecutor, Capabilities capabilities, String capabilityKey) {87 super(commandExecutor, capabilities);88 locationContext = new RemoteLocationContext(getExecuteMethod());89 webStorage = new RemoteWebStorage(getExecuteMethod());90 touchScreen = new RemoteTouchScreen(getExecuteMethod());91 networkConnection = new RemoteNetworkConnection(getExecuteMethod());92 HttpClient.Factory factory = HttpClient.Factory.createDefault();93 connection = ChromiumDevToolsLocator.getChromeConnector(94 factory,95 getCapabilities(),96 capabilityKey);97 CdpInfo cdpInfo = new CdpVersionFinder().match(getCapabilities().getBrowserVersion())98 .orElseGet(() -> {99 LOG.warning(100 String.format(101 "Unable to find version of CDP to use for %s. You may need to " +102 "include a dependency on a specific version of the CDP using " +103 "something similar to " +104 "`org.seleniumhq.selenium:selenium-devtools-v86:%s` where the " +105 "version (\"v86\") matches the version of the chromium-based browser " +106 "you're using and the version number of the artifact is the same " +107 "as Selenium's.",108 capabilities.getBrowserVersion(),109 new BuildInfo().getReleaseLabel()));110 return new NoOpCdpInfo();111 });112 devTools = connection.map(conn -> new DevTools(cdpInfo::getDomains, conn));113 }114 @Override115 public void setFileDetector(FileDetector detector) {116 throw new WebDriverException(117 "Setting the file detector only works on remote webdriver instances obtained " +118 "via RemoteWebDriver");119 }120 @Override121 public <X> void onLogEvent(EventType<X> kind) {122 Require.nonNull("Event type", kind);123 kind.initializeListener(this);124 }125 @Override126 public void register(Predicate<URI> whenThisMatches, Supplier<Credentials> useTheseCredentials) {127 Require.nonNull("Check to use to see how we should authenticate", whenThisMatches);128 Require.nonNull("Credentials to use when authenticating", useTheseCredentials);129 getDevTools().createSessionIfThereIsNotOne();130 getDevTools().getDomains().network().addAuthHandler(whenThisMatches, useTheseCredentials);131 }132 @Override133 public LocalStorage getLocalStorage() {134 return webStorage.getLocalStorage();135 }136 @Override137 public SessionStorage getSessionStorage() {138 return webStorage.getSessionStorage();139 }140 @Override141 public Location location() {142 return locationContext.location();143 }144 @Override145 public void setLocation(Location location) {146 locationContext.setLocation(location);147 }148 @Override149 public TouchScreen getTouch() {150 return touchScreen;151 }152 @Override153 public ConnectionType getNetworkConnection() {154 return networkConnection.getNetworkConnection();155 }156 @Override157 public ConnectionType setNetworkConnection(ConnectionType type) {158 return networkConnection.setNetworkConnection(type);159 }160 /**161 * Launches Chrome app specified by id.162 *163 * @param id Chrome app id.164 */165 public void launchApp(String id) {166 execute(ChromiumDriverCommand.LAUNCH_APP, ImmutableMap.of("id", id));167 }168 /**169 * Execute a Chrome Devtools Protocol command and get returned result. The170 * command and command args should follow171 * <a href="https://chromedevtools.github.io/devtools-protocol/">chrome172 * devtools protocol domains/commands</a>.173 */174 public Map<String, Object> executeCdpCommand(String commandName, Map<String, Object> parameters) {175 Require.nonNull("Command name", commandName);176 Require.nonNull("Parameters", parameters);177 @SuppressWarnings("unchecked")178 Map<String, Object> toReturn = (Map<String, Object>) getExecuteMethod().execute(179 ChromiumDriverCommand.EXECUTE_CDP_COMMAND,180 ImmutableMap.of("cmd", commandName, "params", parameters));181 return ImmutableMap.copyOf(toReturn);182 }183 @Override184 public DevTools getDevTools() {185 return devTools.orElseThrow(() -> new WebDriverException("Unable to create DevTools connection"));186 }187 public String getCastSinks() {188 Object response = getExecuteMethod().execute(ChromiumDriverCommand.GET_CAST_SINKS, null);189 return response.toString();190 }191 public String getCastIssueMessage() {192 Object response = getExecuteMethod().execute(ChromiumDriverCommand.GET_CAST_ISSUE_MESSAGE, null);193 return response.toString();194 }195 public void selectCastSink(String deviceName) {196 getExecuteMethod().execute(ChromiumDriverCommand.SET_CAST_SINK_TO_USE, ImmutableMap.of("sinkName", deviceName));197 }198 public void startTabMirroring(String deviceName) {199 getExecuteMethod().execute(ChromiumDriverCommand.START_CAST_TAB_MIRRORING, ImmutableMap.of("sinkName", deviceName));200 }201 public void stopCasting(String deviceName) {202 getExecuteMethod().execute(ChromiumDriverCommand.STOP_CASTING, ImmutableMap.of("sinkName", deviceName));203 }204 public void setPermission(String name, String value) {205 getExecuteMethod().execute(ChromiumDriverCommand.SET_PERMISSION,206 ImmutableMap.of("descriptor", ImmutableMap.of("name", name), "state", value));207 }208 @Override209 public void quit() {210 connection.ifPresent(Connection::close);211 super.quit();212 }213}...

Full Screen

Full Screen

Source:DevToolsProvider.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;18import com.google.auto.service.AutoService;19import org.openqa.selenium.Capabilities;20import org.openqa.selenium.devtools.noop.NoOpCdpInfo;21import org.openqa.selenium.remote.AugmenterProvider;22import org.openqa.selenium.remote.ExecuteMethod;23import java.util.Optional;24import java.util.function.Predicate;25@AutoService(AugmenterProvider.class)26public class DevToolsProvider implements AugmenterProvider<HasDevTools> {27 @Override28 public Predicate<Capabilities> isApplicable() {29 return caps -> getCdpUrl(caps) != null;30 }31 @Override32 public Class<HasDevTools> getDescribedInterface() {33 return HasDevTools.class;34 }35 @Override36 public HasDevTools getImplementation(Capabilities caps, ExecuteMethod executeMethod) {37 CdpInfo info = new CdpVersionFinder().match(caps.getBrowserVersion()).orElseGet(NoOpCdpInfo::new);38 Optional<DevTools> devTools = SeleniumCdpConnection.create(caps).map(conn -> new DevTools(info::getDomains, conn));39 return () -> devTools.orElseThrow(() -> new IllegalStateException("Unable to create connection to " + caps));40 }41 private String getCdpUrl(Capabilities caps) {42 Object cdp = caps.getCapability("se:cdp");43 if (!(cdp instanceof String)) {44 return null;45 }46 return (String) cdp;47 }48}...

Full Screen

Full Screen

Source:HasDevTools.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;18public interface HasDevTools {19 DevTools getDevTools();20}...

Full Screen

Full Screen

Interface HasDevTools

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.devtools.DevTools;2import org.openqa.selenium.devtools.HasDevTools;3import org.openqa.selenium.devtools.v91.log.Log;4import org.openqa.selenium.devtools.v91.log.model.LogEntry;5import org.openqa.selenium.devtools.v91.log.model.LogType;6import org.openqa.selenium.devtools.v91.network.Network;7import org.openqa.selenium.devtools.v91.network.model.ConnectionType;8import org.openqa.selenium.devtools.v91.network.model.Headers;9import org.openqa.selenium.devtools.v91.network.model.Request;10import org.openqa.selenium.devtools.v91.network.model.ResourceType;11import org.openqa.selenium.devtools.v91.network.model.Response;12import org.openqa.selenium.devtools.v91.runtime.Runtime;13import org.openqa.selenium.devtools.v91.runtime.model.RemoteObject;14import org.openqa.selenium.devtools.v91.security.Security;15import org.openqa.selenium.devtools.v91.security.model.MixedContentType;16import org.openqa.selenium.devtools.v91.security.model.SecurityState;17import org.openqa.selenium.devtools.v91.security.model.SecurityStateChanged;18import org.openqa.selenium.devtools.v91.storage.Storage;19import org.openqa.selenium.devtools.v91.storage.model.CacheStorageContentUpdated;20import org.openqa.selenium.devtools.v91.storage.model.CacheStorageListUpdated;21import org.openqa.selenium.devtools.v91.storage.model.Cookie;22import org.openqa.selenium.devtools.v91.storage.model.CookieDeleted;23import org.openqa.selenium.devtools.v91.storage.model.CookieExpired;24import org.openqa.selenium.devtools.v91.storage.model.CookieUpdated;25import org.openqa.selenium.devtools.v91.storage.model.IndexedDBContentUpdated;26import org.openqa.selenium.devtools.v91.storage.model.IndexedDBListUpdated;27import org.openqa.selenium.devtools.v91.storage.model.StorageId;28import org.openqa.selenium.devtools.v91.storage.model.StorageType;29import org.openqa.selenium.devtools.v91.storage.model.TrackingCookieDeleted;30import org.openqa.selenium.devtools.v91.storage.model.TrackingCookieExpired;31import org.openqa.selenium.devtools.v91.storage.model.TrackingCookieUpdated;32import org.openqa.selenium.devtools.v91.storage.model.TrackingOriginDeleted;33import org.openqa.selenium.devtools.v91.storage.model.TrackingOriginExpired;34import org.openqa.selenium.devtools.v91.storage.model.TrackingOriginUpdated;35import org.openqa.selenium.devtools.v91.storage.model.TrackingUsageUpdated;36import java.util.List;37public class DevToolsListener implements HasDevTools {38 private DevTools devTools;39 public DevToolsListener(DevTools devTools) {

Full Screen

Full Screen

Interface HasDevTools

Using AI Code Generation

copy

Full Screen

1package com.automation;2import org.openqa.selenium.By;3import org.openqa.selenium.WebDriver;4import org.openqa.selenium.WebElement;5import org.openqa.selenium.chrome.ChromeDriver;6import org.openqa.selenium.devtools.DevTools;7import org.openqa.selenium.devtools.HasDevTools;8import org.openqa.selenium.devtools.v91.browser.Browser;9import org.openqa.selenium.devtools.v91.browser.model.BrowserContextID;10import org.openqa.selenium.devtools.v91.page.Page;11import org.openqa.selenium.devtools.v91.page.model.FrameId;12import org.openqa.selenium.devtools.v91.page.model.FrameResource;13import org.openqa.selenium.devtools.v91.page.model.FrameResourceTree;14import org.openqa.selenium.devtools.v91.page.model.ResourceType;15import java.util.List;16import java.util.Optional;17import java.util.concurrent.TimeUnit;18public class DevToolsDemo {19 public static void main(String[] args) {20 System.setProperty("webdriver.chrome.driver", "C:/Users/HP/Downloads/chromedriver_win32/chromedriver.exe");21 WebDriver driver = new ChromeDriver();22 driver.manage().window().maximize();23 DevTools devTools = ((HasDevTools) driver).getDevTools();24 BrowserContextID context = devTools.send(Browser.createBrowserContext());25 devTools.send(Browser.newPage());26 devTools.send(Page.enable());27 devTools.addListener(Page.loadEventFired(), loadEventFired -> {28 System.out.println("Page loaded");29 });30 try {31 TimeUnit.SECONDS.sleep(5);32 } catch (InterruptedException e) {33 e.printStackTrace();34 }35 FrameId frameId = devTools.send(Page.getResourceTree()).getFrameTree().getFrame().getId();36 FrameResourceTree resourceTree = devTools.send(Page.getResourceTree());37 List<FrameResource> resources = resourceTree.getFrameTree().getResources();

Full Screen

Full Screen

Interface HasDevTools

Using AI Code Generation

copy

Full Screen

1HasDevTools devTools = (HasDevTools) driver;2DevTools devTools = devTools.getDevTools();3devTools.createSession();4Map<String, Object> performanceTiming = devTools.send(Performance.getMetrics());5System.out.println(performanceTiming);6{firstPaint: 1.0, firstContentfulPaint: 1.0, domContentLoaded: 1.0, domInteractive: 1.0, domComplete: 1.0, loadEvent: 1.0, firstMeaningfulPaint: 1.0, firstCpuIdle: 1.0, firstCpuIdleAllFrames: 1.0, largestContentfulPaint: 1.0, networkQuiet: 1.0, networkQuietAllFrames: 1.0, networkQuietWithTti: 1.0, networkQuietAllFramesWithTti: 1.0, networkQuietWithTtiAllFrames: 1.0, networkQuietWithTtiAllFramesWithRtt: 1.0, networkQuietWithTtiAllFramesWithRttAndThrottling: 1.0, networkQuietWithTtiAllFramesWithRttAndThrottlingAndLatency: 1.0, networkQuietWithTtiAllFramesWithRttAndThrottlingAndLatencyAndDownloadThroughput: 1.0, networkQuietWithTtiAllFramesWithRttAndThrottlingAndLatencyAndDownloadThroughputAndUploadThroughput: 1.0, networkQuietWithTtiAllFramesWithRttAndThrottlingAndLatencyAndDownloadThroughputAndUploadThroughputAndCpuSlowdownMultiplier: 1.0, networkQuietWithTtiAllFramesWithRttAndThrottlingAndLatencyAndDownloadThroughputAndUploadThroughputAndCpuSlowdownMultiplierAndServerResponseTime: 1.0, networkQuietWithTtiAllFramesWithRttAndThrottlingAndLatencyAndDownloadThroughputAndUploadThroughputAndCpuSlowdownMultiplierAndServerResponseTimeAndAdditionalLatency: 1.0, networkQuietWithTtiAllFramesWithRttAnd

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 Interface-HasDevTools

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