List of usage examples for org.openqa.selenium WebDriverException WebDriverException
public WebDriverException(Throwable cause)
From source file:org.uiautomation.ios.server.application.IOSApplication.java
License:Apache License
public void setLanguage(String lang) { for (AppleLocale loc : getSupportedLanguages()) { if (loc.getLocale().toString().equals(lang)) { currentLanguage = loc;//www. j a v a 2s . c om return; } } throw new WebDriverException("Cannot find " + lang + " in the supported languages for the app."); }
From source file:org.uiautomation.ios.server.application.IOSApplication.java
License:Apache License
public static IOSApplication 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 w ww . ja v a 2s . c o m return new IOSApplication(app.getAbsolutePath()); }
From source file:org.uiautomation.ios.server.application.IOSApplication.java
License:Apache License
public void setDefaultDevice(Device device) { try {//from ww w.ja v a 2 s . c om File plist = new File(app, "Info.plist"); NSDictionary root = (NSDictionary) BinaryPropertyListParser.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); BinaryPropertyListWriter.write(plist, root); } catch (Exception e) { throw new WebDriverException("Cannot change the default device for the app." + e.getMessage(), e); } }
From source file:org.uiautomation.ios.server.command.NotImplementedNativeHandler.java
License:Apache License
@Override public Response handle() throws Exception { throw new WebDriverException("not implemented" + getRequest().getMethod() + " " + getRequest().getPath()); }
From source file:org.uiautomation.ios.server.command.uiautomation.ElementScrollNHandler.java
License:Apache License
public ElementScrollNHandler(IOSServerManager driver, WebDriverLikeRequest request) { super(driver, request); String template = null;/*from w ww .j a v a2 s . com*/ JSONObject payload = request.getPayload(); if (payload.has("direction")) { String direction = payload.optString("direction"); if (direction.equals("up")) { template = scrollUpTemplate; } else if (direction.equals("down")) { template = scrollDownTemplate; } else if (direction.equals("left")) { template = scrollLeftTemplate; } else if (direction.equals("right")) { template = scrollRightTemplate; } else { throw new WebDriverException("Invalid value for scrolling direction"); } } else if (payload.has("name")) { String name = payload.optString("name"); template = scrollToNameTemplate.replace(":name", name); } else if (payload.has("predicateString")) { String predicateString = payload.optString("predicateString"); template = scrollToPredicateTemplate.replace(":predicateString", predicateString); } else if (payload.has("toVisible")) { template = scrollToVisibleTemplate; } else { throw new WebDriverException("Unrecognised payload for ELEMENT_SCROLL"); } String js = template.replace(":sessionId", request.getSession()).replace(":reference", request.getVariableValue(":reference")); setJS(js); }
From source file:org.uiautomation.ios.server.command.uiautomation.SendKeysNHandler.java
License:Apache License
public SendKeysNHandler(IOSServerManager driver, WebDriverLikeRequest request) { super(driver, request); try {// ww w . j a v a 2s. co m JSONArray array = request.getPayload().getJSONArray("value"); StringBuilder b = new StringBuilder(); if (array != null) { int len = array.length(); for (int i = 0; i < len; i++) { b.append(array.get(i).toString()); } } String corrected = b.toString().replaceAll("\\\\", "\\\\\\\\"); corrected = corrected.replaceAll("\\n", "\\\\n"); if (corrected.contains("\\t")) { throw new WebDriverException("cannot tab on the ios keyboard."); } String js = template.replace(":sessionId", request.getSession()).replace(":value", corrected); setJS(js); } catch (JSONException e) { throw new WebDriverException("Error parsing the send keys command.", e); } }
From source file:org.uiautomation.ios.server.command.uiautomation.ServerStatus.java
License:Apache License
@Override public Response handle() throws Exception { JSONObject res = new JSONObject(); res.put("os", new JSONObject().put("name", System.getProperty("os.name")) .put("arch", System.getProperty("os.arch")).put("version", System.getProperty("os.version"))); res.put("java", new JSONObject().put("version", System.getProperty("java.version"))); res.put("ios", new JSONObject().put("simulatorVersion", ClassicCommands.getDefaultSDK())); JSONArray supportedApps = new JSONArray(); for (IOSApplication a : getDriver().getSupportedApplications()) { JSONObject app = new JSONObject(); JSONObject resources = new JSONObject(); for (String key : a.getResources().keySet()) { resources.put(key, "/wd/hub/resources/" + getDriver().getCache().getKey(a, key)); }//from www . ja v a 2 s . co m app.put("resources", resources); Map<String, Object> capabilities = getDriver().getCapabilities(a).getRawCapabilities(); for (String key : capabilities.keySet()) { app.put(key, capabilities.get(key)); } supportedApps.put(app); } res.put("supportedApps", supportedApps); res.put("build", new JSONObject().put("version", BuildInfo.getAttribute("version")) .put("time", BuildInfo.getAttribute("buildTimestamp")) .put("revision", BuildInfo.getAttribute("sha"))); List<ServerSideSession> sessions = getDriver().getSessions(); Response resp = new Response(); resp.setStatus(0); resp.setValue(res); if (sessions.size() == 0) { resp.setSessionId(null); } else if (sessions.size() == 1) { resp.setSessionId(sessions.get(0).getSessionId()); } else { throw new WebDriverException("NI multi sessions per server."); } return resp; }
From source file:org.uiautomation.ios.server.command.uiautomation.ServerStatusNHandler.java
License:Apache License
@Override public Response handle() throws Exception { JSONObject res = new JSONObject(); res.put("os", new JSONObject().put("name", System.getProperty("os.name")) .put("arch", System.getProperty("os.arch")).put("version", System.getProperty("os.version"))); res.put("java", new JSONObject().put("version", System.getProperty("java.version"))); res.put("ios", new JSONObject().put("simulatorVersion", ClassicCommands.getDefaultSDK())); res.put("supportedApps", getSupportedApps()); res.put("build", new JSONObject().put("version", BuildInfo.getAttribute("version")) .put("time", BuildInfo.getAttribute("buildTimestamp")) .put("revision", BuildInfo.getAttribute("sha"))); List<ServerSideSession> sessions = getDriver().getSessions(); Response resp = new Response(); resp.setStatus(0);//from w w w .j av a 2 s .c o m resp.setValue(res); if (sessions.size() == 0) { resp.setSessionId(null); } else if (sessions.size() == 1) { resp.setSessionId(sessions.get(0).getSessionId()); } else { throw new WebDriverException("NI multi sessions per server."); } return resp; }
From source file:org.uiautomation.ios.server.command.uiautomation.SetAlertTextHandler.java
License:Apache License
public SetAlertTextHandler(IOSServerManager driver, WebDriverLikeRequest request) { super(driver, request); try {//from ww w . j a v a 2 s . co m String value = request.getPayload().getString("text"); String corrected = value.replaceAll("\\\\", "\\\\\\\\"); corrected = corrected.replaceAll("\\n", "\\\\n"); if (value.contains("\\t")) { throw new WebDriverException("cannot tab on the ios keyboard."); } String js = jsTemplate.replace(":sessionId", getRequest().getSession()).replace(":value", corrected); setJS(js); } catch (JSONException e) { throw new WebDriverException("error parsing request " + request + "\n" + e.getMessage(), e); } }
From source file:org.uiautomation.ios.server.command.web.ToCSSSelectorConvertor.java
License:Apache License
public static String convertToCSSSelector(String type, String value) { if ("css selector".equals(type)) { return value; }//from w w w .ja v a 2 s . com if ("id".equals(type)) { // return "#" + value; // doesn't work for id starting with an int. return "[id='" + value + "']"; } if ("tag name".equals(type)) { return value; } if ("class name".equals(type)) { return "." + value; } if ("class name".equals(type)) { return "." + value; } if ("name".equals(type)) { return "[name='" + value + "']"; } throw new WebDriverException("NI , selector type " + type); }