List of usage examples for org.openqa.selenium WebDriverException WebDriverException
public WebDriverException(String message, Throwable cause)
From source file:org.agileware.test.web.SharedWebDriver.java
License:Open Source License
/** * Returns the current shared instance or creates a new one using the * <i>selenium.driver</i> system property to determine the delegate * implementation./*from www. j a va 2s. com*/ * * @return the shared instance * @throws WebDriverException * if the delegate implementation cannot be created */ @SuppressWarnings("unchecked") public static SharedWebDriver open() throws WebDriverException { try { Class<?> delegate = Class.forName(System.getProperty(SELENIUM_DRIVER_PROPERTY)); return open((Class<? extends WebDriver>) delegate); } catch (ClassNotFoundException cnfe) { throw new WebDriverException("Driver class not found", cnfe); } }
From source file:org.agileware.test.web.SharedWebDriver.java
License:Open Source License
/** * Returns the current shared instance or creates a new one using the * provided WebDriver implementation type to create the delegate instance. * //from w ww .j av a 2 s.c o m * @param delegate * the WebDriver implementation type * @return the shared instance * @throws WebDriverException * if the delegate instance cannot be created */ public static synchronized SharedWebDriver open(Class<? extends WebDriver> delegate) throws WebDriverException { if (instance == null) { try { instance = new SharedWebDriver(delegate.newInstance()); } catch (Exception e) { throw new WebDriverException("Cannot create delegate", e); } } else { instance.delegate.manage().deleteAllCookies(); } return instance; }
From source file:org.qe4j.web.OpenWebDriver.java
License:Open Source License
public Object executeJavaScript(String script) { JavascriptExecutor javascript = (JavascriptExecutor) webDriver; Object response = null;/*from w w w . ja v a2 s .com*/ log.trace("executing javascript script: [{}]", script); try { response = javascript.executeScript(script); } catch (Exception e) { log.error("javascript failed to execute [{}]", script); throw new WebDriverException("javascript failed to execute: " + e.getMessage(), e); } log.trace("javascript response [{}]", response.toString()); return response; }
From source file:org.uiautomation.ios.client.uiamodels.impl.RemoteIOSObject.java
License:Apache License
/** * Uses reflection to instanciate a remote object implementing the correct interface. * * @return the object. If the object is UIAElementNil, return null for a simple object, an empty * list for a UIAElementArray./*from w w w .j a va 2 s. c o m*/ */ public static WebElement createObject(RemoteWebDriver driver, Map<String, Object> ro) { String ref = ro.get("ELEMENT").toString(); String type = (String) ro.get("type"); if (type != null) { String remoteObjectName = "org.uiautomation.ios.client.uiamodels.impl.Remote" + type; if ("UIAElementNil".equals(type)) { return null; } boolean isArray = false; // uiObject.has("length"); Object[] args = null; Class<?>[] argsClass = null; if (isArray) { // args = new Object[] {driver, ref, uiObject.getInt("length")}; // argsClass = new Class[] {RemoteIOSDriver.class, String.class, // Integer.class}; } else { args = new Object[] { driver, ref }; argsClass = new Class[] { RemoteWebDriver.class, String.class }; } try { Class<?> clazz = Class.forName(remoteObjectName); Constructor<?> c = clazz.getConstructor(argsClass); Object o = c.newInstance(args); RemoteWebElement element = (RemoteWebElement) o; element.setFileDetector(driver.getFileDetector()); element.setParent(driver); element.setId(ref); return (RemoteIOSObject) o; } catch (Exception e) { throw new WebDriverException("error casting", e); } } else { RemoteWebElement element = new RemoteWebElement(); element.setFileDetector(driver.getFileDetector()); element.setId(ref); element.setParent(driver); return element; } }
From source file:org.uiautomation.ios.communication.Helper.java
License:Apache License
public static JSONObject extractObject(HttpResponse resp) { String str = ""; try {// w w w .j ava 2 s .c o m InputStream is = resp.getEntity().getContent(); StringWriter writer = new StringWriter(); IOUtils.copy(is, writer, "UTF-8"); str = writer.toString(); return new JSONObject(str); } catch (Exception e) { throw new WebDriverException(str, e); } }
From source file:org.uiautomation.ios.communication.Helper.java
License:Apache License
public static String extractString(HttpResponse resp) { String str = ""; try {//from www .j a va 2 s. c om InputStream is = resp.getEntity().getContent(); StringWriter writer = new StringWriter(); IOUtils.copy(is, writer, "UTF-8"); str = writer.toString(); return str; } catch (Exception e) { throw new WebDriverException(str, e); } }
From source file:org.uiautomation.ios.inspector.model.IDESessionModelImpl.java
License:Apache License
@Override public JSONObject getStatus() { try {// w w w . ja v a 2 s.co m HttpClient client = HttpClientFactory.getClient(); String url = getEndPoint() + "/status"; URL u = new URL(url); BasicHttpEntityEnclosingRequest r = new BasicHttpEntityEnclosingRequest("GET", url); HttpHost h = new HttpHost(u.getHost(), u.getPort()); HttpResponse response = client.execute(h, r); JSONObject o = Helper.extractObject(response); return o; } catch (Exception e) { throw new WebDriverException(e.getMessage(), e); } }
From source file:org.uiautomation.ios.inspector.views.ResourceView.java
License:Apache License
public void render(HttpServletResponse response) { try {//from w w w . j a v a 2s. c om response.setContentType(mime); IOUtils.copy(is, response.getOutputStream()); IOUtils.closeQuietly(is); } catch (IOException e) { throw new WebDriverException("Cannot load the requested resource : " + e.getMessage(), e); } }
From source file:org.uiautomation.ios.mobileSafari.events.EventFactory.java
License:Apache License
public static Event createEvent(JSONObject message) { try {/*from w ww. ja va 2s. c o m*/ Event e = createObject(message); return e; } catch (Exception e) { log.log(Level.WARNING, "TODO", e); throw new WebDriverException("Error creating an event generated by the webview:" + message, e); } }
From source file:org.uiautomation.ios.server.application.APPIOSApplication.java
License:Apache License
private String getFirstIconFile(String bundleIcons) { if (!metadata.has(bundleIcons)) { return ""; }/*w ww. j ava2s. co m*/ try { HashMap icons = (HashMap) metadata.get(bundleIcons); HashMap primaryIcon = (HashMap) icons.get("CFBundlePrimaryIcon"); ArrayList iconFiles = (ArrayList) primaryIcon.get("CFBundleIconFiles"); return iconFiles.get(0).toString(); } catch (JSONException e) { throw new WebDriverException("property 'CFBundleIcons' can't be returned. " + e.getMessage(), e); } }