List of usage examples for org.openqa.selenium WebDriverException WebDriverException
public WebDriverException(Throwable cause)
From source file:org.uiautomation.ios.server.application.APPIOSApplication.java
License:Apache License
public LanguageDictionary getDictionary(AppleLanguage language) throws WebDriverException { if (!language.exists()) { throw new WebDriverException( "The application doesn't have any content files.The l10n " + "features cannot be used."); }/* www . j a v a 2s. com*/ for (LanguageDictionary dict : dictionaries) { if (dict.getLanguage() == language) { return dict; } } throw new WebDriverException("Cannot find dictionary for " + language); }
From source file:org.uiautomation.ios.server.application.APPIOSApplication.java
License:Apache License
/** * Load all the dictionaries for the application. *//* ww w . j a v a 2 s . co m*/ private void loadAllContent() throws WebDriverException { if (!dictionaries.isEmpty()) { throw new WebDriverException("Content already present."); } Map<String, LanguageDictionary> dicts = new HashMap<String, LanguageDictionary>(); List<File> l10nFiles = LanguageDictionary.getL10NFiles(app); for (File f : l10nFiles) { String name = LanguageDictionary.extractLanguageName(f); LanguageDictionary res = dicts.get(name); if (res == null) { res = new LanguageDictionary(name); dicts.put(name, res); } try { // and load the content. JSONObject content = res.readContentFromBinaryFile(f); res.addJSONContent(content); } catch (Exception e) { throw new WebDriverException("error loading content for l10n", e); } } dictionaries.addAll(dicts.values()); }
From source file:org.uiautomation.ios.server.application.APPIOSApplication.java
License:Apache License
public static APPIOSApplication findSafariLocation(File xcodeInstall, String sdkVersion) { File app = new File(xcodeInstall, "/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator" + sdkVersion + ".sdk/Applications/MobileSafari.app"); if (!app.exists()) { throw new WebDriverException(app + " should be the safari app, but doesn't exist."); }/*from www. j ava 2s .c om*/ return new APPIOSApplication(app.getAbsolutePath()); }
From source file:org.uiautomation.ios.server.application.APPIOSApplication.java
License:Apache License
public void setDefaultDevice(DeviceType device) { try {/*w ww . j av a2 s . c o m*/ File plist = new File(app, "Info.plist"); PListFormat format = getFormat(plist); NSDictionary root = (NSDictionary) PropertyListParser.parse(new FileInputStream(plist)); NSArray devices = (NSArray) root.objectForKey("UIDeviceFamily"); int length = devices.getArray().length; if (length == 1) { return; } NSArray rearrangedArray = new NSArray(length); NSNumber last = null; int index = 0; for (int i = 0; i < length; i++) { NSNumber d = (NSNumber) devices.objectAtIndex(i); if (d.intValue() == device.getDeviceFamily()) { last = d; } else { rearrangedArray.setValue(index, d); index++; } } if (last == null) { throw new WebDriverException("Cannot find device " + device + " in the supported device list."); } rearrangedArray.setValue(index, last); root.put("UIDeviceFamily", rearrangedArray); write(plist, root, format); } catch (Exception e) { throw new WebDriverException("Cannot change the default device for the app." + e.getMessage(), e); } }
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; }//from w w w . j a v a2 s. c om 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.application.APPIOSApplication.java
License:Apache License
public List<DeviceType> getSupportedDevices() { List<DeviceType> families = new ArrayList<DeviceType>(); String s = (String) getMetadata(IOSCapabilities.DEVICE_FAMILLY); try {/*from w ww .java 2s .c o m*/ JSONArray ar = new JSONArray(s); for (int i = 0; i < ar.length(); i++) { int f = ar.getInt(i); if (f == 1) { families.add(DeviceType.iphone); families.add(DeviceType.ipod); } else { families.add(DeviceType.ipad); } } return families; } catch (JSONException e) { throw new WebDriverException(e); } }
From source file:org.uiautomation.ios.server.application.AppleLocale.java
License:Apache License
public AppleLocale(String lprojname) { Locale loc = findBestLocale(lprojname); if (loc == null) { throw new WebDriverException("no support for " + lprojname); }/*from w w w .j ava 2 s. c o m*/ locale = loc; lproj = lprojname; }
From source file:org.uiautomation.ios.server.application.IOSApplication.java
License:Apache License
/** * /*from w w w . ja va 2s . c om*/ * @param currentLanguage * @param pathToApp * @throws WebDriverException */ public IOSApplication(String pathToApp) { this.app = new File(pathToApp); if (!app.exists()) { throw new WebDriverException(pathToApp + "isn't an IOS app."); } loadAllContent(); try { metadata = getFullPlist(); } catch (Exception e) { throw new WebDriverException("cannot load the metadata from the Info.plist file for " + pathToApp); } }
From source file:org.uiautomation.ios.server.application.IOSApplication.java
License:Apache License
public AppleLocale getAppleLocaleFromLanguageCode(String languageCode) { for (AppleLocale loc : getSupportedLanguages()) { if (languageCode.equals(loc.getLocale().getLanguage())) { return loc; }//w w w . j av a2s .co m } throw new WebDriverException("Cannot find AppleLocale for " + languageCode); }
From source file:org.uiautomation.ios.server.application.IOSApplication.java
License:Apache License
public LanguageDictionary getDictionary(AppleLocale language) throws WebDriverException { for (LanguageDictionary dict : dictionaries) { if (dict.getLanguage() == language) { return dict; }//w w w . j a v a2 s . c om } throw new WebDriverException("Cannot find dictionary for " + language); }