类org.openqa.selenium.remote.CommandExecutor源码实例Demo

下面列出了怎么用org.openqa.selenium.remote.CommandExecutor的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: hifive-pitalium   文件: PtlIPhoneDriver.java
/**
 * コンストラクタ
 *
 * @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());
		}
	}
}
 
源代码2 项目: selenium   文件: FirefoxDriverTest.java
@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));
  }
}
 
源代码3 项目: selenium   文件: WebDriverWaitTest.java
@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");
}
 
源代码4 项目: selenium   文件: RemoteSession.java
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())));
}
 
源代码5 项目: selenium   文件: OneShotNode.java
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);
  }
}
 
源代码6 项目: aquality-selenium-java   文件: BrowserFactory.java
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());
}
 
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;
}
 
源代码8 项目: qaf   文件: LiveIsExtendedWebDriver.java
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);
	}
}
 
源代码9 项目: qaf   文件: SeleniumDriverFactory.java
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;
}
 
源代码10 项目: qaf   文件: SeleniumDriverFactory.java
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.");
		}
	}
 
/**
 * コンストラクタ
 *
 * @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());
	}
}
 
源代码12 项目: hifive-pitalium   文件: PtlIPadDriver.java
/**
 * コンストラクタ
 *
 * @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());
		}
	}
}
 
源代码13 项目: hifive-pitalium   文件: PtlWebDriver.java
/**
 * コンストラクタ
 *
 * @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));
}
 
源代码14 项目: selenium   文件: ChromiumDriver.java
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);
}
 
源代码15 项目: selenium   文件: W3CActions.java
@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;
}
 
源代码16 项目: carina   文件: MobileRecordingListener.java
public MobileRecordingListener(CommandExecutor commandExecutor, O1 startRecordingOpt, O2 stopRecordingOpt,
		TestArtifactType artifact) {
	this.commandExecutor = commandExecutor;
	this.startRecordingOpt = startRecordingOpt;
	this.stopRecordingOpt = stopRecordingOpt;
	this.videoArtifact = artifact;
}
 
源代码17 项目: QVisual   文件: WebDriverManager.java
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);
}
 
源代码18 项目: qaf   文件: QAFExtendedWebDriver.java
public QAFExtendedWebDriver(CommandExecutor cmdExecutor, Capabilities capabilities,
		WebDriverCommandLogger reporter) {
	super(cmdExecutor, capabilities);
	init(reporter);
}
 
源代码19 项目: hifive-pitalium   文件: PtlWebDriverFactory.java
@Override
public PtlWebDriver createReusableWebDriver(CommandExecutor executor) {
	return new PtlFirefoxDriver(executor, getCapabilities());
}
 
源代码20 项目: hifive-pitalium   文件: PtlWebDriverFactory.java
@Override
public PtlWebDriver createReusableWebDriver(CommandExecutor executor) {
	return new PtlChromeDriver(executor, getCapabilities());
}
 
源代码21 项目: hifive-pitalium   文件: PtlWebDriverFactory.java
@Override
public PtlWebDriver createReusableWebDriver(CommandExecutor executor) {
	return new PtlInternetExplorerDriver(executor, getCapabilities());
}
 
源代码22 项目: hifive-pitalium   文件: PtlWebDriverFactory.java
@Override
public PtlWebDriver createReusableWebDriver(CommandExecutor executor) {
	return new PtlInternetExplorer7Driver(executor, getCapabilities());
}
 
源代码23 项目: hifive-pitalium   文件: PtlWebDriverFactory.java
@Override
public PtlWebDriver createReusableWebDriver(CommandExecutor executor) {
	return new PtlInternetExplorer8Driver(executor, getCapabilities());
}
 
源代码24 项目: hifive-pitalium   文件: PtlWebDriverFactory.java
@Override
public PtlWebDriver createReusableWebDriver(CommandExecutor executor) {
	return new PtlEdgeDriver(executor, getCapabilities());
}
 
源代码25 项目: hifive-pitalium   文件: PtlWebDriverFactory.java
@Override
public PtlWebDriver createReusableWebDriver(CommandExecutor executor) {
	return new PtlSafariDriver(executor, getCapabilities());
}
 
源代码26 项目: hifive-pitalium   文件: PtlWebDriverFactory.java
@Override
public PtlWebDriver createReusableWebDriver(CommandExecutor executor) {
	return new PtlIPhoneDriver(executor, getCapabilities());
}
 
源代码27 项目: hifive-pitalium   文件: PtlWebDriverFactory.java
@Override
public PtlWebDriver createReusableWebDriver(CommandExecutor executor) {
	return new PtlIPadDriver(executor, getCapabilities());
}
 
源代码28 项目: hifive-pitalium   文件: PtlWebDriverFactory.java
@Override
public PtlWebDriver createReusableWebDriver(CommandExecutor executor) {
	return new PtlAndroidDriver(executor, getCapabilities());
}
 
源代码29 项目: hifive-pitalium   文件: PtlWebDriverFactory.java
@Override
public PtlWebDriver createReusableWebDriver(CommandExecutor executor) {
	return new PtlSelendroidDriver(executor, getCapabilities());
}
 
源代码30 项目: kspl-selenium-helper   文件: xRemoteWebDriver.java
public xRemoteWebDriver(CommandExecutor executor, Capabilities desiredCapabilities,Log log)
{
  super(executor, desiredCapabilities);
}
 
 类所在包
 类方法
 同包方法