org.openqa.selenium.remote.CommandExecutor Java Examples

The following examples show how to use org.openqa.selenium.remote.CommandExecutor. 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: OneShotNode.java    From selenium with Apache License 2.0 6 votes vote down vote up
private HttpClient extractHttpClient(RemoteWebDriver driver) {
  CommandExecutor executor = driver.getCommandExecutor();

  try {
    Field client = null;
    Class<?> current = executor.getClass();
    while (client == null && (current != null || Object.class.equals(current))) {
      client = findClientField(current);
      current = current.getSuperclass();
    }

    if (client == null) {
      throw new IllegalStateException("Unable to find client field in " + executor.getClass());
    }

    if (!HttpClient.class.isAssignableFrom(client.getType())) {
      throw new IllegalStateException("Client field is not assignable to http client");
    }
    client.setAccessible(true);
    return (HttpClient) client.get(executor);
  } catch (ReflectiveOperationException e) {
    throw new IllegalStateException(e);
  }
}
 
Example #2
Source File: RemoteSession.java    From selenium with Apache License 2.0 6 votes vote down vote up
protected RemoteSession(
    Dialect downstream,
    Dialect upstream,
    HttpHandler codec,
    SessionId id,
    Map<String, Object> capabilities) {
  this.downstream = Require.nonNull("Downstream dialect", downstream);
  this.upstream = Require.nonNull("Upstream dialect", upstream);
  this.codec = Require.nonNull("Codec", codec);
  this.id = Require.nonNull("Session id", id);
  this.capabilities = Require.nonNull("Capabilities", capabilities);

  File tempRoot = new File(StandardSystemProperty.JAVA_IO_TMPDIR.value(), id.toString());
  Require.stateCondition(tempRoot.mkdirs(), "Could not create directory %s", tempRoot);
  this.filesystem = TemporaryFilesystem.getTmpFsBasedOn(tempRoot);

  CommandExecutor executor = new ActiveSessionCommandExecutor(this);
  this.driver = new Augmenter().augment(new RemoteWebDriver(
      executor,
      new ImmutableCapabilities(getCapabilities())));
}
 
Example #3
Source File: WebDriverWaitTest.java    From selenium with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldIncludeRemoteInfoForWrappedDriverTimeout() throws IOException {
  Capabilities caps = new MutableCapabilities();
  Response response = new Response(new SessionId("foo"));
  response.setValue(caps.asMap());
  CommandExecutor executor = mock(CommandExecutor.class);
  when(executor.execute(any(Command.class))).thenReturn(response);

  RemoteWebDriver driver = new RemoteWebDriver(executor, caps);
  WebDriver testDriver = mock(WebDriver.class, withSettings().extraInterfaces(WrapsDriver.class));
  when(((WrapsDriver) testDriver).getWrappedDriver()).thenReturn(driver);

  TickingClock clock = new TickingClock();
  WebDriverWait wait =
      new WebDriverWait(testDriver, Duration.ofSeconds(1), Duration.ofMillis(200), clock, clock);

  assertThatExceptionOfType(TimeoutException.class)
      .isThrownBy(() -> wait.until(d -> false))
      .withMessageContaining("Capabilities {javascriptEnabled: true, platform: ANY, platformName: ANY}")
      .withMessageContaining("Session ID: foo");
}
 
Example #4
Source File: FirefoxDriverTest.java    From selenium with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldGetMeaningfulExceptionOnBrowserDeath() throws Exception {
  FirefoxDriver driver2 = new FirefoxDriver();
  driver2.get(pages.formPage);

  // Grab the command executor
  CommandExecutor keptExecutor = driver2.getCommandExecutor();
  SessionId sessionId = driver2.getSessionId();

  try {
    Field field = RemoteWebDriver.class.getDeclaredField("executor");
    field.setAccessible(true);
    CommandExecutor spoof = mock(CommandExecutor.class);
    doThrow(new IOException("The remote server died"))
        .when(spoof).execute(ArgumentMatchers.any());

    field.set(driver2, spoof);

    driver2.get(pages.formPage);
    fail("Should have thrown.");
  } catch (UnreachableBrowserException e) {
    assertThat(e.getMessage()).contains("Error communicating with the remote browser");
  } finally {
    keptExecutor.execute(new Command(sessionId, DriverCommand.QUIT));
  }
}
 
