org.openqa.selenium.remote.CommandInfo Java Examples

The following examples show how to use org.openqa.selenium.remote.CommandInfo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BrowserRunnerHelper.java    From neodymium-library with MIT License 6 votes vote down vote up
/**
 * Returns an {@link HttpCommandExecutor} to a Selenium grid (e.g. SauceLabs) that contains basic authentication for
 * access
 * 
 * @param testEnvironment
 *            The {@link TestEnvironment} to the grid
 * @return {@link HttpCommandExecutor} to Selenium grid augmented with credentials
 * @throws MalformedURLException
 *             if the given gridUrl is invalid
 */
protected static HttpCommandExecutor createGridExecutor(String testEnvironment) throws MalformedURLException

{
    TestEnvironment testEnvironmentProperties = MultibrowserConfiguration.getInstance().getTestEnvironment(testEnvironment);

    if (testEnvironmentProperties == null)
    {
        throw new IllegalArgumentException("No properties found for test environment: \"" + testEnvironment + "\"");
    }

    final Map<String, CommandInfo> additionalCommands = new HashMap<String, CommandInfo>(); // just a dummy

    URL gridUrl = new URL(testEnvironmentProperties.getUrl());
    return new HttpCommandExecutor(additionalCommands, gridUrl, new NeodymiumProxyHttpClientFactory(testEnvironmentProperties));
}
 
Example #2
Source File: Browser.java    From selenium-shutterbug with MIT License 6 votes vote down vote up
public BufferedImage takeScreenshotEntirePageUsingChromeCommand() {
    //should use devicePixelRatio by default as chrome command executor makes screenshot account for that
    Object devicePixelRatio = executeJsScript(DEVICE_PIXEL_RATIO);
    this.devicePixelRatio = devicePixelRatio instanceof Double ? (Double) devicePixelRatio : (Long) devicePixelRatio * 1.0;

    defineCustomCommand("sendCommand", new CommandInfo("/session/:sessionId/chromium/send_command_and_get_result", HttpMethod.POST));

    int verticalIterations = (int) Math.ceil(((double) this.getDocHeight()) / this.getViewportHeight());
    for (int j = 0; j < verticalIterations; j++) {
        this.scrollTo(0, j * this.getViewportHeight());
        wait(betweenScrollTimeout);
    }
    Object metrics = this.evaluate(FileUtil.getJsScript(ALL_METRICS));
    this.sendCommand("Emulation.setDeviceMetricsOverride", metrics);
    wait(beforeShootCondition,beforeShootTimeout);
    Object result = this.sendCommand("Page.captureScreenshot", ImmutableMap.of("format", "png", "fromSurface", true));
    this.sendCommand("Emulation.clearDeviceMetricsOverride", ImmutableMap.of());
    return decodeBase64EncodedPng((String) ((Map<String, ?>) result).get("data"));
}
 
Example #3
Source File: Browser.java    From selenium-shutterbug with MIT License 6 votes vote down vote up
public BufferedImage takeScreenshotEntirePageUsingGeckoDriver() {
    // Check geckodriver version (>= 0.24.0 is requried)
    String version = (String) ((RemoteWebDriver) driver).getCapabilities().getCapability("moz:geckodriverVersion");
    if (version == null || Version.valueOf(version).satisfies("<0.24.0")) {
        return takeScreenshotEntirePageDefault();
    }
    defineCustomCommand("mozFullPageScreenshot", new CommandInfo("/session/:sessionId/moz/screenshot/full", HttpMethod.GET));
    Object result = this.executeCustomCommand("mozFullPageScreenshot");
    String base64EncodedPng;
    if (result instanceof String) {
        base64EncodedPng = (String) result;
    } else if (result instanceof byte[]) {
        base64EncodedPng = new String((byte[]) result);
    } else {
        throw new RuntimeException(String.format("Unexpected result for /moz/screenshot/full command: %s",
            result == null ? "null" : result.getClass().getName() + "instance"));
    }
    return decodeBase64EncodedPng(base64EncodedPng);
}
 
