List of usage examples for org.openqa.selenium SessionNotCreatedException SessionNotCreatedException
public SessionNotCreatedException(String msg)
From source file:io.appium.java_client.remote.AppiumProtocolHandShake.java
License:Apache License
public Result createSession(HttpClient client, Command command) throws IOException, WebDriverException { Capabilities desired = ofNullable((Capabilities) command.getParameters().get("desiredCapabilities")) .orElseGet(DesiredCapabilities::new); Capabilities required = ofNullable((Capabilities) command.getParameters().get("requiredCapabilities")) .orElseGet(DesiredCapabilities::new); JsonParser parser = new JsonParser(); JsonElement des = parser.parse(new BeanToJsonConverter().convert(desired)); JsonElement req = parser.parse(new BeanToJsonConverter().convert(required)); JsonObject jsonObject = new JsonObject(); amendW3CParameters(jsonObject, des, req); amendOssParamters(jsonObject, des, req); Optional<Result> result = createSession(client, jsonObject); return ofNullable(result.orElseGet(() -> { JsonObject jsonObject1 = new JsonObject(); amendOssParamters(jsonObject1, des, req); try {//from w w w.j a v a 2 s . c o m return createSession(client, jsonObject1).orElseGet(() -> { JsonObject jsonObject2 = new JsonObject(); amendW3CParameters(jsonObject2, des, req); try { return createSession(client, jsonObject2).orElse(null); } catch (IOException e) { throw new WebDriverException(e); } }); } catch (IOException e) { throw new WebDriverException(e); } })).orElseThrow(() -> new SessionNotCreatedException(String.format( "Unable to create new remote session. " + "desired capabilities = %s, required capabilities = %s", desired, required))); }
From source file:org.uiautomation.ios.server.application.APPIOSApplication.java
License:Apache License
public static boolean canRun(IOSCapabilities desiredCapabilities, IOSCapabilities appCapability) { if (desiredCapabilities.isSimulator() != null && desiredCapabilities.isSimulator() != appCapability.isSimulator()) { return false; }/*ww w.j a v a 2 s. com*/ if (desiredCapabilities.getBundleName() == null) { throw new WebDriverException("you need to specify the bundle to test."); } String desired = desiredCapabilities.getBundleName(); String bundleName = (String) appCapability.getCapability(IOSCapabilities.BUNDLE_NAME); String displayName = (String) appCapability.getCapability(IOSCapabilities.BUNDLE_DISPLAY_NAME); String name = bundleName != null ? bundleName : displayName; if (!desired.equals(name)) { return false; } if (desiredCapabilities.getBundleVersion() != null && !desiredCapabilities.getBundleVersion().equals(appCapability.getBundleVersion())) { return false; } if (desiredCapabilities.getDevice() == null) { throw new WebDriverException("you need to specify the device."); } if (!(appCapability.getSupportedDevices().contains(desiredCapabilities.getDevice()))) { return false; } // check any extra capability starting with plist_ for (String key : desiredCapabilities.getRawCapabilities().keySet()) { if (key.startsWith(IOSCapabilities.MAGIC_PREFIX)) { String realKey = key.replace(MAGIC_PREFIX, ""); if (!desiredCapabilities.getRawCapabilities().get(key) .equals(appCapability.getRawCapabilities().get(realKey))) { return false; } } } String l = desiredCapabilities.getLanguage(); if (appCapability.getSupportedLanguages().isEmpty()) { log.info("The application doesn't have any content files." + " Localization related features won't be available."); } else if (l != null && !appCapability.getSupportedLanguages().contains(l)) { throw new SessionNotCreatedException("Language requested, " + l + " ,isn't supported.Supported are : " + appCapability.getSupportedLanguages()); } return true; }
From source file:org.uiautomation.ios.server.command.uiautomation.NewSession.java
License:Apache License
public Response handle() throws Exception { try {// w w w .j a v a 2 s . c o m GetCapabilitiesCommandHandler.reset(); JSONObject payload = getRequest().getPayload(); IOSCapabilities capabilities = new IOSCapabilities(payload.getJSONObject("desiredCapabilities")); session = getDriver().createSession(capabilities); session.start(); Response resp = new Response(); resp.setSessionId(session.getSessionId()); resp.setStatus(0); resp.setValue(""); return resp; } catch (Exception e) { throw new SessionNotCreatedException(e.getMessage()); } }
From source file:org.uiautomation.ios.server.command.uiautomation.NewSessionNHandler.java
License:Apache License
public Response handle() throws Exception { try {/*from w ww . j av a2 s . c o m*/ GetCapabilitiesNHandler.reset(); JSONObject payload = getRequest().getPayload(); IOSCapabilities capabilities = new IOSCapabilities(payload.getJSONObject("desiredCapabilities")); session = getDriver().createSession(capabilities); session.start(); Response resp = new Response(); resp.setSessionId(session.getSessionId()); resp.setStatus(0); resp.setValue(""); return resp; } catch (Exception e) { if (session != null) { session.stop(); } throw new SessionNotCreatedException(e.getMessage()); } }
From source file:org.uiautomation.ios.server.IOSDriver.java
License:Apache License
public IOSApplication findMatchingApplication(IOSCapabilities desiredCapabilities) { for (IOSApplication app : supportedApplications) { IOSCapabilities appCapabilities = getCapabilities(app); if (IOSDriver.matches(appCapabilities, desiredCapabilities)) { return app; }/*from w w w .j a v a2 s.com*/ } throw new SessionNotCreatedException(desiredCapabilities.getRawCapabilities() + "not found on server."); }
From source file:org.uiautomation.ios.server.IOSDriver.java
License:Apache License
private static boolean matches(IOSCapabilities applicationCapabilities, IOSCapabilities desiredCapabilities) { if (desiredCapabilities.getBundleName() == null) { throw new WebDriverException("you need to specify the bundle to test."); }// ww w. j av a 2 s .c om String desired = desiredCapabilities.getBundleName(); String appName = (String) (applicationCapabilities.getBundleName() != null ? applicationCapabilities.getBundleName() : applicationCapabilities.getCapability("CFBundleDisplayName")); if (!desired.equals(appName)) { return false; } if (desiredCapabilities.getBundleVersion() != null && !desiredCapabilities.getBundleVersion().equals(applicationCapabilities.getBundleVersion())) { return false; } if (desiredCapabilities.getDevice() == null) { throw new WebDriverException("you need to specify the device."); } if (!(applicationCapabilities.getSupportedDevices().contains(desiredCapabilities.getDevice()))) { return false; } // check any extra capability starting with plist_ for (String key : desiredCapabilities.getRawCapabilities().keySet()) { if (key.startsWith(IOSCapabilities.MAGIC_PREFIX)) { String realKey = key.replace(MAGIC_PREFIX, ""); if (!desiredCapabilities.getRawCapabilities().get(key) .equals(applicationCapabilities.getRawCapabilities().get(realKey))) { return false; } } } String l = desiredCapabilities.getLanguage(); if (l != null && !applicationCapabilities.getSupportedLanguages().contains(l)) { throw new SessionNotCreatedException("Language requested, " + l + " ,isn't supported.Supported are : " + applicationCapabilities.getSupportedLanguages()); } String sdk = desiredCapabilities.getSDKVersion(); // TODO freynaud validate for multi SDK /* * if (sdk != null && !sdk.equals(applicationCapabilities.getSDKVersion())) * { throw new IOSAutomationException("Cannot start sdk " + sdk + * ". Run on " + applicationCapabilities.getSDKVersion()); } */ return true; }
From source file:org.uiautomation.ios.server.IOSServerManager.java
License:Apache License
public IOSRunningApplication findAndCreateInstanceMatchingApplication(IOSCapabilities desiredCapabilities) { for (APPIOSApplication app : getApplicationStore().getApplications()) { IOSCapabilities appCapabilities = app.getCapabilities(); if (APPIOSApplication.canRun(desiredCapabilities, appCapabilities)) { AppleLanguage lang = AppleLanguage.create(desiredCapabilities.getLanguage()); return app.createInstance(lang); }/*from www. j a va2s .c o m*/ } throw new SessionNotCreatedException(desiredCapabilities.getRawCapabilities() + " not found on server."); }
From source file:org.uiautomation.ios.server.IOSServerManager.java
License:Apache License
public Device findAndReserveMatchingDevice(IOSCapabilities desiredCapabilities) { List<Device> devices = getDeviceStore().getDevices(); for (Device device : devices) { IOSCapabilities deviceCapabilities = device.getCapability(); if (Device.canRun(desiredCapabilities, deviceCapabilities)) { Device d = device.reserve(); if (d != null) { return d; }/*from w w w . jav a 2 s. c o m*/ } } throw new SessionNotCreatedException( desiredCapabilities.getRawCapabilities() + "not available. Available are " + devices); }
From source file:org.uiautomation.ios.server.ServerSideSession.java
License:Apache License
ServerSideSession(IOSServerManager driver, IOSCapabilities desiredCapabilities,
IOSServerConfiguration options) {
super(UUID.randomUUID().toString());
this.driver = driver;
this.capabilities = desiredCapabilities;
this.options = options;
this.sessionCrashed = false;
this.applicationCrashDetails = null;
String appCapability = (String) desiredCapabilities.getCapability("app");
if (appCapability != null) {
if (!Configuration.BETA_FEATURE)
Configuration.off();//w w w.ja v a 2 s . c o m
try {
File appFile = ZipUtils.extractAppFromURL(appCapability);
if (appFile.getName().endsWith(".app"))
desiredCapabilities.setCapability(IOSCapabilities.SIMULATOR, true);
APPIOSApplication app = APPIOSApplication.createFrom(appFile);
AppleLanguage lang = AppleLanguage.valueOf(desiredCapabilities.getLanguage());
application = app.createInstance(lang);
} catch (Exception ex) {
throw new SessionNotCreatedException("cannot create app from " + appCapability + ": " + ex);
}
} else {
application = driver.findAndCreateInstanceMatchingApplication(desiredCapabilities);
}
try {
device = driver.findAndReserveMatchingDevice(desiredCapabilities);
// update capabilities and put default values in the missing fields.
if (capabilities.getDeviceVariation() == null) {
capabilities.setDeviceVariation(DeviceVariation.Regular);
}
capabilities.setBundleId(application.getBundleId());
// TODO device.getSDK()
if (capabilities.getSDKVersion() == null) {
capabilities.setSDKVersion(ClassicCommands.getDefaultSDK());
} else {
String version = capabilities.getSDKVersion();
if (!new IOSVersion(version).isGreaterOrEqualTo("5.0")) {
throw new SessionNotCreatedException(version + " is too old. Only support SDK 5.0 and above.");
}
if (!driver.getHostInfo().getInstalledSDKs().contains(version)) {
throw new SessionNotCreatedException("SDK " + version + " not installed on this machine.");
}
if (!driver.getHostInfo().getInstalledSDKs().contains(version)) {
throw new SessionNotCreatedException("Cannot start on version " + version + ".Installed : "
+ driver.getHostInfo().getInstalledSDKs());
}
}
instruments = new InstrumentsManager(this);
configuration = new DriverConfigurationStore();
Runtime.getRuntime().addShutdownHook(shutdownHook);
} catch (WebDriverException e) {
if (device != null) {
device.release();
}
throw e;
}
}