Example usage for org.openqa.selenium WebDriverException getMessage

List of usage examples for org.openqa.selenium WebDriverException getMessage

Introduction

In this page you can find the example usage for org.openqa.selenium WebDriverException getMessage.

Prototype

@Override
    public String getMessage() 

Source Link

Usage

From source file:com.seleniumtests.uipage.PageObject.java

License:Apache License

/**
 * Close a PageObject. This method can be called when a web session opens several pages and one of them is closed after some action
 * In case there are multiple windows opened, switch back to the previous window in the list
 * /*  w w w  .ja va2s  .c  om*/
 * @throws NotCurrentPageException
 */
public final void close() {

    if (WebUIDriver.getWebDriver() == null) {
        return;
    }

    SeleniumTestsPageListener.informPageUnload(this);
    TestLogging.info("close web page: " + getTitle());

    boolean isMultipleWindow = false;
    List<String> handles = new ArrayList<>(driver.getWindowHandles());
    if (handles.size() > 1) {
        isMultipleWindow = true;
    }
    logger.debug("Current handles: " + handles);

    try {
        driver.close();
    } catch (WebDriverException ignore) {
        logger.info("Error closing driver: " + ignore.getMessage());
    }

    // wait a bit before going back to main window
    WaitHelper.waitForSeconds(2);

    try {
        if (isMultipleWindow) {
            try {
                selectWindow(handles.get(handles.indexOf(windowHandle) - 1));
            } catch (IndexOutOfBoundsException | NoSuchWindowException e) {
                selectMainWindow();
            }
        } else {
            WebUIDriver.setWebDriver(null);
        }
    } catch (UnreachableBrowserException ex) {
        WebUIDriver.setWebDriver(null);

    }
}

From source file:com.tascape.qa.th.webui.comm.Firefox.java

License:Apache License

public Firefox(boolean enableFirebug) throws Exception {
    FirefoxProfile profile;/*  w w w  . j a  v  a 2s .  c om*/

    ProfilesIni profileIni = new ProfilesIni();
    String profileName = sysConfig.getProperty(SYSPROP_FF_PROFILE_NAME);
    if (profileName != null) {
        LOG.debug("Load Firefox profile named as {}", profileName);
        profile = profileIni.getProfile(profileName);
    } else {
        LOG.debug("Load Firefox profile named as {}", DEFAULT_FF_PROFILE_NAME);
        profile = profileIni.getProfile(DEFAULT_FF_PROFILE_NAME);
    }
    if (profile == null) {
        throw new Exception("Cannot find Firefox profile");
    }

    profile.setPreference("app.update.enabled", false);
    profile.setEnableNativeEvents(false);
    profile.setAcceptUntrustedCertificates(true);
    profile.setAssumeUntrustedCertificateIssuer(false);
    profile.setPreference("dom.max_chrome_script_run_time", 0);
    profile.setPreference("dom.max_script_run_time", 0);
    if (enableFirebug) {
        this.firebug = new Firebug();
        this.firebug.updateProfile(profile);
    }
    long end = System.currentTimeMillis() + 180000;
    while (System.currentTimeMillis() < end) {
        try {
            super.setWebDriver(new FirefoxDriver(profile));
            break;
        } catch (org.openqa.selenium.WebDriverException ex) {
            String msg = ex.getMessage();
            LOG.warn(msg);
            if (!msg.contains("Unable to bind to locking port 7054 within 45000 ms")) {
                throw ex;
            }
        }
    }
}

From source file:com.thoughtworks.selenium.InternalSelenseTestBase.java

License:Apache License

@BeforeClass
public static void buildJavascriptLibraries() throws IOException {
    if (!DevMode.isInDevMode()) {
        return;/*from  ww  w .  j  av a2s. c om*/
    }

    log.info("In dev mode. Copying required files in case we're using a WebDriver-backed Selenium");

    try {
        new Build().of("//java/client/src/org/openqa/selenium/internal/seleniumemulation",
                "//third_party/js/sizzle").go();

        File buildDir = InProject
                .locate("java/client/build/production/org/openqa/selenium/internal/seleniumemulation");
        buildDir = new File(buildDir, "selenium_atoms");
        if (!buildDir.exists()) {
            assertTrue(buildDir.mkdir());
        }
        File atomsDir = InProject.locate("build/javascript/selenium-atoms");

        for (File file : atomsDir.listFiles()) {
            if (file.getName().endsWith(".js")) {
                File dest = new File(buildDir, file.getName());
                Files.copy(file, dest);
            }
        }

        File sizzle = InProject.locate("third_party/js/sizzle/sizzle.js");
        Files.copy(sizzle, new File(buildDir, "sizzle.js"));

        File seDir = InProject.locate("java/client/test/com/thoughtworks/selenium");
        File destDir = InProject.locate("java/client/build/production/com/thoughtworks/selenium");
        for (File file : seDir.listFiles()) {
            if (file.getName().endsWith(".js")) {
                File dest = new File(destDir, file.getName());
                Files.copy(file, dest);
            }
        }

    } catch (WebDriverException e) {
        System.err.println("Cannot build javascript libraries for selenium emulation: " + e.getMessage());
    }
}

