How to use execute method of org.openqa.selenium.remote.service.DriverCommandExecutor class

Best Selenium code snippet using org.openqa.selenium.remote.service.DriverCommandExecutor.execute

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 static org.openqa.selenium.firefox.FirefoxDriver.SystemProperty.DRIVER_USE_MARIONETTE;19import static org.openqa.selenium.remote.CapabilityType.PROXY;20import com.google.common.collect.Maps;21import com.google.common.collect.Sets;22import org.openqa.selenium.Capabilities;23import org.openqa.selenium.ImmutableCapabilities;24import org.openqa.selenium.MutableCapabilities;25import org.openqa.selenium.Proxy;26import org.openqa.selenium.WebDriverException;27import org.openqa.selenium.html5.LocalStorage;28import org.openqa.selenium.html5.SessionStorage;29import org.openqa.selenium.html5.WebStorage;30import org.openqa.selenium.remote.CommandExecutor;31import org.openqa.selenium.remote.FileDetector;32import org.openqa.selenium.remote.RemoteWebDriver;33import org.openqa.selenium.remote.html5.RemoteWebStorage;34import org.openqa.selenium.remote.service.DriverCommandExecutor;35import org.openqa.selenium.remote.service.DriverService;36import java.util.Objects;37import java.util.Set;38/**39 * An implementation of the {#link WebDriver} interface that drives Firefox.40 * <p>41 * The best way to construct a {@code FirefoxDriver} with various options is to make use of the42 * {@link FirefoxOptions}, like so:43 *44 * <pre>45 *FirefoxOptions options = new FirefoxOptions()46 * .setProfile(new FirefoxProfile());47 *WebDriver driver = new FirefoxDriver(options);48 * </pre>49 */50public class FirefoxDriver extends RemoteWebDriver implements WebStorage {51 public static final class SystemProperty {52 /**53 * System property that defines the location of the Firefox executable file.54 */55 public static final String BROWSER_BINARY = "webdriver.firefox.bin";56 /**57 * System property that defines the location of the file where Firefox log should be stored.58 */59 public static final String BROWSER_LOGFILE = "webdriver.firefox.logfile";60 /**61 * System property that defines the additional library path (Linux only).62 */63 public static final String BROWSER_LIBRARY_PATH = "webdriver.firefox.library.path";64 /**65 * System property that defines the profile that should be used as a template.66 * When the driver starts, it will make a copy of the profile it is using,67 * rather than using that profile directly.68 */69 public static final String BROWSER_PROFILE = "webdriver.firefox.profile";70 /**71 * System property that defines the location of the webdriver.xpi browser extension to install72 * in the browser. If not set, the prebuilt extension bundled with this class will be used.73 */74 public static final String DRIVER_XPI_PROPERTY = "webdriver.firefox.driver";75 /**76 * Boolean system property that instructs FirefoxDriver to use Marionette backend,77 * overrides any capabilities specified by the user78 */79 public static final String DRIVER_USE_MARIONETTE = "webdriver.firefox.marionette";80 }81 public static final String BINARY = "firefox_binary";82 public static final String PROFILE = "firefox_profile";83 public static final String MARIONETTE = "marionette";84 protected FirefoxBinary binary;85 private RemoteWebStorage webStorage;86 public FirefoxDriver() {87 this(new FirefoxOptions());88 }89 /**90 * @deprecated Use {@link #FirefoxDriver(FirefoxOptions)}.91 */92 @Deprecated93 public FirefoxDriver(Capabilities desiredCapabilities) {94 this(new FirefoxOptions(Objects.requireNonNull(desiredCapabilities, "No capabilities seen")));95 }96 /**97 * @deprecated Use {@link #FirefoxDriver(GeckoDriverService, FirefoxOptions)}.98 */99 @Deprecated100 public FirefoxDriver(GeckoDriverService service, Capabilities desiredCapabilities) {101 this(102 Objects.requireNonNull(service, "No geckodriver service provided"),103 new FirefoxOptions(desiredCapabilities));104 }105 public FirefoxDriver(FirefoxOptions options) {106 super(toExecutor(options), dropCapabilities(options));107 webStorage = new RemoteWebStorage(getExecuteMethod());108 }109 public FirefoxDriver(GeckoDriverService service) {110 super(new DriverCommandExecutor(service), new FirefoxOptions());111 webStorage = new RemoteWebStorage(getExecuteMethod());112 }113 public FirefoxDriver(XpiDriverService service) {114 super(new DriverCommandExecutor(service), new FirefoxOptions());115 webStorage = new RemoteWebStorage(getExecuteMethod());116 }117 public FirefoxDriver(GeckoDriverService service, FirefoxOptions options) {118 super(new DriverCommandExecutor(service), dropCapabilities(options));119 webStorage = new RemoteWebStorage(getExecuteMethod());120 }121 public FirefoxDriver(XpiDriverService service, FirefoxOptions options) {122 super(new DriverCommandExecutor(service), dropCapabilities(options));123 webStorage = new RemoteWebStorage(getExecuteMethod());124 }125 private static CommandExecutor toExecutor(FirefoxOptions options) {126 Objects.requireNonNull(options, "No options to construct executor from");127 DriverService.Builder<?, ?> builder;128 if (! Boolean.parseBoolean(System.getProperty(DRIVER_USE_MARIONETTE, "true"))129 || options.isLegacy()) {130 FirefoxProfile profile = options.getProfile();131 if (profile == null) {132 profile = new FirefoxProfile();133 options.setCapability(FirefoxDriver.PROFILE, profile);134 }135 builder = XpiDriverService.builder()136 .withBinary(options.getBinary())137 .withProfile(profile);138 } else {139 builder = new GeckoDriverService.Builder()140 .usingFirefoxBinary(options.getBinary());141 }142 return new DriverCommandExecutor(builder.build());143 }144 @Override145 public void setFileDetector(FileDetector detector) {146 throw new WebDriverException(147 "Setting the file detector only works on remote webdriver instances obtained " +148 "via RemoteWebDriver");149 }150 @Override151 public LocalStorage getLocalStorage() {152 return webStorage.getLocalStorage();153 }154 @Override155 public SessionStorage getSessionStorage() {156 return webStorage.getSessionStorage();157 }158 private static boolean isLegacy(Capabilities desiredCapabilities) {159 Boolean forceMarionette = forceMarionetteFromSystemProperty();160 if (forceMarionette != null) {161 return !forceMarionette;162 }163 Object marionette = desiredCapabilities.getCapability(MARIONETTE);164 return marionette instanceof Boolean && ! (Boolean) marionette;165 }166 private static Boolean forceMarionetteFromSystemProperty() {167 String useMarionette = System.getProperty(DRIVER_USE_MARIONETTE);168 if (useMarionette == null) {169 return null;170 }171 return Boolean.valueOf(useMarionette);172 }173 /**174 * Drops capabilities that we shouldn't send over the wire.175 *176 * Used for capabilities which aren't BeanToJson-convertable, and are only used by the local177 * launcher.178 */179 private static Capabilities dropCapabilities(Capabilities capabilities) {180 if (capabilities == null) {181 return new ImmutableCapabilities();182 }183 MutableCapabilities caps;184 if (isLegacy(capabilities)) {185 final Set<String> toRemove = Sets.newHashSet(BINARY, PROFILE);186 caps = new MutableCapabilities(187 Maps.filterKeys(capabilities.asMap(), key -> !toRemove.contains(key)));188 } else {189 caps = new MutableCapabilities(capabilities);190 }191 // Ensure that the proxy is in a state fit to be sent to the extension192 Proxy proxy = Proxy.extractFrom(capabilities);193 if (proxy != null) {194 caps.setCapability(PROXY, proxy);195 }196 return caps;197 }198}...

Full Screen

Full Screen

Source:DriverCommandExecutor.java Github

copy

Full Screen

...59 * Sends the {@code command} to the driver server for execution. The server will be started60 * if requesting a new session. Likewise, if terminating a session, the server will be shutdown61 * once a response is received.62 *63 * @param command The command to execute.64 * @return The command response.65 * @throws IOException If an I/O error occurs while sending the command.66 */67 @Override68 public Response execute(Command command) throws IOException {69 if (DriverCommand.NEW_SESSION.equals(command.getName())) {70 service.start();71 }72 try {73 return super.execute(command);74 } catch (Throwable t) {75 Throwable rootCause = Throwables.getRootCause(t);76 if (rootCause instanceof ConnectException &&77 "Connection refused".equals(rootCause.getMessage()) &&78 !service.isRunning()) {79 throw new WebDriverException("The driver server has unexpectedly died!", t);80 }81 Throwables.throwIfUnchecked(t);82 throw new WebDriverException(t);83 } finally {84 if (DriverCommand.QUIT.equals(command.getName())) {85 service.stop();86 }87 }...

Full Screen

Full Screen

Source:ChromiumDriverCommandExecutor.java Github

copy

Full Screen

...35 new CommandInfo("/session/:sessionId/chromium/network_conditions", HttpMethod.POST),36 ChromiumDriverCommand.DELETE_NETWORK_CONDITIONS,37 new CommandInfo("/session/:sessionId/chromium/network_conditions", HttpMethod.DELETE),38 ChromiumDriverCommand.EXECUTE_CDP_COMMAND,39 new CommandInfo("/session/:sessionId/goog/cdp/execute", HttpMethod.POST));40 public ChromiumDriverCommandExecutor(DriverService service) {41 super(service, CHROME_COMMAND_NAME_TO_URL);42 }43}...

Full Screen

Full Screen

Source:ChromeDriverCommandExecutor.java Github

copy

Full Screen

...35 new CommandInfo("/session/:sessionId/chromium/network_conditions", HttpMethod.POST),36 ChromeDriverCommand.DELETE_NETWORK_CONDITIONS,37 new CommandInfo("/session/:sessionId/chromium/network_conditions", HttpMethod.DELETE),38 ChromeDriverCommand.EXECUTE_CDP_COMMAND,39 new CommandInfo("/session/:sessionId/goog/cdp/execute", HttpMethod.POST));40 public ChromeDriverCommandExecutor(DriverService service) {41 super(service, CHROME_COMMAND_NAME_TO_URL);42 }43}...

Full Screen

Full Screen

Source:modal.java Github

copy

Full Screen

...21 22 WebElement op = driver.findElement(By.id("close-button"));23 24 JavascriptExecutor js = (JavascriptExecutor)driver;25 js.executeScript("arguments[0].click();", op);26 27 28 Thread.sleep(2000);29 driver.quit();30 }31}...

Full Screen

Full Screen

execute

Using AI Code Generation

copy

Full Screen

1WebElement element = driver.findElement(By.name("q"));2element.sendKeys("Cheese!");3element.submit();4System.out.println("Page title is: " + driver.getTitle());5driver.quit();6}

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 method in DriverCommandExecutor

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful