Source:Custom unchecked exception doesn't make throwing and caller methods return
 @Bean
public CommonsRequestLoggingFilter requestLoggingFilter() {
...
}
Best Selenium code snippet using org.openqa.selenium.remote.Interface CommandExecutor
Source:FirefoxDriver.java  
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.Proxy;24import org.openqa.selenium.WebDriverException;25import org.openqa.selenium.remote.CommandExecutor;26import org.openqa.selenium.remote.DesiredCapabilities;27import org.openqa.selenium.remote.FileDetector;28import org.openqa.selenium.remote.RemoteWebDriver;29import org.openqa.selenium.remote.service.DriverCommandExecutor;30import org.openqa.selenium.remote.service.DriverService;31import java.util.Set;32import java.util.logging.Logger;33/**34 * An implementation of the {#link WebDriver} interface that drives Firefox.35 * <p>36 * The best way to construct a {@code FirefoxDriver} with various options is to make use of the37 * {@link FirefoxOptions}, like so:38 *39 * <pre>40 *FirefoxOptions options = new FirefoxOptions()41 *    .setProfile(new FirefoxProfile());42 *WebDriver driver = new FirefoxDriver(options);43 * </pre>44 */45public class FirefoxDriver extends RemoteWebDriver {46  public static final class SystemProperty {47    /**48     * System property that defines the location of the Firefox executable file.49     */50    public static final String BROWSER_BINARY = "webdriver.firefox.bin";51    /**52     * System property that defines the location of the file where Firefox log should be stored.53     */54    public static final String BROWSER_LOGFILE = "webdriver.firefox.logfile";55    /**56     * System property that defines the additional library path (Linux only).57     */58    public static final String BROWSER_LIBRARY_PATH = "webdriver.firefox.library.path";59    /**60     * System property that defines the profile that should be used as a template.61     * When the driver starts, it will make a copy of the profile it is using,62     * rather than using that profile directly.63     */64    public static final String BROWSER_PROFILE = "webdriver.firefox.profile";65    /**66     * System property that defines the location of the webdriver.xpi browser extension to install67     * in the browser. If not set, the prebuilt extension bundled with this class will be used.68     */69    public static final String DRIVER_XPI_PROPERTY = "webdriver.firefox.driver";70    /**71     * Boolean system property that instructs FirefoxDriver to use Marionette backend,72     * overrides any capabilities specified by the user73     */74    public static final String DRIVER_USE_MARIONETTE = "webdriver.firefox.marionette";75  }76  private static final Logger LOG = Logger.getLogger(FirefoxDriver.class.getName());77  public static final String BINARY = "firefox_binary";78  public static final String PROFILE = "firefox_profile";79  public static final String MARIONETTE = "marionette";80  protected FirefoxBinary binary;81  public FirefoxDriver() {82    this(new FirefoxOptions());83  }84  public FirefoxDriver(FirefoxOptions options) {85    this(toExecutor(options), options.toCapabilities(), options.toCapabilities());86  }87  /**88   * @deprecated Prefer {@link FirefoxOptions#setBinary(FirefoxBinary)}.89   */90  @Deprecated91  public FirefoxDriver(FirefoxBinary binary) {92    this(new FirefoxOptions().setBinary(binary));93    warnAboutDeprecatedConstructor("FirefoxBinary", "setBinary(binary)");94  }95  /**96   * @deprecated Prefer {@link FirefoxOptions#setProfile(FirefoxProfile)}.97   */98  @Deprecated99  public FirefoxDriver(FirefoxProfile profile) {100    this(new FirefoxOptions().setProfile(profile));101    warnAboutDeprecatedConstructor("FirefoxProfile", "setProfile(profile)");102  }103  /**104   * @deprecated Prefer {@link FirefoxOptions#setBinary(FirefoxBinary)}, and105   *   {@link FirefoxOptions#setProfile(FirefoxProfile)}.106   */107  @Deprecated108  public FirefoxDriver(FirefoxBinary binary, FirefoxProfile profile) {109    this(new FirefoxOptions().setBinary(binary).setProfile(profile));110    warnAboutDeprecatedConstructor(111        "FirefoxBinary and FirefoxProfile",112        "setBinary(binary).setProfile(profile)");113  }114  public FirefoxDriver(Capabilities desiredCapabilities) {115    this(new FirefoxOptions(desiredCapabilities).addCapabilities(desiredCapabilities));116  }117  /**118   * @deprecated Prefer {@link FirefoxDriver#FirefoxDriver(FirefoxOptions)}119   */120  @Deprecated121  public FirefoxDriver(Capabilities desiredCapabilities, Capabilities requiredCapabilities) {122    this(new FirefoxOptions(desiredCapabilities)123             .addCapabilities(desiredCapabilities)124             .addCapabilities(requiredCapabilities));125    warnAboutDeprecatedConstructor(126        "Capabilities, Capabilities",127        "addCapabilities(capabilities)");128  }129  /**130   * @deprecated Prefer {@link FirefoxOptions#setBinary(FirefoxBinary)},131   *   {@link FirefoxOptions#setProfile(FirefoxProfile)}132   */133  @Deprecated134  public FirefoxDriver(FirefoxBinary binary, FirefoxProfile profile, Capabilities capabilities) {135    this(new FirefoxOptions(capabilities)136             .setBinary(binary)137             .setProfile(profile)138             .addCapabilities(capabilities));139    warnAboutDeprecatedConstructor(140        "FirefoxBinary, FirefoxProfile, Capabilities",141        "setBinary(binary).setProfile(profile).addCapabilities(capabilities)");142  }143  /**144   * @deprecated Prefer {@link FirefoxOptions#setBinary(FirefoxBinary)},145   *   {@link FirefoxOptions#setProfile(FirefoxProfile)}146   */147  @Deprecated148  public FirefoxDriver(149      FirefoxBinary binary,150      FirefoxProfile profile,151      Capabilities desiredCapabilities,152      Capabilities requiredCapabilities) {153    this(new FirefoxOptions(desiredCapabilities)154             .setBinary(binary).setProfile(profile)155             .addCapabilities(desiredCapabilities)156             .addCapabilities(requiredCapabilities));157    warnAboutDeprecatedConstructor(158        "FirefoxBinary, FirefoxProfile, Capabilities",159        "setBinary(binary).setProfile(profile).addCapabilities(capabilities)");160  }161  private FirefoxDriver(162      CommandExecutor executor,163      Capabilities desiredCapabilities,164      Capabilities requiredCapabilities) {165    super(executor,166          dropCapabilities(desiredCapabilities).merge(dropCapabilities(requiredCapabilities)));167  }168  private static CommandExecutor toExecutor(FirefoxOptions options) {169    DriverService.Builder<?, ?> builder;170    if (options.isLegacy()) {171      builder = XpiDriverService.builder()172          .withBinary(options.getBinary())173          .withProfile(options.getProfile());174    } else {175      builder = new GeckoDriverService.Builder()176          .usingFirefoxBinary(options.getBinary());177    }178    return new DriverCommandExecutor(builder.build());179  }180  private void warnAboutDeprecatedConstructor(String arguments, String alternative) {181    LOG.warning(String.format(182        "The FirefoxDriver constructor taking %s has been deprecated. Please use the " +183        "FirefoxDriver(FirefoxOptions) constructor, configuring the FirefoxOptions like this: " +184        "new FirefoxOptions().%s",185        arguments,186        alternative));187  }188  @Override189  public void setFileDetector(FileDetector detector) {190    throw new WebDriverException(191        "Setting the file detector only works on remote webdriver instances obtained " +192        "via RemoteWebDriver");193  }194  private static boolean isLegacy(Capabilities desiredCapabilities) {195    Boolean forceMarionette = forceMarionetteFromSystemProperty();196    if (forceMarionette != null) {197      return !forceMarionette;198    }199    Object marionette = desiredCapabilities.getCapability(MARIONETTE);200    return marionette instanceof Boolean && ! (Boolean) marionette;201  }202  private static Boolean forceMarionetteFromSystemProperty() {203    String useMarionette = System.getProperty(DRIVER_USE_MARIONETTE);204    if (useMarionette == null) {205      return null;206    }207    return Boolean.valueOf(useMarionette);208  }209  /**210   * Drops capabilities that we shouldn't send over the wire.211   *212   * Used for capabilities which aren't BeanToJson-convertable, and are only used by the local213   * launcher.214   */215  private static Capabilities dropCapabilities(Capabilities capabilities) {216    if (capabilities == null) {217      return new DesiredCapabilities();218    }219    DesiredCapabilities caps;220    if (isLegacy(capabilities)) {221      final Set<String> toRemove = Sets.newHashSet(BINARY, PROFILE);222      caps = new DesiredCapabilities(223          Maps.filterKeys(capabilities.asMap(), key -> !toRemove.contains(key)));224    } else {225      caps = new DesiredCapabilities(capabilities);226    }227    // Ensure that the proxy is in a state fit to be sent to the extension228    Proxy proxy = Proxy.extractFrom(capabilities);229    if (proxy != null) {230      caps.setCapability(PROXY, proxy);231    }232    return caps;233  }234}...Source:ChromeDriver.java  
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.chrome;18import com.google.common.collect.ImmutableMap;19import org.openqa.selenium.Capabilities;20import org.openqa.selenium.WebDriver;21import org.openqa.selenium.WebDriverException;22import org.openqa.selenium.html5.LocalStorage;23import org.openqa.selenium.html5.Location;24import org.openqa.selenium.html5.LocationContext;25import org.openqa.selenium.html5.SessionStorage;26import org.openqa.selenium.html5.WebStorage;27import org.openqa.selenium.interactions.HasTouchScreen;28import org.openqa.selenium.interactions.TouchScreen;29import org.openqa.selenium.mobile.NetworkConnection;30import org.openqa.selenium.remote.FileDetector;31import org.openqa.selenium.remote.RemoteTouchScreen;32import org.openqa.selenium.remote.RemoteWebDriver;33import org.openqa.selenium.remote.html5.RemoteLocationContext;34import org.openqa.selenium.remote.html5.RemoteWebStorage;35import org.openqa.selenium.remote.mobile.RemoteNetworkConnection;36/**37 * A {@link WebDriver} implementation that controls a Chrome browser running on the local machine.38 * This class is provided as a convenience for easily testing the Chrome browser. The control server39 * which each instance communicates with will live and die with the instance.40 *41 * To avoid unnecessarily restarting the ChromeDriver server with each instance, use a42 * {@link RemoteWebDriver} coupled with the desired {@link ChromeDriverService}, which is managed43 * separately. For example: <pre>{@code44 *45 * import static org.junit.Assert.assertEquals;46 *47 * import org.junit.*;48 * import org.junit.runner.RunWith;49 * import org.junit.runners.JUnit4;50 * import org.openqa.selenium.chrome.ChromeDriverService;51 * import org.openqa.selenium.remote.DesiredCapabilities;52 * import org.openqa.selenium.remote.RemoteWebDriver;53 *54 * {@literal @RunWith(JUnit4.class)}55 * public class ChromeTest extends TestCase {56 *57 *   private static ChromeDriverService service;58 *   private WebDriver driver;59 *60 *   {@literal @BeforeClass}61 *   public static void createAndStartService() {62 *     service = new ChromeDriverService.Builder()63 *         .usingDriverExecutable(new File("path/to/my/chromedriver.exe"))64 *         .usingAnyFreePort()65 *         .build();66 *     service.start();67 *   }68 *69 *   {@literal @AfterClass}70 *   public static void createAndStopService() {71 *     service.stop();72 *   }73 *74 *   {@literal @Before}75 *   public void createDriver() {76 *     driver = new RemoteWebDriver(service.getUrl(),77 *         DesiredCapabilities.chrome());78 *   }79 *80 *   {@literal @After}81 *   public void quitDriver() {82 *     driver.quit();83 *   }84 *85 *   {@literal @Test}86 *   public void testGoogleSearch() {87 *     driver.get("http://www.google.com");88 *     WebElement searchBox = driver.findElement(By.name("q"));89 *     searchBox.sendKeys("webdriver");90 *     searchBox.quit();91 *     assertEquals("webdriver - Google Search", driver.getTitle());92 *   }93 * }94 * }</pre>95 *96 * Note that unlike ChromeDriver, RemoteWebDriver doesn't directly implement97 * role interfaces such as {@link LocationContext} and {@link WebStorage}.98 * Therefore, to access that functionality, it needs to be99 * {@link org.openqa.selenium.remote.Augmenter augmented} and then cast100 * to the appropriate interface.101 *102 * @see ChromeDriverService#createDefaultService103 */104public class ChromeDriver extends RemoteWebDriver105    implements LocationContext, WebStorage, HasTouchScreen, NetworkConnection {106  private RemoteLocationContext locationContext;107  private RemoteWebStorage webStorage;108  private TouchScreen touchScreen;109  private RemoteNetworkConnection networkConnection;110  /**111   * Creates a new ChromeDriver using the {@link ChromeDriverService#createDefaultService default}112   * server configuration.113   *114   * @see #ChromeDriver(ChromeDriverService, ChromeOptions)115   */116  public ChromeDriver() {117    this(ChromeDriverService.createDefaultService(), new ChromeOptions());118  }119  /**120   * Creates a new ChromeDriver instance. The {@code service} will be started along with the driver,121   * and shutdown upon calling {@link #quit()}.122   *123   * @param service The service to use.124   * @see RemoteWebDriver#RemoteWebDriver(org.openqa.selenium.remote.CommandExecutor, Capabilities)125   * @deprecated Use {@link RemoteWebDriver#RemoteWebDriver(org.openqa.selenium.remote.CommandExecutor, Capabilities)}126   */127  @Deprecated128  public ChromeDriver(ChromeDriverService service) {129    this(service, new ChromeOptions());130  }131  /**132   * Creates a new ChromeDriver instance. The {@code capabilities} will be passed to the133   * chromedriver service.134   *135   * @param capabilities The capabilities required from the ChromeDriver.136   * @see #ChromeDriver(ChromeDriverService, Capabilities)137   */138  public ChromeDriver(Capabilities capabilities) {139    this(ChromeDriverService.createDefaultService(), capabilities);140  }141  /**142   * Creates a new ChromeDriver instance with the specified options.143   *144   * @param options The options to use.145   * @see #ChromeDriver(ChromeDriverService, ChromeOptions)146   */147  public ChromeDriver(ChromeOptions options) {148    this(ChromeDriverService.createDefaultService(), options);149  }150  /**151   * Creates a new ChromeDriver instance with the specified options. The {@code service} will be152   * started along with the driver, and shutdown upon calling {@link #quit()}.153   *154   * @param service The service to use.155   * @param options The options to use.156   * @deprecated Use {@link RemoteWebDriver#RemoteWebDriver(org.openqa.selenium.remote.CommandExecutor, Capabilities)}157   */158  @Deprecated159  public ChromeDriver(ChromeDriverService service, ChromeOptions options) {160    this(service, options.toCapabilities());161  }162  /**163   * Creates a new ChromeDriver instance. The {@code service} will be started along with the164   * driver, and shutdown upon calling {@link #quit()}.165   *166   * @param service The service to use.167   * @param capabilities The capabilities required from the ChromeDriver.168   * @deprecated Use {@link RemoteWebDriver#RemoteWebDriver(org.openqa.selenium.remote.CommandExecutor, Capabilities)}169   */170  @Deprecated171  public ChromeDriver(ChromeDriverService service, Capabilities capabilities) {172    super(new ChromeDriverCommandExecutor(service), capabilities);173    locationContext = new RemoteLocationContext(getExecuteMethod());174    webStorage = new  RemoteWebStorage(getExecuteMethod());175    touchScreen = new RemoteTouchScreen(getExecuteMethod());176    networkConnection = new RemoteNetworkConnection(getExecuteMethod());177  }178  @Override179  public void setFileDetector(FileDetector detector) {180    throw new WebDriverException(181        "Setting the file detector only works on remote webdriver instances obtained " +182        "via RemoteWebDriver");183  }184  @Override185  public LocalStorage getLocalStorage() {186    return webStorage.getLocalStorage();187  }188  @Override189  public SessionStorage getSessionStorage() {190    return webStorage.getSessionStorage();191  }192  @Override193  public Location location() {194    return locationContext.location();195  }196  @Override197  public void setLocation(Location location) {198    locationContext.setLocation(location);199  }200  @Override201  public TouchScreen getTouch() {202    return touchScreen;203  }204  @Override205  public ConnectionType getNetworkConnection() {206    return networkConnection.getNetworkConnection();207  }208  @Override209  public ConnectionType setNetworkConnection(ConnectionType type) {210    return networkConnection.setNetworkConnection(type);211  }212  /**213   * Launches Chrome app specified by id.214   *215   * @param id chrome app id216   */217  public void launchApp(String id) {218    execute(ChromeDriverCommand.LAUNCH_APP, ImmutableMap.of("id", id));219  }220  221}...Source:ChromiumDriver.java  
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.Capabilities;20import org.openqa.selenium.WebDriver;21import org.openqa.selenium.WebDriverException;22import org.openqa.selenium.devtools.Connection;23import org.openqa.selenium.devtools.DevTools;24import org.openqa.selenium.devtools.HasDevTools;25import org.openqa.selenium.html5.LocalStorage;26import org.openqa.selenium.html5.Location;27import org.openqa.selenium.html5.LocationContext;28import org.openqa.selenium.html5.SessionStorage;29import org.openqa.selenium.html5.WebStorage;30import org.openqa.selenium.interactions.HasTouchScreen;31import org.openqa.selenium.interactions.TouchScreen;32import org.openqa.selenium.mobile.NetworkConnection;33import org.openqa.selenium.remote.CommandExecutor;34import org.openqa.selenium.remote.FileDetector;35import org.openqa.selenium.remote.RemoteTouchScreen;36import org.openqa.selenium.remote.RemoteWebDriver;37import org.openqa.selenium.remote.html5.RemoteLocationContext;38import org.openqa.selenium.remote.html5.RemoteWebStorage;39import org.openqa.selenium.remote.http.HttpClient;40import org.openqa.selenium.remote.mobile.RemoteNetworkConnection;41import java.util.Map;42import java.util.Objects;43import java.util.Optional;44/**45 * A {@link WebDriver} implementation that controls a Chromium browser running on the local machine.46 * This class is provided as a convenience for easily testing the Chromium browser. The control server47 * which each instance communicates with will live and die with the instance.48 *49 * To avoid unnecessarily restarting the ChromiumDriver server with each instance, use a50 * {@link RemoteWebDriver} coupled with the desired WebDriverService, which is managed51 * separately.52 *53 * Note that unlike ChromiumDriver, RemoteWebDriver doesn't directly implement54 * role interfaces such as {@link LocationContext} and {@link WebStorage}.55 * Therefore, to access that functionality, it needs to be56 * {@link org.openqa.selenium.remote.Augmenter augmented} and then cast57 * to the appropriate interface.58 */59public class ChromiumDriver extends RemoteWebDriver60    implements HasDevTools, HasTouchScreen, LocationContext, NetworkConnection, WebStorage {61  private final RemoteLocationContext locationContext;62  private final RemoteWebStorage webStorage;63  private final TouchScreen touchScreen;64  private final RemoteNetworkConnection networkConnection;65  private final Optional<Connection> connection;66  private final Optional<DevTools> devTools;67  protected ChromiumDriver(CommandExecutor commandExecutor, Capabilities capabilities, String capabilityKey) {68    super(commandExecutor, capabilities);69    locationContext = new RemoteLocationContext(getExecuteMethod());70    webStorage = new RemoteWebStorage(getExecuteMethod());71    touchScreen = new RemoteTouchScreen(getExecuteMethod());72    networkConnection = new RemoteNetworkConnection(getExecuteMethod());73    HttpClient.Factory factory = HttpClient.Factory.createDefault();74    connection = ChromiumDevToolsLocator.getChromeConnector(75        factory,76        getCapabilities(),77        capabilityKey);78    devTools = connection.map(DevTools::new);79  }80  @Override81  public void setFileDetector(FileDetector detector) {82    throw new WebDriverException(83        "Setting the file detector only works on remote webdriver instances obtained " +84        "via RemoteWebDriver");85  }86  @Override87  public LocalStorage getLocalStorage() {88    return webStorage.getLocalStorage();89  }90  @Override91  public SessionStorage getSessionStorage() {92    return webStorage.getSessionStorage();93  }94  @Override95  public Location location() {96    return locationContext.location();97  }98  @Override99  public void setLocation(Location location) {100    locationContext.setLocation(location);101  }102  @Override103  public TouchScreen getTouch() {104    return touchScreen;105  }106  @Override107  public ConnectionType getNetworkConnection() {108    return networkConnection.getNetworkConnection();109  }110  @Override111  public ConnectionType setNetworkConnection(ConnectionType type) {112    return networkConnection.setNetworkConnection(type);113  }114  /**115   * Launches Chrome app specified by id.116   *117   * @param id Chrome app id.118   */119  public void launchApp(String id) {120    execute(ChromiumDriverCommand.LAUNCH_APP, ImmutableMap.of("id", id));121  }122  /**123   * Execute a Chrome Devtools Protocol command and get returned result. The124   * command and command args should follow125   * <a href="https://chromedevtools.github.io/devtools-protocol/">chrome126   * devtools protocol domains/commands</a>.127   */128  public Map<String, Object> executeCdpCommand(String commandName, Map<String, Object> parameters) {129    Objects.requireNonNull(commandName, "Command name must be set.");130    Objects.requireNonNull(parameters, "Parameters for command must be set.");131    @SuppressWarnings("unchecked")132    Map<String, Object> toReturn = (Map<String, Object>) getExecuteMethod().execute(133        ChromiumDriverCommand.EXECUTE_CDP_COMMAND,134        ImmutableMap.of("cmd", commandName, "params", parameters));135    return ImmutableMap.copyOf(toReturn);136  }137  @Override138  public DevTools getDevTools() {139    return devTools.orElseThrow(() -> new WebDriverException("Unable to create DevTools connection"));140  }141  public String getCastSinks() {142    Object response =  getExecuteMethod().execute(ChromiumDriverCommand.GET_CAST_SINKS, null);143    return response.toString();144  }145  public String getCastIssueMessage() {146    Object response = getExecuteMethod().execute(ChromiumDriverCommand.GET_CAST_ISSUE_MESSAGE, null);147    return response.toString();148  }149  public void selectCastSink(String deviceName) {150    Object response =  getExecuteMethod().execute(ChromiumDriverCommand.SET_CAST_SINK_TO_USE, ImmutableMap.of("sinkName", deviceName));151  }152  public void startTabMirroring(String deviceName) {153    Object response =  getExecuteMethod().execute(ChromiumDriverCommand.START_CAST_TAB_MIRRORING, ImmutableMap.of("sinkName", deviceName));154  }155  public void stopCasting(String deviceName) {156    Object response = getExecuteMethod().execute(ChromiumDriverCommand.STOP_CASTING, ImmutableMap.of("sinkName", deviceName));157  }158  public void setPermission(String name, String value) {159    Object response = getExecuteMethod().execute(ChromiumDriverCommand.SET_PERMISSION,160      ImmutableMap.of("descriptor", ImmutableMap.of("name", name), "state", value));161  }162  @Override163  public void quit() {164    connection.ifPresent(Connection::close);165    super.quit();166  }167}...Source:MobileDriverProvider.java  
1/*-------------------------------------------------------------------------------------------------------------------*\2|  Copyright (C) 2016 PayPal                                                                                          |3|                                                                                                                     |4|  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance     |5|  with the License.                                                                                                  |6|                                                                                                                     |7|  You may obtain a copy of the License at                                                                            |8|                                                                                                                     |9|       http://www.apache.org/licenses/LICENSE-2.0                                                                    |10|                                                                                                                     |11|  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed   |12|  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for  |13|  the specific language governing permissions and limitations under the License.                                     |14\*-------------------------------------------------------------------------------------------------------------------*/15package com.paypal.selion.platform.grid;16import com.paypal.selion.internal.platform.grid.MobileNodeType;17import com.paypal.selion.internal.platform.grid.WebDriverPlatform;18import com.paypal.selion.platform.grid.browsercapabilities.DefaultCapabilitiesBuilder;19import org.openqa.selenium.Capabilities;20import org.openqa.selenium.remote.CommandExecutor;21import org.openqa.selenium.remote.RemoteWebDriver;22import java.net.URL;23/**24 * A service provider interface that mobile driver providers for SeLion client (that use IOSDriver, Selendroid25 * or Appium etc.) must implement.26 * <p>27 * This is a service loaded extension for SeLion client mobile driver providers.28 */29public interface MobileDriverProvider {30    /**31     * @return <code>true</code> If mobile driver provider implementation supports the specified {@link MobileNodeType}.32     */33    boolean supports(MobileNodeType nodeType);34    /**35     * Creates an instance of a RemoteWebDriver using mobile driver implementation36     *37     * @return An instance of a {@link RemoteWebDriver} for the mobile driver implementation.38     */39    RemoteWebDriver createDriver(WebDriverPlatform platform, CommandExecutor commandExecutor, URL url,40                                 Capabilities capabilities);41    /**42     * Creates an instance of a CapabilitiesBuilder for mobile driver implementation43     *44     * @return An instance of a {@link DefaultCapabilitiesBuilder} for the mobile driver implementation.45     */46    DefaultCapabilitiesBuilder capabilityBuilder();47}...Source:IPhoneDriver.java  
1/*2Copyright 2007-2009 WebDriver committers3Copyright 2007-2009 Google Inc.4Licensed under the Apache License, Version 2.0 (the "License");5you may not use this file except in compliance with the License.6You may obtain a copy of the License at7     http://www.apache.org/licenses/LICENSE-2.08Unless required by applicable law or agreed to in writing, software9distributed under the License is distributed on an "AS IS" BASIS,10WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11See the License for the specific language governing permissions and12limitations under the License.13*/14package org.openqa.selenium.iphone;15import java.net.URL;16import org.openqa.selenium.remote.Capabilities;17import org.openqa.selenium.remote.CommandExecutor;18import org.openqa.selenium.remote.RemoteWebDriver;19/**20 * IPhoneDriver is a driver for running tests on Mobile Safari on the iPhone / iPod Touch.21 * 22 * The driver uses WebDriver's remote REST interface to communicate with the23 * iphone. The iphone (or iphone simulator) must run the iWebDriver app.24 */25public class IPhoneDriver extends RemoteWebDriver {26  public IPhoneDriver(CommandExecutor executor, Capabilities desiredCapabilities) {27    super(executor, desiredCapabilities);28  }29  public IPhoneDriver(Capabilities desiredCapabilities) throws Exception {30    super(desiredCapabilities);31  }32  public IPhoneDriver(URL remoteAddress, Capabilities desiredCapabilities)33  	    throws Exception {34    super(remoteAddress, desiredCapabilities);35  }36}...Source:WebDriver.java  
1package com.testpros.fast;2import com.testpros.fast.reporter.Reporter;3import io.appium.java_client.service.local.AppiumServiceBuilder;4import org.openqa.selenium.Capabilities;5import org.openqa.selenium.MutableCapabilities;6import org.openqa.selenium.remote.CommandExecutor;7import org.openqa.selenium.remote.http.HttpClient;8import org.openqa.selenium.remote.service.DriverService;9import java.net.URL;10import java.util.List;11public interface WebDriver extends org.openqa.selenium.WebDriver {12    org.openqa.selenium.WebDriver getDriver();13    Capabilities getCapabilities();14    DriverService getService();15    MutableCapabilities getOptions();16    CommandExecutor getExecutor();17    URL getRemoteAddress();18    HttpClient.Factory getHttpClientFactory();19    AppiumServiceBuilder getBuilder();20    int getPort();21    Reporter getReporter();22    List<WebElement> findElements(By by);23    WebElement findElement(By by);24    boolean isElementPresent(By by);25    void waitForElementPresent(By by);26}...Interface CommandExecutor
Using AI Code Generation
1import org.openqa.selenium.remote.CommandExecutor;2import org.openqa.selenium.remote.RemoteWebDriver;3import org.openqa.selenium.remote.Response;4import org.openqa.selenium.remote.http.HttpClient;5import org.openqa.selenium.remote.http.HttpRequest;6import org.openqa.selenium.remote.http.HttpResponse;7public class Test {8    public static void main(String[] args) {9        RemoteWebDriver driver = new RemoteWebDriver(new CommandExecutor() {10            public Response execute(Command command) throws IOException {11                return null;12            }13        });14        driver.quit();15    }16}17  (unknown error: DevToolsActivePort file doesn't exist)18  (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)19  (Driver info: chromedriver=2.41.578700 (0ecf3c3a7a3b9c9f7e8f8a1e7a0d6c7b7a8b8f0b),platform=Linux 4.4.0-109-generic x86_64) (WARNING: The server did not provide any stacktrace information)Interface CommandExecutor
Using AI Code Generation
1import org.openqa.selenium.remote.CommandExecutor;2import org.openqa.selenium.remote.HttpCommandExecutor;3import org.openqa.selenium.remote.Response;4import org.openqa.selenium.remote.internal.OkHttpClient;5import org.openqa.selenium.remote.internal.OkHttpClientFactory;6import java.net.MalformedURLException;7import java.net.URL;8public class Selenium4RemoteDriver {9    public static void main(String[] args) throws MalformedURLException {10        Response response = executor.execute("getStatus", null);11        System.out.println(response);12        System.out.println(response.getStatus());13        System.out.println(response.getSessionId());14        System.out.println(response.getValue());15        System.out.println(response.getValue().getClass());16        System.out.println(response.getValue().getClass().getName());17        System.out.println(response.getValue().getClass().getCanonicalName());18        System.out.println(response.getValue().getClass().getTypeName());19        System.out.println(response.getValue().getClass().getSimpleName());20    }21}22{state=success, sessionId=null, hCode=1398000559, value={build={revision=2c5a1ee, time=2020-08-19T18:06:48, version=4.0.0-alpha-4}, os={arch=amd64, name=Mac OS X, version=10.15.6}, os.name=Mac OS X, os.arch=amd64, os.version=10.15.6, java={version=11.0.8}, java.version=11.0.8, seleniumProtocol=WebDriver}}23{build={revision=2c5a1ee, time=2020-08-19T18:06:48, version=4.0.0-alpha-4}, os={arch=amd64, name=Mac OS X, version=10.15.6},Interface CommandExecutor
Using AI Code Generation
1import org.openqa.selenium.remote.CommandExecutor;2import org.openqa.selenium.remote.Command;3import org.openqa.selenium.remote.Response;4import org.openqa.selenium.remote.HttpCommandExecutor;5import org.openqa.selenium.remote.DesiredCapabilities;6import org.openqa.selenium.remote.RemoteWebDriver;7import org.openqa.selenium.WebDriver;8import org.openqa.selenium.By;9import org.openqa.selenium.WebElement;10import org.openqa.selenium.JavascriptExecutor;11import org.openqa.selenium.chrome.ChromeDriver;12import org.openqa.selenium.chrome.ChromeOptions;13import org.openqa.selenium.chrome.ChromeDriverService;14import org.openqa.selenium.WebDriverException;15import org.openqa.selenium.NoSuchElementException;16import org.openqa.selenium.TimeoutException;17import org.openqa.selenium.support.ui.WebDriverWait;18import org.openqa.selenium.support.ui.ExpectedConditions;19import org.openqa.selenium.WebDriverException;20import org.openqa.selenium.remote.SessionId;21import org.openqa.selenium.remote.RemoteWebDriver;22import org.openqa.selenium.remote.SessionNotFoundException;23import org.openqa.selenium.remote.UnreachableBrowserException;24import org.openqa.selenium.remote.ErrorHandler;25import org.openqa.selenium.remote.ErrorCodes;26import org.openqa.selenium.remote.ErrorHandler.UnknownServerException;27import org.openqa.selenium.remote.ErrorHandler.UnknownMethodException;28import org.openqa.selenium.remote.ErrorHandler.WebDriverException;29import org.openqa.selenium.remote.ErrorHandler.UnhandledAlertException;30import org.openqa.selenium.remote.ErrorHandler.NoSuchElement;31import org.openqa.selenium.remote.ErrorHandler.NoSuchFrame;32import org.openqa.selenium.remote.ErrorHandler.NoSuchWindow;33import org.openqa.selenium.remote.ErrorHandler.StaleElementReference;34import org.openqa.selenium.remote.ErrorHandler.ElementNotVisible;35import org.openqa.selenium.remote.ErrorHandler.InvalidElementState;36import org.openqa.selenium.remote.ErrorHandler.ElementIsNotSelectable;37import org.openqa.selenium.remote.ErrorHandler.ElementNotInteractable;38import org.openqa.selenium.remote.ErrorHandler.ElementNotSelectable;39import org.openqa.selenium.remote.ErrorHandler.NoSuchDocument;40import org.openqa.selenium.remote.ErrorHandler.InvalidCookieDomain;41import org.openqa.selenium.remote.ErrorHandler.UnableToSetCookie;42import org.openqa.selenium.remote.ErrorHandler.UnexpectedAlertOpen;43import org.openqa.selenium.remote.ErrorHandler.NoAlertPresent;44import org.openqa.selenium.remote.ErrorHandler.ScriptTimeout;45import org.openqa.selenium.remote.ErrorHandler.InvalidElementCoordinates;46import org.openqa.selenium.remote.ErrorHandler.IMEEngineActivationFailed;47import org.openqa.selenium.remote.ErrorHandler.IMENotAvailable;48import org.openqa.selenium.remote.ErrorHandler.InvalidSelector;49import org.openqa.selenium.remote.ErrorHandler.SessionNotCreatedException;50import org.openqa.selenium.remote.ErrorHandler.MoveTargetOutOfBounds;51import org.openqa.selenium.remote.ErrorHandler.NoSuchCollection;52import org.openqa.selenium.remote.ErrorHandlerInterface CommandExecutor
Using AI Code Generation
1package seleniumBasic;2import org.openqa.selenium.By;3import org.openqa.selenium.WebDriver;4import org.openqa.selenium.WebElement;5import org.openqa.selenium.chrome.ChromeDriver;6public class SeleniumTest {7public static void main(String[] args) {8	System.setProperty("webdriver.chrome.driver", "C:\\Users\\Dell\\Downloads\\chromedriver_win32\\chromedriver.exe");9	WebDriver driver = new ChromeDriver();10	WebElement email = driver.findElement(By.id("email"));11	email.sendKeys("Interface CommandExecutor
Using AI Code Generation
1import org.openqa.selenium.remote.CommandExecutor;2import org.openqa.selenium.remote.Command;3import org.openqa.selenium.remote.Response;4import org.openqa.selenium.remote.DesiredCapabilities;5import org.openqa.selenium.remote.RemoteWebDriver;6import org.openqa.selenium.remote.HttpCommandExecutor;7import org.openqa.selenium.WebDriver;8import org.openqa.selenium.By;9import org.openqa.selenium.WebElement;10import org.openqa.selenium.JavascriptExecutor;11import org.openqa.selenium.interactions.Actions;12import org.openqa.selenium.support.ui.ExpectedConditions;13import org.openqa.selenium.support.ui.WebDriverWait;14import org.openqa.selenium.support.ui.Select;15import java.util.ArrayList;16import java.util.List;17import java.util.concurrent.TimeUnit;18import java.net.URL;19import java.net.MalformedURLException;20import java.io.File;21import java.io.FileInputStream;22import java.io.FileNotFoundException;23import java.io.IOException;24import java.io.InputStream;25import java.io.OutputStream;26import java.io.OutputStreamWriter;27import java.io.PrintWriter;28import java.io.InputStreamReader;29import java.io.BufferedReader;30import java.io.BufferedWriter;31import java.io.FileWriter;32import java.io.StringReader;33import java.io.StringWriter;34import java.io.Writer;35import java.io.Reader;36import java.io.ByteArrayInputStream;37import java.io.ByteArrayOutputStream;38import java.util.Properties;39import org.apache.commons.io.FileUtils;40import org.openqa.selenium.OutputType;41import org.openqa.selenium.TakesScreenshot;42import org.openqa.selenium.chrome.ChromeDriver;43import org.openqa.selenium.chrome.ChromeOptions;44import org.openqa.selenium.firefox.FirefoxDriver;45import org.openqa.selenium.firefox.FirefoxProfile;46import org.openqa.selenium.ie.InternetExplorerDriver;47import org.openqa.selenium.edge.EdgeDriver;48import org.openqa.selenium.opera.OperaDriver;49import org.openqa.selenium.opera.OperaOptions;50import org.openqa.selenium.safari.SafariDriver;51import org.openqa.selenium.safari.SafariOptions;52import org.openqa.selenium.htmlunit.HtmlUnitDriver;53import org.openqa.selenium.phantomjs.PhantomJSDriver;54import org.openqa.selenium.phantomjs.PhantomJSDriverService;55import org.openqa.selenium.remote.CapabilityType;56import org.openqa.selenium.remote.DesiredCapabilities;57import org.openqa.selenium.remote.SessionId;58import org.openqa.selenium.remote.service.DriverService;59import org.openqa.selenium.remote.service.DriverCommandExecutor;60import org.openqa.selenium.remote.service.DriverCommandExecutorService;61import org.openqa.selenium.remote.service.DriverService.Builder;62import org.openqa.selenium.remote.service.DriverService.Builder.DriverServiceBuilder;63import org.openqa.selenium.remote.service.DriverService.DriverServiceBuilder;64import org.openqaInterface CommandExecutor
Using AI Code Generation
1import java.util.HashMap;2import java.util.Map;3import org.openqa.selenium.remote.Command;4import org.openqa.selenium.remote.CommandExecutor;5import org.openqa.selenium.remote.Response;6public class CommandExecutorExample {7    public static void main(String[] args) {8        Map<String, Object> params = new HashMap<String, Object>();9        params.put("commandName", "open");10        Command command = new Command(null, params);11        CommandExecutor commandExecutor = new CommandExecutor() {12            public Response execute(Command command) {13                Response response = new Response();14                response.setStatus(0);15                response.setValue("Command executed successfully");16                return response;17            }18        };19        Response response = commandExecutor.execute(command);20        int status = response.getStatus();21        String value = (String) response.getValue();22        System.out.println("Status of the response: " + status);23        System.out.println("Value of the response: " + value);24    }25}1 @Bean2public CommonsRequestLoggingFilter requestLoggingFilter() {3...4}5LambdaTest’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.
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.
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.
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.
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.
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.
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.
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.
LambdaTest also provides certification for Selenium testing to accelerate your career in Selenium automation testing.
Get 100 minutes of automation test minutes FREE!!