Example #5
Source File: PtlIPhoneDriver.java    From hifive-pitalium with Apache License 2.0 6 votes vote down vote up
/**
 * コンストラクタ
 *
 * @param executor CommandExecutor
 * @param capabilities Capability
 */
PtlIPhoneDriver(CommandExecutor executor, PtlCapabilities capabilities) {
	super(executor, capabilities);

	Object headerHeightCapability = capabilities.getCapability("headerHeight");
	if (headerHeightCapability == null) {
		throw new TestRuntimeException("Capability \"headerHeight\" is required");
	} else {
		if (headerHeightCapability instanceof Number) {
			headerHeight = ((Number) headerHeightCapability).intValue();
		} else {
			headerHeight = Integer.parseInt(headerHeightCapability.toString());
		}
	}

	Object footerHeightCapability = capabilities.getCapability("footerHeight");
	if (footerHeightCapability == null) {
		throw new TestRuntimeException("Capability \"footerHeight\" is required");
	} else {
		if (footerHeightCapability instanceof Number) {
			footerHeight = ((Number) footerHeightCapability).intValue();
		} else {
			footerHeight = Integer.parseInt(footerHeightCapability.toString());
		}
	}
}
 
Example #6
Source File: RemoteBrowserFactory.java    From aquality-selenium-java with Apache License 2.0 5 votes vote down vote up
private RemoteWebDriver createRemoteDriver(Capabilities capabilities) {
    AqualityServices.getLocalizedLogger().info("loc.browser.grid");

    ClientFactory clientFactory = new ClientFactory();
    CommandExecutor commandExecutor = new HttpCommandExecutor(
            ImmutableMap.of(),
            browserProfile.getRemoteConnectionUrl(),
            clientFactory);

    RemoteWebDriver driver = getDriver(RemoteWebDriver.class, commandExecutor, capabilities);
    driver.setFileDetector(new LocalFileDetector());
    return driver;
}
 
Example #7
Source File: MobileRecordingListener.java    From carina with Apache License 2.0 5 votes vote down vote up
public MobileRecordingListener(CommandExecutor commandExecutor, O1 startRecordingOpt, O2 stopRecordingOpt,
		TestArtifactType artifact) {
	this.commandExecutor = commandExecutor;
	this.startRecordingOpt = startRecordingOpt;
	this.stopRecordingOpt = stopRecordingOpt;
	this.videoArtifact = artifact;
}
 
Example #8
Source File: W3CActions.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Override
public Void call() throws Exception {
  RemoteWebDriver driver = (RemoteWebDriver) getUnwrappedDriver();
  CommandExecutor executor = (driver).getCommandExecutor();

  long start = System.currentTimeMillis();
  Command command = new Command(driver.getSessionId(), ACTIONS, allParameters);
  Response response = executor.execute(command);

  new ErrorHandler(true)
      .throwIfResponseFailed(response, System.currentTimeMillis() - start);

  return null;
}
 
Example #9
Source File: ChromiumDriver.java    From selenium with Apache License 2.0 5 votes vote down vote up
protected ChromiumDriver(CommandExecutor commandExecutor, Capabilities capabilities, String capabilityKey) {
  super(commandExecutor, capabilities);
  locationContext = new RemoteLocationContext(getExecuteMethod());
  webStorage = new RemoteWebStorage(getExecuteMethod());
  touchScreen = new RemoteTouchScreen(getExecuteMethod());
  networkConnection = new RemoteNetworkConnection(getExecuteMethod());

  HttpClient.Factory factory = HttpClient.Factory.createDefault();
  connection = ChromiumDevToolsLocator.getChromeConnector(
      factory,
      getCapabilities(),
      capabilityKey);
  devTools = connection.map(DevTools::new);
}
 
Example #10
Source File: PtlWebDriver.java    From hifive-pitalium with Apache License 2.0 5 votes vote down vote up
/**
 * コンストラクタ
 *
 * @param executor CommandExecutor
 * @param capabilities Capability
 */
protected PtlWebDriver(CommandExecutor executor, PtlCapabilities capabilities) {
	super(executor, capabilities);
	this.capabilities = capabilities;

	// JsonToWebElementConverterを上書きすることでfindElementから取得されるRemoteWebElementを差し替え
	setElementConverter(new JsonToPtlWebElementConverter(this));
}
 
Example #11
Source File: PtlIPadDriver.java    From hifive-pitalium with Apache License 2.0 5 votes vote down vote up
/**
 * コンストラクタ
 *
 * @param executor CommandExecutor
 * @param capabilities Capability
 */
