public void failsWhenRequestingNonCurrentPlatform() throws Throwable { Platform[] values = Platform.values(); Platform otherPlatform = null; for (Platform platform : values) { if (Platform.getCurrent().is(platform)) { continue; } otherPlatform = platform; break; } DesiredCapabilities caps = new DesiredCapabilities("java", "1.0", otherPlatform); try { driver = new JavaDriver(caps, caps); throw new MissingException(SessionNotCreatedException.class); } catch (SessionNotCreatedException e) { } }
private ServerSideSession safeStart(DesiredCapabilities cap) { ServerSideSession session = null; try { // init session session = getServer().createSession(cap); if (session == null) { throw new SessionNotCreatedException( "The server is currently shutting down and doesn't accept new tests."); } // start session session.start(); return session; } catch (Exception e) { // TODO(user): Clean this up to meet logging best practices (should not log and throw). logger.atSevere().withCause(e).log("Error starting the session"); if (session != null) { session.stop(); } throw new SessionNotCreatedException(e.getMessage(), e); } }
public SeleniumHelper getSeleniumHelper() { if (helper == null) { DriverFactory currentFactory = getFactory(); if (currentFactory == null) { throw new StopTestException("Cannot use Selenium before configuring how to start a driver (for instance using SeleniumDriverSetup)"); } else { try { WebDriver driver = currentFactory.createDriver(); postProcessDriver(driver); SeleniumHelper newHelper = createHelper(driver); newHelper.setWebDriver(driver, getDefaultTimeoutSeconds()); setSeleniumHelper(newHelper); } catch (SessionNotCreatedException e) { throw new StopTestException("Unable to create selenium session using: " + currentFactory, e); } } } return helper; }
public void failsWhenRequestingANonJavaDriver() throws Throwable { DesiredCapabilities caps = new DesiredCapabilities("xjava", "1.0", Platform.getCurrent()); try { driver = new JavaDriver(caps, caps); throw new MissingException(SessionNotCreatedException.class); } catch (SessionNotCreatedException e) { } }
public void failsWhenRequestingUnsupportedCapability() throws Throwable { DesiredCapabilities caps = new DesiredCapabilities("java", "1.0", Platform.getCurrent()); caps.setCapability("rotatable", true); try { driver = new JavaDriver(caps, caps); throw new MissingException(SessionNotCreatedException.class); } catch (SessionNotCreatedException e) { } }
@Override public Response handle() throws Exception { ServerSideSession session = null; try { JsonObject capsJson = getRequest().getPayload().getJsonObject("desiredCapabilities"); session = safeStart(new DesiredCapabilities(JavaxJson.toJavaMap(capsJson))); if (session == null) { throw new SessionNotCreatedException("Failed to start session."); } Response r = new Response(); r.setSessionId(session.getSessionId()); r.setValue(session.getWebDriver().capabilities()); r.setStatus(0); return r; } catch (Exception e) { logger.atSevere().withCause(e).log(); if (session != null) { session.stop(); } if (e instanceof WebDriverException) { throw e; } else { throw new SessionNotCreatedException(e.getMessage(), e); } } }