From source file:com.thoughtworks.selenium.webdriven.SeleneseCommand.java

License:Apache License

public T apply(WebDriver driver, String[] args) {
    try {//  w ww.  j  ava  2s. co  m
        switch (args.length) {
        case 0:
            return handleSeleneseCommand(driver, null, null);

        case 1:
            return handleSeleneseCommand(driver, args[0], null);

        case 2:
            return handleSeleneseCommand(driver, args[0], args[1]);

        default:
            throw new SeleniumException("Too many arguments! " + args.length);
        }
    } catch (WebDriverException e) {
        throw new SeleniumException(e.getMessage(), e);
    }
}

From source file:com.vilt.minium.WebElementsException.java

License:Apache License

protected static String getMessage(Throwable cause) {
    if (cause == null)
        return null;
    if (!(cause instanceof WebDriverException))
        return cause.getMessage();

    WebDriverException wdCause = (WebDriverException) cause;

    // we don't really want all that supporUrl and build stuff into our
    // message//from  w  w  w . j a  v a  2  s . co  m
    // so let's remove that
    String message = wdCause.getMessage();
    int idx = message.indexOf("\nFor documentation on this error, please visit:");
    if (idx < 0)
        idx = message.indexOf("\nBuild info:");

    return idx < 0 ? message : message.substring(0, idx);
}

From source file:com.virtusa.isq.vtaf.runtime.SeleniumTestBase.java

License:Apache License

/**
 * Arguments: <br>//from w w  w.  j  a v a  2 s.com
 * <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:contentspeed.CosCumparaturi.java

public void Completeaza(String prenume, String nume, String email, String telefon, String observatii,
        String judet, String oras, String adresa) {

    try {/*  w  w  w.java  2s.c o  m*/

        CompleteazaPrenume(prenume);
        CompleteazaNume(nume);
        CompleteazaEmail(email);
        CompleteazaTelefon(telefon);
        CompleteazaObservatii(observatii);
        CompleteazaAdresa(judet, oras, adresa);
        //selectPlata(plata);
        //findPF();
        //findDelivery();
        findClickTermeni();
        findclikFinalizeaza();

        if (!ExistsErrorEmail()) {

            System.out.println(driver.findElement(comandaFinalizata).getText());

            Assert.assertEquals("Comanda finalizata", driver.findElement(comandaFinalizata).getText());

            //System.out.println("check if message is displayed: " + driver.findElement(comandaFinalizata).isDisplayed());
        }

    } catch (WebDriverException ex) {
        ex.getMessage();
        driver.quit();

    }

}

From source file:contentspeed.ProdusCeai.java

public void Completeaza(String prenume, String nume, String email, String telefon, String judet, String oras,
        String adresa, String observatii) {

    try {/*from ww w .  j  a  v  a  2s  .  c om*/

        CompleteazaPrenume(prenume);
        CompleteazaNume(nume);
        CompleteazaEmail(email);
        CompleteazaTelefon(telefon);

        CompleteazaAdresa(judet, oras, adresa);
        CompleteazaObservatii(observatii);
        //selectPlata(plata);
        //findPF();
        //findDelivery();
        findClickTermeni();
        findclikFinalizeaza();

        if (!ExistsErrorEmail()) {

            System.out.println(driver.findElement(comandaFinalizata).getText());

            //System.out.println("check if message is displayed: " + driver.findElement(comandaFinalizata).isDisplayed());
        }

    } catch (WebDriverException ex) {
        ex.getMessage();
        driver.quit();

    }
}

From source file:contentspeed.ProdusCeaiIE11.java

public void Completeaza(String prenume, String nume, String email, String telefon, String observatii,
        String judet, String oras, String adresa) {

    try {//  w  w w.j  a v a 2  s. c  o  m

        JavascriptExecutor js = ((JavascriptExecutor) driver);
        js.executeScript("window.scrollTo(0, document.body.scrollHeight)");
        CompleteazaPrenume(prenume);
        CompleteazaNume(nume);
        CompleteazaEmail(email);
        CompleteazaTelefon(telefon);
        CompleteazaObservatii(observatii);
        CompleteazaAdresa(judet, oras, adresa);
        //selectPlata(plata);
        //findPF();
        //findDelivery();
        findClickTermeni();
        findclikFinalizeaza();

        if (!ExistsErrorEmail()) {

            System.out.println(driver.findElement(comandaFinalizata).getText());

            Assert.assertEquals("Comanda finalizata", driver.findElement(comandaFinalizata).getText());

            //System.out.println("check if message is displayed: " + driver.findElement(comandaFinalizata).isDisplayed());
        }

    } catch (WebDriverException ex) {
        ex.getMessage();
        driver.quit();

    }
}

From source file:daveayan.gherkinsalad.browser.Browser.java

License:Open Source License

/**
 * Use this method to close the currently open browser.
 *///  w  w w  .  ja  va  2s  . c  o  m
public void close() {
    try {
        if (instance != null) {
            instance.close();
            instance.quit();
        }
    } catch (WebDriverException wde) {
        System.err.println(wde.getMessage());
    }
    instance = null;
    default_window_handle = StringUtils.EMPTY;
}