PtlIPadDriver(CommandExecutor executor, PtlCapabilities capabilities) {
	super(executor, capabilities);

	Object headerHeightCapability = capabilities.getCapability("headerHeight");
	if (headerHeightCapability == null) {
		throw new TestRuntimeException("Capability \"headerHeight\" is required");
	} else {
		if (headerHeightCapability instanceof Number) {
			headerHeight = ((Number) headerHeightCapability).intValue();
		} else {
			headerHeight = Integer.parseInt(headerHeightCapability.toString());
		}
	}
}
 
Example #12
Source File: BrowserFactory.java    From aquality-selenium-java with Apache License 2.0 5 votes vote down vote up
default <T extends RemoteWebDriver> T getDriver(Class<T> driverClass, CommandExecutor commandExecutor, Capabilities capabilities) {
    return AqualityServices.get(IActionRetrier.class).doWithRetry(() -> {
        try {
            if (commandExecutor != null) {
                return driverClass.getDeclaredConstructor(CommandExecutor.class, Capabilities.class).newInstance(commandExecutor, capabilities);
            }

            return driverClass.getDeclaredConstructor(Capabilities.class).newInstance(capabilities);
        } catch (ReflectiveOperationException e) {
            throw new UnsupportedOperationException(String.format("Cannot instantiate driver with type '%1$s'.", driverClass), e);
        }
    }, Collections.emptyList());
}
 
Example #13
Source File: LiveIsExtendedWebDriver.java    From qaf with MIT License 5 votes vote down vote up
private void setCodec() {
	try {
		CommandExecutor executor = getCommandExecutor();
		setField("commandCodec", executor, Dialect.W3C.getCommandCodec());
		setField("responseCodec", executor, Dialect.W3C.getResponseCodec());
	} catch (Throwable e) {
		logger.error("Unable to set W3C codec", e);
	}
}
 
Example #14
Source File: SeleniumDriverFactory.java    From qaf with MIT License 5 votes vote down vote up
public UiDriver getDriver(WebDriverCommandLogger cmdLogger, String[] stb) {
	String browser = STBArgs.browser_str.getFrom(stb);
	String baseUrl = STBArgs.base_url.getFrom(stb);

	QAFCommandProcessor commandProcessor =
			new SeleniumCommandProcessor(STBArgs.sel_server.getFrom(stb),
					Integer.parseInt(STBArgs.port.getFrom(stb)),
					browser.split("_")[0], baseUrl);
	CommandExecutor executor = getObject(commandProcessor);
	QAFExtendedWebDriver driver =
			new QAFExtendedWebDriver(executor, new DesiredCapabilities(), cmdLogger);
	QAFWebDriverBackedSelenium selenium =
			new QAFWebDriverBackedSelenium(commandProcessor, driver);

	commandProcessor.addListener(new SubmitCommandListener());

	commandProcessor.addListener(new SeleniumCommandLogger(new ArrayList<LoggingBean>()));
	commandProcessor.addListener(new AutoWaitInjector());
	if (browser.contains("iexproper") || browser.contains("iehta")) {
		commandProcessor.addListener(new IEScreenCaptureListener());
	}
	String listners = ApplicationProperties.SELENIUM_CMD_LISTENERS.getStringVal("");

	if (!listners.equalsIgnoreCase("")) {
		commandProcessor.addListener(listners.split(","));
	}

	return selenium;
}
 
Example #15
Source File: PtlInternetExplorerDriver.java    From hifive-pitalium with Apache License 2.0 5 votes vote down vote up
/**
 * コンストラクタ
 *
 * @param executor CommandExecutor
 * @param capabilities Capability
 */
PtlInternetExplorerDriver(CommandExecutor executor, PtlCapabilities capabilities) {
	super(executor, capabilities);

	Object chromeWidthCapability = capabilities.getCapability("chromeWidth");
	if (chromeWidthCapability == null) {
		throw new TestRuntimeException("Capability \"chromeWidth\" is required.");
	}

	if (chromeWidthCapability instanceof Number) {
		chromeWidth = ((Number) chromeWidthCapability).intValue();
	} else {
		chromeWidth = Integer.parseInt(chromeWidthCapability.toString());
	}
}
 
