List of usage examples for org.openqa.selenium.remote.server Session getDriver
WebDriver getDriver();
From source file:com.thoughtworks.selenium.webdriven.WebDriverBackedSeleniumServlet.java
License:Apache License
private void startNewSession(HttpServletResponse resp, String browserString, String baseUrl, String options) throws IOException { SessionId sessionId = null;/*w ww .j a va 2 s .co m*/ if (options.startsWith("webdriver.remote.sessionid")) { // We may have a hit List<String> split = Splitter.on("=").omitEmptyStrings().trimResults().limit(2).splitToList(options); if (!"webdriver.remote.sessionid".equals(split.get(0))) { getServletContext() .log("Unable to find existing webdriver session. Wrong parameter name: " + options); sendError(resp, "Unable to find existing webdriver session. Wrong parameter name: " + options); return; } if (split.size() != 2) { getServletContext().log("Attempted to find webdriver id, but none specified. Bailing"); sendError(resp, "Unable to find existing webdriver session. No ID specified"); return; } sessionId = new SessionId(split.get(1)); } if (sessionId != null) { Session session = sessionsSupplier.get().get(sessionId); // Let's assume the person knew what they're doing... Skip to the end } else { // Fine. Let's see if the user chose "webdriver" or something specific. DesiredCapabilities caps; switch (browserString) { case "*webdriver": caps = new DesiredCapabilities(); break; case "*chrome": case "*firefox": case "*firefoxproxy": case "*firefoxchrome": case "*pifirefox": caps = DesiredCapabilities.firefox(); break; case "*iehta": case "*iexplore": case "*iexploreproxy": case "*piiexplore": caps = DesiredCapabilities.internetExplorer(); break; case "*googlechrome": caps = DesiredCapabilities.chrome(); break; case "*MicrosoftEdge": caps = DesiredCapabilities.edge(); break; case "*opera": case "*operablink": caps = DesiredCapabilities.operaBlink(); break; case "*safari": case "*safariproxy": caps = DesiredCapabilities.safari(); break; default: sendError(resp, "Unable to match browser string: " + browserString); return; } try { sessionId = sessionsSupplier.get().newSession(caps); } catch (Exception e) { getServletContext().log("Unable to start session", e); sendError(resp, "Unable to start session. Cause can be found in logs. Message is: " + e.getMessage()); return; } } Session session = sessionsSupplier.get().get(sessionId); if (session == null) { getServletContext().log("Attempt to use non-existant session: " + sessionId); sendError(resp, "Attempt to use non-existant session: " + sessionId); return; } WebDriver driver = session.getDriver(); CommandProcessor commandProcessor = new WebDriverCommandProcessor(baseUrl, driver); SESSIONS.put(sessionId, commandProcessor); sendResponse(resp, sessionId.toString()); }