use of org.openqa.selenium.SessionNotCreatedException in project java-client by appium.
the class AppiumCommandExecutor method createSession.
private Response createSession(Command command) throws IOException {
if (getCommandCodec() != null) {
throw new SessionNotCreatedException("Session already exists");
}
ProtocolHandshake.Result result = new AppiumProtocolHandshake().createSession(getClient().with((httpHandler) -> (req) -> {
req.setHeader(IDEMPOTENCY_KEY_HEADER, UUID.randomUUID().toString().toLowerCase());
return httpHandler.execute(req);
}), command);
Dialect dialect = result.getDialect();
if (!(dialect.getCommandCodec() instanceof W3CHttpCommandCodec)) {
throw new SessionNotCreatedException("Only W3C sessions are supported. " + "Please make sure your server is up to date.");
}
setCommandCodec(new AppiumW3CHttpCommandCodec());
refreshAdditionalCommands();
setResponseCodec(dialect.getResponseCodec());
return result.createResponse();
}
use of org.openqa.selenium.SessionNotCreatedException in project java-client by appium.
the class AppiumDriver method startSession.
@Override
protected void startSession(Capabilities capabilities) {
Response response = execute(new AppiumNewSessionCommandPayload(capabilities));
if (response == null) {
throw new SessionNotCreatedException("The underlying command executor returned a null response.");
}
Object responseValue = response.getValue();
if (responseValue == null) {
throw new SessionNotCreatedException("The underlying command executor returned a response without payload: " + response);
}
if (!(responseValue instanceof Map)) {
throw new SessionNotCreatedException("The underlying command executor returned a response with a non well formed payload: " + response);
}
@SuppressWarnings("unchecked") Map<String, Object> rawCapabilities = (Map<String, Object>) responseValue;
// A workaround for Selenium API enforcing some legacy capability values
rawCapabilities.remove(CapabilityType.PLATFORM);
if (rawCapabilities.containsKey(CapabilityType.BROWSER_NAME) && isBlank((String) rawCapabilities.get(CapabilityType.BROWSER_NAME))) {
rawCapabilities.remove(CapabilityType.BROWSER_NAME);
}
MutableCapabilities returnedCapabilities = new BaseOptions<>(rawCapabilities);
try {
Field capsField = RemoteWebDriver.class.getDeclaredField("capabilities");
capsField.setAccessible(true);
capsField.set(this, returnedCapabilities);
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new WebDriverException(e);
}
setSessionId(response.getSessionId());
}
use of org.openqa.selenium.SessionNotCreatedException in project java-client by appium.
the class BaseIOSWebViewTest method beforeClass.
@BeforeClass
public static void beforeClass() throws IOException {
startAppiumServer();
XCUITestOptions options = new XCUITestOptions().setDeviceName(DEVICE_NAME).setWdaLaunchTimeout(WDA_LAUNCH_TIMEOUT).setCommandTimeouts(Duration.ofSeconds(240)).setApp(vodQaAppZip().toAbsolutePath().toString());
Supplier<IOSDriver> createDriver = () -> new IOSDriver(service.getUrl(), options);
try {
driver = createDriver.get();
} catch (SessionNotCreatedException e) {
// Sometimes WDA session creation freezes unexpectedly on CI:
// https://dev.azure.com/srinivasansekar/java-client/_build/results?buildId=356&view=ms.vss-test-web.build-test-results-tab
options.useNewWDA();
driver = createDriver.get();
}
}
use of org.openqa.selenium.SessionNotCreatedException in project seleniumRobot by bhecquet.
the class SeleniumGridConnector method getSessionInformationFromGrid.
public void getSessionInformationFromGrid(RemoteWebDriver driver, long driverCreationDuration) {
// logging node ip address:
JSONObject object;
try {
object = Unirest.get(String.format("http://%s:%d%s", hubUrl.getHost(), hubUrl.getPort(), API_TEST_SESSSION)).queryString("session", driver.getSessionId().toString()).asJson().getBody().getObject();
} catch (Exception e) {
throw new SessionNotCreatedException(String.format("Could not get session information from grid: %s", e.getMessage()));
}
// if we have an error (session not found), raise an exception
try {
nodeUrl = (String) object.get("proxyId");
} catch (JSONException e) {
// },
throw new SessionNotCreatedException(object.getString("msg"));
}
try {
String node = nodeUrl.split("//")[1].split(":")[0];
String browserName = driver.getCapabilities().getBrowserName();
String version = driver.getCapabilities().getVersion();
// if so, keep the previous sessionId so that recordings are correctly handled
if (sessionId == null) {
setSessionId(driver.getSessionId());
}
// store some information about driver creation
MutableCapabilities caps = (MutableCapabilities) driver.getCapabilities();
caps.setCapability(DriverUsage.GRID_HUB, hubUrl);
caps.setCapability(DriverUsage.SESSION_ID, sessionId);
caps.setCapability(DriverUsage.GRID_NODE, node);
logger.info(String.format("Brower %s (%s) created in %.1f secs on node %s [%s] with session %s", browserName, version, driverCreationDuration / 1000.0, node, hubUrl, sessionId).replace(",", "."));
} catch (Exception ex) {
throw new SessionNotCreatedException(ex.getMessage());
}
}
use of org.openqa.selenium.SessionNotCreatedException in project seleniumRobot by bhecquet.
the class SeleniumGridDriverFactory method createWebDriver.
@Override
public WebDriver createWebDriver() {
// create capabilities, specific to OS
MutableCapabilities capabilities = createSpecificGridCapabilities(webDriverConfig);
capabilities.merge(driverOptions);
// upload file on all available grids as we don't know which one will be chosen before driver has been created
for (SeleniumGridConnector gridConnector : gridConnectors) {
gridConnector.uploadMobileApp(capabilities);
}
// connection to grid is made here
for (int i = 0; i < 3; i++) {
long start = new Date().getTime();
driver = getDriver(capabilities);
long duration = new Date().getTime() - start;
setImplicitWaitTimeout(webDriverConfig.getImplicitWaitTimeout());
if (webDriverConfig.getPageLoadTimeout() >= 0 && SeleniumTestsContextManager.isWebTest()) {
setPageLoadTimeout(webDriverConfig.getPageLoadTimeout());
}
this.setWebDriver(driver);
// if session has not been really created, we retry
try {
activeGridConnector.getSessionInformationFromGrid((RemoteWebDriver) driver, duration);
} catch (SessionNotCreatedException e) {
logger.error(e.getMessage());
continue;
}
// sets a file detector. This is only useful for remote drivers
((RemoteWebDriver) driver).setFileDetector(new LocalFileDetector());
// create a BrowserInfo based on information get from grid hub
selectedBrowserInfo = new BrowserInfo(BrowserType.getBrowserTypeFromSeleniumBrowserType(((RemoteWebDriver) driver).getCapabilities().getBrowserName()), ((RemoteWebDriver) driver).getCapabilities().getVersion());
return driver;
}
throw new SessionNotCreatedException("Session not created on any grid hub, after 3 tries");
}
Aggregations