List of usage examples for org.openqa.selenium WebDriverException WebDriverException
public WebDriverException(Throwable cause)
From source file:com.virtusa.isq.vtaf.runtime.SeleniumTestBase.java
License:Apache License
/** * Opens an URL in the test frame. This accepts both relative and absolute * URLs. The "open" command <br>//from w w w .j a va2 s . co m * waits for the page to load before proceeding, ie. the "AndWait" suffix is * implicit. Note: The URL <br> * must be on the same domain as the runner HTML due to security * restrictions in the browser <br> * (Same Origin Policy). If you need to open an URL on another domain, use * the Selenium Server <br> * to start a new browser session on that domain. * * @param locator * : url of the openning page * @param waitTime * : time to wait till the page is loaded. * * */ private void doOpen(final ObjectLocator locator, final String waitTime) { String url = ""; WebDriver driver = getDriver(); try { url = locator.getActualLocator(); if ("default".equalsIgnoreCase(url)) { PropertyHandler propertyHandler = new PropertyHandler("runtime.properties"); url = propertyHandler.getRuntimeProperty("DEFAULT_URL"); if ("".equals(url)) { throw new WebDriverException("Empty URL : " + url); } } setCommandStartTime(getCurrentTime()); driver.get(url); try { driver.manage().timeouts().implicitlyWait(Integer.parseInt(waitTime), TimeUnit.MILLISECONDS); } catch (Exception e) { e.printStackTrace(); } reportresult(true, "OPEN : " + url + "", "PASSED", url); } catch (WebDriverException e) { String errorString = e.getMessage(); reportresult(true, "OPEN : " + url + "", "FAILED", "Cannot access the empty URL. URL : " + url + ". Actual Error : " + errorString); checkTrue(false, true, "Cannot access the empty URL. URL : " + url + ". Actual Error : " + errorString); } catch (Exception e) { String errorString = e.getMessage(); reportresult(true, "OPEN : " + url + "", "FAILED", "Cannot access the URL. URL : " + url + ". Actual Error : " + errorString); checkTrue(false, true, "Cannot access the URL. URL : " + url + ". Actual Error : " + errorString); } }
From source file:com.virtusa.isq.vtaf.runtime.SeleniumTestBase.java
License:Apache License
/** * Arguments: <br>//from ww w . jav a 2 s . c o m * <br> * * windowID - the JavaScript window ID of the window to select<br> * * Selects a popup window using a window locator; once a popup window has * been selected, all commands go to that window. To select the main window * again, use null as the target.<br> * <br> * * Window locators provide different ways of specifying the window object: * by title, by internal JavaScript "name," or by JavaScript variable.<br> * <br> * * title=My Special Window: Finds the window using the text that appears in * the title bar. Be careful; two windows can share the same title. If that * happens, this locator will just pick one.<br> * name=myWindow: Finds the window using its internal JavaScript "name" * property. This is the second parameter "windowName" passed to the * JavaScript method window.open(url, windowName, windowFeatures, * replaceFlag) (which Selenium intercepts).<br> * var=variableName: Some pop-up windows are unnamed (anonymous), but are * associated with a JavaScript variable name in the current application * window, e.g. "window.foo = window.open(url);". In those cases, you can * open the window using "var=foo".<br> * <br> * * If no window locator prefix is provided, we'll try to guess what you mean * like this:<br> * <br> * * 1.) if windowID is null, (or the string "null") then it is assumed the * user is referring to the original window instantiated by the browser).<br> * <br> * * 2.) if the value of the "windowID" parameter is a JavaScript variable * name in the current application window, then it is assumed that this * variable contains the return value from a call to the JavaScript * window.open() method.<br> * <br> * * 3.) Otherwise, selenium looks in a hash it maintains that maps string * names to window "names".<br> * <br> * * 4.) If that fails, we'll try looping over all of the known windows to try * to find the appropriate "title". Since "title" is not necessarily unique, * this may have unexpected behavior.<br> * <br> * * If you're having trouble figuring out the name of a window that you want * to manipulate, look at the Selenium log messages which identify the names * of windows created via window.open (and therefore intercepted by * Selenium). You will see messages like the following for each window as it * is opened:<br> * <br> * * debug: window.open call intercepted; window ID (which you can use with * selectWindow()) is "myNewWindow"<br> * <br> * * In some cases, Selenium will be unable to intercept a call to window.open * (if the call occurs during or before the "onLoad" event, for example). * (This is bug SEL-339.) In those cases, you can force Selenium to notice * the open window's name by using the Selenium openWindow command, using an * empty (blank) url, like this: openWindow("", "myFunnyWindow").<br> * <br> * * @param locator * : Logical name of the window assigned by the test scriptor * * * */ private void doSelectWindow(final ObjectLocator locator) { int counter = getRetryCount(); String targetWindow = null; WebDriver driver = getDriver(); // Getting the actual object identification from the object map String window = locator.getActualLocator(); try { checkForNewWindowPopups(); /* * START DESCRIPTION following for loop was added to make the * command more consistent try the command for give amount of time * (can be configured through class variable RETRY) command will be * tried for "RETRY" amount of times or untill command works. any * exception thrown within the tries will be handled internally. * * can be exited from the loop under 2 conditions 1. if the command * succeeded 2. if the RETRY count is exceeded */ while (counter > 0) { try { counter--; targetWindow = getMatchingWindowFromCurrentWindowHandles(driver, window); if (targetWindow != null) { driver.switchTo().window(targetWindow); driver.manage().window().maximize(); focusToCurrentWindow(driver); reportresult(true, "SELECT WINDOW :" + locator.getLogicalName() + "", "PASSED", ""); break; } else { throw new WebDriverException("Window Not Found" + window); } } catch (WebDriverException ex) { sleep(retryInterval); if (!(counter > 0)) { String errorString = ex.getMessage(); String objectName = locator.getLogicalName(); reportresult(true, "SELECT WINDOW :" + objectName + "", "FAILED", "selectWindow command :Element (" + objectName + ") [" + window + "] is not accessible. Actual Error : " + errorString); checkTrue(false, true, "selectWindow command :Element (" + objectName + ") [" + window + "] is not accessible. Actual Error : " + errorString); } } } } catch (Exception e) { e.printStackTrace(); String objectName = locator.getLogicalName(); // if any exception is raised, report failure reportresult(true, "SELECT WINDOW :" + objectName + "", "FAILED", "selectWindow command :Element (" + objectName + ") [" + window + "] not present"); checkTrue(false, true, "selectWindow command :Element (" + objectName + ") [" + window + "] not present"); } }
From source file:com.wikia.webdriver.pageobjectsfactory.pageobject.WikiBasePageObject.java
License:Open Source License
/** * Logout by navigating to 'logout' button href attribute value; *///from w w w .j av a 2 s. c om public void logOut() { try { if (navigationLogoutLink.getAttribute("href") != null) { driver.get(navigationLogoutLink.getAttribute("href")); } else { throw new WebDriverException("No logout link provided"); } } catch (TimeoutException e) { PageObjectLogging.log("logOut", "page loads for more than 30 seconds", true); } }
From source file:com.wikia.webdriver.pageobjectsfactory.pageobject.WikiBasePageObject.java
License:Open Source License
public void verifyWgVariableValuesTheSame(Object[] value1, Object[] value2) { Arrays.sort(value1);/* w w w . j ava 2s . c o m*/ Arrays.sort(value2); if (Arrays.equals(value1, value2)) { PageObjectLogging.log("VariablesAreTheSame", "Variable on wiki and on community are the same", true, driver); } else { throw new WebDriverException("Values on community and on wiki are different"); } }
From source file:crazy.seleiumTools.ProfilesIni.java
License:Apache License
private void getinfoOfPro() { BufferedReader reader = null; try {/*from w w w . j a v a 2 s . com*/ reader = new BufferedReader(new FileReader(this.profiles_ini)); String line = reader.readLine(); while (line != null) { if (line.startsWith("Name=")) { this.nameOfpro = line.substring("Name=".length()); } else if (line.startsWith("Path=")) { this.pathOfpro = line.substring("Path=".length()); } line = reader.readLine(); } reader.close(); } catch (IOException e) { throw new WebDriverException(e); } }
From source file:crazy.seleiumTools.ProfilesIni.java
License:Apache License
protected Map<String, File> readProfiles(File appData) { Map<String, File> toReturn = Maps.newHashMap(); File profilesIni = new File(appData, "profiles.ini"); this.profiles_ini = profilesIni; if (!profilesIni.exists()) { // Fine. No profiles.ini file return toReturn; }//from w ww. j a va2s .c o m boolean isRelative = true; String name = null; String path = null; BufferedReader reader = null; try { reader = new BufferedReader(new FileReader(profilesIni)); String line = reader.readLine(); while (line != null) { if (line.startsWith("[Profile")) { File profile = newProfile(name, appData, path, isRelative); if (profile != null) toReturn.put(name, profile); name = null; path = null; } else if (line.startsWith("Name=")) { name = line.substring("Name=".length()); } else if (line.startsWith("IsRelative=")) { isRelative = line.endsWith("1"); } else if (line.startsWith("Path=")) { path = line.substring("Path=".length()); } line = reader.readLine(); } } catch (IOException e) { throw new WebDriverException(e); } finally { try { if (reader != null) { File profile = newProfile(name, appData, path, isRelative); if (profile != null) toReturn.put(name, profile); reader.close(); } } catch (IOException e) { // Nothing that can be done sensibly. Swallowing. } } return toReturn; }
From source file:crazy.seleiumTools.ProfilesIni.java
License:Apache License
public FirefoxProfile getDefaultProfile() { String profileName = this.nameOfpro; File profileDir = profiles.get(profileName); if (profileDir == null) return null; // Make a copy of the profile to use File tempDir = TemporaryFilesystem.getDefaultTmpFS().createTempDir("userprofile", "copy"); try {/*from w w w . java 2 s. co m*/ FileHandler.copy(profileDir, tempDir); // Delete the old compreg.dat file so that our new extension is registered File compreg = new File(tempDir, "compreg.dat"); if (compreg.exists()) { if (!compreg.delete()) { throw new WebDriverException("Cannot delete file from copy of profile " + profileName); } } } catch (IOException e) { throw new WebDriverException(e); } return new FirefoxProfile(tempDir); }
From source file:crazy.seleiumTools.ProfilesIni.java
License:Apache License
public FirefoxProfile getProfile(String profileName) { File profileDir = profiles.get(profileName); if (profileDir == null) return null; // Make a copy of the profile to use File tempDir = TemporaryFilesystem.getDefaultTmpFS().createTempDir("userprofile", "copy"); try {/*from ww w . j a v a2 s .c om*/ FileHandler.copy(profileDir, tempDir); // Delete the old compreg.dat file so that our new extension is registered File compreg = new File(tempDir, "compreg.dat"); if (compreg.exists()) { if (!compreg.delete()) { throw new WebDriverException("Cannot delete file from copy of profile " + profileName); } } } catch (IOException e) { throw new WebDriverException(e); } return new FirefoxProfile(tempDir); }
From source file:crazy.seleiumTools.ProfilesIni.java
License:Apache License
public File locateAppDataDirectory(Platform os) { File appData;/* w w w. ja v a2 s.c om*/ if (os.is(WINDOWS)) { appData = new File(MessageFormat.format("{0}\\Mozilla\\Firefox", System.getenv("APPDATA"))); } else if (os.is(MAC)) { appData = new File( MessageFormat.format("{0}/Library/Application Support/Firefox", System.getenv("HOME"))); } else { appData = new File(MessageFormat.format("{0}/.mozilla/firefox", System.getenv("HOME"))); } if (!appData.exists()) { // It's possible we're being run as part of an automated build. // Assume the user knows what they're doing return null; } if (!appData.isDirectory()) { throw new WebDriverException("The discovered user firefox data directory " + "(which normally contains the profiles) isn't a directory: " + appData.getAbsolutePath()); } return appData; }
From source file:edu.umd.cs.guitar.model.WebWindowCreator.java
License:Open Source License
private void checkForClosed() { if (handle == null || handle.equals("")) throw new WebDriverException("Web Window closed or not initialized"); }