use of com.thoughtworks.selenium.DefaultSelenium 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();
}
}
Aggregations