/** * 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; }
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; }
@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); }
@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); }
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; }
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."); } }
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); }
public WebDriverEx(CommandExecutor executor, Capabilities desiredCapabilities, Capabilities requiredCapabilities) { super(executor, desiredCapabilities, requiredCapabilities); }
public WebDriverEx(CommandExecutor executor, Capabilities desiredCapabilities) { super(executor, desiredCapabilities); }
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); }
CustomCommandExecutor(CommandExecutor grid, CommandExecutor node) { this.grid = grid; this.node = node; }
public WebDriverRemote(CommandExecutor executor, Capabilities capabilities) { super(executor, capabilities); }
public DefaultGenericMobileDriver(CommandExecutor executor, Capabilities desiredCapabilities) { super(executor, desiredCapabilities); }
public QAFExtendedWebDriver(CommandExecutor cmdExecutor, Capabilities capabilities, WebDriverCommandLogger reporter) { super(cmdExecutor, capabilities); init(reporter); }
public xRemoteWebDriver(CommandExecutor executor, Capabilities desiredCapabilities,Log log) { super(executor, desiredCapabilities); }