Example #16
Source File: SeleniumDriverFactory.java    From qaf with MIT License 5 votes vote down vote up
private CommandExecutor getObject(Object commandProcessor) {

		try {
			Class<?> clazz = Class.forName("org.openqa.selenium.SeleneseCommandExecutor");
			Class<?> commandProcessorclazz =
					Class.forName("com.thoughtworks.selenium.CommandProcessor");
			Constructor<?> ctor = clazz.getConstructor(commandProcessorclazz);
			return (CommandExecutor) ctor.newInstance(new Object[]{commandProcessor});
		} catch (Exception e) {
			throw new RuntimeException(e.getMessage()
					+ "SeleneseCommandExecutor is not available. Please try with selenium 2.32 or older.");
		}
	}
 
Example #17
Source File: PtlWebDriverFactory.java    From hifive-pitalium with Apache License 2.0 4 votes vote down vote up
@Override
public PtlWebDriver createReusableWebDriver(CommandExecutor executor) {
	return new PtlSafariDriver(executor, getCapabilities());
}
 
Example #18
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 #19
Source File: QAFExtendedWebDriver.java    From qaf with MIT License 4 votes vote down vote up
public QAFExtendedWebDriver(CommandExecutor cmdExecutor, Capabilities capabilities,
		WebDriverCommandLogger reporter) {
	super(cmdExecutor, capabilities);
	init(reporter);
}
 
Example #20
Source File: DefaultGenericMobileDriver.java    From java-client with Apache License 2.0 4 votes vote down vote up
public DefaultGenericMobileDriver(CommandExecutor executor, Capabilities desiredCapabilities) {
    super(executor, desiredCapabilities);
}
 
Example #21
Source File: xRemoteWebDriver.java    From kspl-selenium-helper with GNU General Public License v3.0 4 votes vote down vote up
public xRemoteWebDriver(CommandExecutor executor, Capabilities desiredCapabilities,Log log)
{
  super(executor, desiredCapabilities);
}
 
Example #22
Source File: PtlWebDriverFactory.java    From hifive-pitalium with Apache License 2.0 4 votes vote down vote up
@Override
public PtlWebDriver createReusableWebDriver(CommandExecutor executor) {
	return new PtlSelendroidDriver(executor, getCapabilities());
}
 
Example #23
Source File: PtlWebDriverFactory.java    From hifive-pitalium with Apache License 2.0 4 votes vote down vote up
@Override
public PtlWebDriver createReusableWebDriver(CommandExecutor executor) {
	return new PtlAndroidDriver(executor, getCapabilities());
}
 
Example #24
Source File: PtlWebDriverFactory.java    From hifive-pitalium with Apache License 2.0 4 votes vote down vote up
@Override
public PtlWebDriver createReusableWebDriver(CommandExecutor executor) {
	return new PtlIPadDriver(executor, getCapabilities());
}
 
Example #25
Source File: PtlWebDriverFactory.java    From hifive-pitalium with Apache License 2.0 4 votes vote down vote up
@Override
public PtlWebDriver createReusableWebDriver(CommandExecutor executor) {
	return new PtlIPhoneDriver(executor, getCapabilities());
}
 
Example #26
Source File: PtlWebDriverFactory.java    From hifive-pitalium with Apache License 2.0 4 votes vote down vote up
@Override
public PtlWebDriver createReusableWebDriver(CommandExecutor executor) {
	return new PtlEdgeDriver(executor, getCapabilities());
}
 
Example #27
Source File: PtlWebDriverFactory.java    From hifive-pitalium with Apache License 2.0 4 votes vote down vote up
@Override
public PtlWebDriver createReusableWebDriver(CommandExecutor executor) {
	return new PtlInternetExplorer8Driver(executor, getCapabilities());
}
 
Example #28
Source File: PtlWebDriverFactory.java    From hifive-pitalium with Apache License 2.0 4 votes vote down vote up
@Override
public PtlWebDriver createReusableWebDriver(CommandExecutor executor) {
	return new PtlInternetExplorer7Driver(executor, getCapabilities());
}
 
Example #29
Source File: PtlWebDriverFactory.java    From hifive-pitalium with Apache License 2.0 4 votes vote down vote up
@Override
public PtlWebDriver createReusableWebDriver(CommandExecutor executor) {
	return new PtlInternetExplorerDriver(executor, getCapabilities());
}
 
Example #30
Source File: PtlWebDriverFactory.java    From hifive-pitalium with Apache License 2.0 4 votes vote down vote up
@Override
public PtlWebDriver createReusableWebDriver(CommandExecutor executor) {
	return new PtlChromeDriver(executor, getCapabilities());
}