Search in sources :

Example 1 with SeleniumException

use of com.thoughtworks.selenium.SeleniumException in project jangaroo-tools by CoreMedia.

the class JooTestMojo method executeSelenium.

void executeSelenium(String testsHtmlUrl) throws MojoExecutionException, MojoFailureException {
    jooUnitSeleniumRCHost = System.getProperty("SELENIUM_RC_HOST", jooUnitSeleniumRCHost);
    try {
        // check wether the host is reachable
        // noinspection ResultOfMethodCallIgnored
        InetAddress.getAllByName(jooUnitSeleniumRCHost);
    } catch (UnknownHostException e) {
        throw new MojoExecutionException("Cannot resolve host " + jooUnitSeleniumRCHost + ". Please specify a host running the selenium remote control or skip tests" + " by -DskipTests", e);
    }
    getLog().info("JooTest report directory: " + testResultOutputDirectory.getAbsolutePath());
    Selenium selenium = new DefaultSelenium(jooUnitSeleniumRCHost, jooUnitSeleniumRCPort, jooUnitSeleniumBrowserStartCommand, testsHtmlUrl);
    try {
        selenium.start();
        getLog().debug("Opening " + testsHtmlUrl);
        selenium.open(testsHtmlUrl);
        getLog().debug("Waiting for test results for " + jooUnitTestExecutionTimeout + "ms ...");
        selenium.waitForCondition("selenium.browserbot.getCurrentWindow().result != null || selenium.browserbot.getCurrentWindow().classLoadingError != null", "" + jooUnitTestExecutionTimeout);
        String classLoadingError = selenium.getEval("selenium.browserbot.getCurrentWindow().classLoadingError");
        if (classLoadingError != null && !classLoadingError.equals("null")) {
            throw new MojoExecutionException(classLoadingError);
        }
        String testResultXml = selenium.getEval("selenium.browserbot.getCurrentWindow().result");
        writeResultToFile(testResultXml);
        evalTestOutput(new StringReader(testResultXml));
    } catch (IOException e) {
        throw new MojoExecutionException("Cannot write test results to file", e);
    } catch (ParserConfigurationException e) {
        throw new MojoExecutionException("Cannot create a simple XML Builder", e);
    } catch (SAXException e) {
        throw new MojoExecutionException("Cannot parse test result", e);
    } catch (SeleniumException e) {
        throw new MojoExecutionException("Selenium setup exception", e);
    } finally {
        selenium.stop();
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) SeleniumException(com.thoughtworks.selenium.SeleniumException) StringReader(java.io.StringReader) DefaultSelenium(com.thoughtworks.selenium.DefaultSelenium) Selenium(com.thoughtworks.selenium.Selenium) DefaultSelenium(com.thoughtworks.selenium.DefaultSelenium) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Aggregations

DefaultSelenium (com.thoughtworks.selenium.DefaultSelenium)1 Selenium (com.thoughtworks.selenium.Selenium)1 SeleniumException (com.thoughtworks.selenium.SeleniumException)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 UnknownHostException (java.net.UnknownHostException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 SAXException (org.xml.sax.SAXException)1