Example #4
Source File: Browser.java    From selenium-shutterbug with MIT License 5 votes vote down vote up
private void defineCustomCommand(String name, CommandInfo info) {
    try {
        Method defineCommand = HttpCommandExecutor.class.getDeclaredMethod("defineCommand", String.class, CommandInfo.class);
        defineCommand.setAccessible(true);
        defineCommand.invoke(((RemoteWebDriver) this.driver).getCommandExecutor(), name, info);
    } catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {
        throw new RuntimeException(e);
    }
}
 
Example #5
Source File: AppiumCommandExecutor.java    From java-client with Apache License 2.0 5 votes vote down vote up
private AppiumCommandExecutor(Map<String, CommandInfo> additionalCommands, DriverService service,
                              URL addressOfRemoteServer,
                              HttpClient.Factory httpClientFactory) {
    super(additionalCommands,
            ofNullable(service)
                    .map(DriverService::getUrl)
                    .orElse(addressOfRemoteServer), httpClientFactory);
    serviceOptional = ofNullable(service);
}
 
Example #6
Source File: ChromiumDriverCommandExecutor.java    From selenium with Apache License 2.0 5 votes vote down vote up
private static Map<String, CommandInfo> buildChromiumCommandMappings(String vendorKeyword) {
  String sessionPrefix = "/session/:sessionId/";
  String chromiumPrefix = sessionPrefix + "chromium";
  String vendorPrefix = sessionPrefix + vendorKeyword;

  HashMap<String, CommandInfo> mappings = new HashMap<>();

  mappings.put(ChromiumDriverCommand.LAUNCH_APP,
    new CommandInfo(chromiumPrefix + "/launch_app", HttpMethod.POST));

  String networkConditions = chromiumPrefix + "/network_conditions";
  mappings.put(ChromiumDriverCommand.GET_NETWORK_CONDITIONS,
    new CommandInfo(networkConditions, HttpMethod.GET));
  mappings.put(ChromiumDriverCommand.SET_NETWORK_CONDITIONS,
    new CommandInfo(networkConditions, HttpMethod.POST));
  mappings.put(ChromiumDriverCommand.DELETE_NETWORK_CONDITIONS,
    new CommandInfo(networkConditions, HttpMethod.DELETE));

  mappings.put( ChromiumDriverCommand.EXECUTE_CDP_COMMAND,
    new CommandInfo(vendorPrefix + "/cdp/execute", HttpMethod.POST));

  // Cast / Media Router APIs
  String cast = vendorPrefix + "/cast";
  mappings.put(ChromiumDriverCommand.GET_CAST_SINKS,
    new CommandInfo(cast + "/get_sinks", HttpMethod.GET));
  mappings.put(ChromiumDriverCommand.SET_CAST_SINK_TO_USE,
    new CommandInfo(cast + "/set_sink_to_use", HttpMethod.POST));
  mappings.put(ChromiumDriverCommand.START_CAST_TAB_MIRRORING,
    new CommandInfo(cast + "/start_tab_mirroring", HttpMethod.POST));
  mappings.put(ChromiumDriverCommand.GET_CAST_ISSUE_MESSAGE,
    new CommandInfo(cast + "/get_issue_message", HttpMethod.GET));
  mappings.put(ChromiumDriverCommand.STOP_CASTING,
    new CommandInfo(cast + "/stop_casting", HttpMethod.POST));

  mappings.put(ChromiumDriverCommand.SET_PERMISSION,
    new CommandInfo(sessionPrefix + "/permissions", HttpMethod.POST));

  return unmodifiableMap(mappings);
}
 
Example #7
Source File: EventFiringAppiumCommandExecutor.java    From carina with Apache License 2.0 5 votes vote down vote up
private EventFiringAppiumCommandExecutor(Map<String, CommandInfo> additionalCommands, DriverService service,
        URL addressOfRemoteServer,
        HttpClient.Factory httpClientFactory) {
    super(additionalCommands,
            ofNullable(service)
                    .map(DriverService::getUrl)
                    .orElse(addressOfRemoteServer),
            httpClientFactory);
    serviceOptional = ofNullable(service);
}
 
Example #8
Source File: EventFiringAppiumCommandExecutor.java    From carina with Apache License 2.0 4 votes vote down vote up
private Map<String, CommandInfo> getAdditionalCommands() {
    // noinspection unchecked
    return getPrivateFieldValue("additionalCommands", Map.class);
}
 
