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

项目:talk2grid    文件:RemoteWebDriverEnricher.java   
/**
 * A helper method that enriches a {@link RemoteWebDriver} instance with the ability to route all browser
 * interaction requests directly to the node on which the session was created and route only the session termination
 * request to the hub.
 *
 * @param driver - A {@link RemoteWebDriver} instance.
 * @param hub    - A {@link Host} object that represents the Hub information.
 * @return - A {@link RemoteWebDriver} instance that is enriched with the ability to route all browser interactions
 * directly to the node.
 */
public static RemoteWebDriver enrichRemoteWebDriverToInteractDirectlyWithNode(RemoteWebDriver driver, Host hub) {
    if (hub == null) {
        return driver;
    }
    try {
        CommandExecutor grid = driver.getCommandExecutor();
        String sessionId = driver.getSessionId().toString();
        GridApiAssistant assistant = new GridApiAssistant(hub);

        Host nodeHost = assistant.getNodeDetailsForSession(sessionId);
        URL url = new URL(String.format("http://%s:%d/wd/hub", nodeHost.getIpAddress(), nodeHost.getPort()));
        CommandExecutor node = new HttpCommandExecutor(url);
        CommandCodec commandCodec = getCodec(grid, "commandCodec");
        ResponseCodec responseCodec = getCodec(grid, "responseCodec");
        setCodec(node, commandCodec, "commandCodec");
        setCodec(node, responseCodec, "responseCodec");
        appendListenerToWebDriver(driver, grid, node);
        LOG.info("Traffic will now be routed directly to the node.");
        LOG.warning(constructWarningMessage(hub));
    } catch (Exception e) {
        //Gobble exceptions
        LOG.warning("Unable to enrich the RemoteWebDriver instance. Root cause :" + e.getMessage()
            + ". Returning back the original instance that was passed, as is.");
    }
    return driver;
}
项目:talk2grid    文件:RemoteWebDriverEnricher.java   
private static Host getHubInfo(RemoteWebDriver driver) {
    Host hub = null;
    CommandExecutor executor = driver.getCommandExecutor();
    if (executor instanceof HttpCommandExecutor) {
        URL url = ((HttpCommandExecutor) executor).getAddressOfRemoteServer();
        hub = new Host(url.getHost(), Integer.toString(url.getPort()));
    }
    return hub;
}
项目:talk2grid    文件:RemoteWebDriverEnricher.java   
@SuppressWarnings("unchecked")
private static <T> T getCodec(CommandExecutor executor, String fieldName) throws Exception {
    Class clazz = executor.getClass();
    Field field = clazz.getDeclaredField(fieldName);
    field.setAccessible(true);
    return (T) field.get(executor);
}
项目:talk2grid    文件:RemoteWebDriverEnricher.java   
@SuppressWarnings("unchecked")
private static void appendListenerToWebDriver(RemoteWebDriver rwd, CommandExecutor grid, CommandExecutor node)
    throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    CommandExecutor executor = new CustomCommandExecutor(grid, node);
    Class clazz = rwd.getClass();
    while (!RemoteWebDriver.class.equals(clazz)) {
        clazz = clazz.getSuperclass();
    }
    Method m = clazz.getDeclaredMethod("setCommandExecutor", CommandExecutor.class);
    m.setAccessible(true);
    m.invoke(rwd, executor);
}
项目: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;
}
项目: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.");
        }
    }
项目:selendroid    文件:SelendroidDriver.java   
private SelendroidDriver(CommandExecutor executor, Capabilities caps) throws Exception {
  super(executor, caps);
  RemoteExecuteMethod executeMethod = new RemoteExecuteMethod(this);
  touchScreen = new RemoteTouchScreen(executeMethod);
  multiTouchScreen = new MultiTouchScreen(executeMethod);
  adbConnection = new RemoteAdbConnection(executeMethod);
  trackBall = new TrackBall(executeMethod);
}
项目:jspider    文件:WebDriverEx.java   
public WebDriverEx(CommandExecutor executor, Capabilities desiredCapabilities, Capabilities requiredCapabilities) {
    super(executor, desiredCapabilities, requiredCapabilities);
}
项目:jspider    文件:WebDriverEx.java   
public WebDriverEx(CommandExecutor executor, Capabilities desiredCapabilities) {
    super(executor, desiredCapabilities);
}
项目:talk2grid    文件:RemoteWebDriverEnricher.java   
private static <T> void setCodec(CommandExecutor executor, T codec, String fieldName) throws Exception {
    Class clazz = executor.getClass();
    Field field = clazz.getDeclaredField(fieldName);
    field.setAccessible(true);
    field.set(executor, codec);
}
项目:talk2grid    文件:CustomCommandExecutor.java   
CustomCommandExecutor(CommandExecutor grid, CommandExecutor node) {
    this.grid = grid;
    this.node = node;
}
项目:saladium    文件:WebDriverRemote.java   
public WebDriverRemote(CommandExecutor executor, Capabilities capabilities) {
    super(executor, capabilities);
}
项目:menggeqa    文件:DefaultGenericMobileDriver.java   
public DefaultGenericMobileDriver(CommandExecutor executor, Capabilities desiredCapabilities) {
    super(executor, desiredCapabilities);
}
项目:qaf    文件:QAFExtendedWebDriver.java   
public QAFExtendedWebDriver(CommandExecutor cmdExecutor, Capabilities capabilities,
        WebDriverCommandLogger reporter) {
    super(cmdExecutor, capabilities);
    init(reporter);
}
项目:kspl-selenium-helper    文件:xRemoteWebDriver.java   
public xRemoteWebDriver(CommandExecutor executor, Capabilities desiredCapabilities,Log log)
{
  super(executor, desiredCapabilities);
}