Example #9
Source File: WebDriverManager.java    From QVisual with Apache License 2.0 4 votes vote down vote up
private static void setCommand(CommandExecutor executor) throws Exception {
    CommandInfo cmd = new CommandInfo("/session/:sessionId/chromium/send_command_and_get_result", POST);
    Method defineCommand = HttpCommandExecutor.class.getDeclaredMethod("defineCommand", String.class, CommandInfo.class);
    defineCommand.setAccessible(true);
    defineCommand.invoke(executor, "sendCommand", cmd);
}
 
Example #10
Source File: EventFiringAppiumCommandExecutor.java    From carina with Apache License 2.0 4 votes vote down vote up
public EventFiringAppiumCommandExecutor(Map<String, CommandInfo> additionalCommands,
        DriverService service) {
    this(additionalCommands, service, new HttpClientFactoryCustom());
}
 
Example #11
Source File: EventFiringAppiumCommandExecutor.java    From carina with Apache License 2.0 4 votes vote down vote up
public EventFiringAppiumCommandExecutor(Map<String, CommandInfo> additionalCommands,
        URL addressOfRemoteServer) {
    this(additionalCommands, addressOfRemoteServer, new HttpClientFactoryCustom());
}
 
Example #12
Source File: EventFiringAppiumCommandExecutor.java    From carina with Apache License 2.0 4 votes vote down vote up
public EventFiringAppiumCommandExecutor(Map<String, CommandInfo> additionalCommands,
        URL addressOfRemoteServer, HttpClient.Factory httpClientFactory) {
    this(additionalCommands, null, checkNotNull(addressOfRemoteServer), httpClientFactory);
}
 
Example #13
Source File: EventFiringAppiumCommandExecutor.java    From carina with Apache License 2.0 4 votes vote down vote up
public EventFiringAppiumCommandExecutor(Map<String, CommandInfo> additionalCommands, DriverService service,
        HttpClient.Factory httpClientFactory) {
    this(additionalCommands, checkNotNull(service), null, httpClientFactory);
}
 
Example #14
Source File: AppiumCommandExecutor.java    From java-client with Apache License 2.0 4 votes vote down vote up
protected Map<String, CommandInfo> getAdditionalCommands() {
    //noinspection unchecked
    return getPrivateFieldValue("additionalCommands", Map.class);
}
 
Example #15
Source File: AppiumCommandExecutor.java    From java-client with Apache License 2.0 4 votes vote down vote up
public AppiumCommandExecutor(Map<String, CommandInfo> additionalCommands,
                             DriverService service) {
    this(additionalCommands, service, HttpClient.Factory.createDefault());
}
 
Example #16
Source File: AppiumCommandExecutor.java    From java-client with Apache License 2.0 4 votes vote down vote up
public AppiumCommandExecutor(Map<String, CommandInfo> additionalCommands,
                             URL addressOfRemoteServer) {
    this(additionalCommands, addressOfRemoteServer, HttpClient.Factory.createDefault());
}
 
Example #17
Source File: AppiumCommandExecutor.java    From java-client with Apache License 2.0 4 votes vote down vote up
public AppiumCommandExecutor(Map<String, CommandInfo> additionalCommands,
                             URL addressOfRemoteServer, HttpClient.Factory httpClientFactory) {
    this(additionalCommands, null, checkNotNull(addressOfRemoteServer), httpClientFactory);
}
 
Example #18
Source File: AppiumCommandExecutor.java    From java-client with Apache License 2.0 4 votes vote down vote up
public AppiumCommandExecutor(Map<String, CommandInfo> additionalCommands, DriverService service,
                             HttpClient.Factory httpClientFactory) {
    this(additionalCommands, checkNotNull(service), null, httpClientFactory);
}
 
Example #19
Source File: DriverCommandExecutor.java    From selenium with Apache License 2.0 2 votes vote down vote up
/**
 * Creates an {@link DriverCommandExecutor} that supports non-standard
 * {@code additionalCommands} in addition to the standard.
 *
 * @param service driver server
 * @param additionalCommands additional commands the remote end can process
 */
protected DriverCommandExecutor(
    DriverService service, Map<String, CommandInfo> additionalCommands) {
  super(additionalCommands, service.getUrl());
  this.service = service;
}