use of org.openqa.selenium.By.ById in project antlr4 by antlr.
the class BaseBrowserTest method execHtmlPage.
public String execHtmlPage(String fileName, String input) throws Exception {
// 'file' protocol is not supported by Selenium drivers
// so we run an embedded Jetty server
ServerThread thread = new ServerThread(fileName);
thread.start();
try {
while (thread.server == null && thread.ex == null) Thread.sleep(10);
if (thread.ex != null)
throw thread.ex;
while (thread.server.isStarting()) Thread.sleep(10);
// despite all the above precautions, driver.get often fails if you don't give time to Jetty
Thread.sleep(400);
driver.get("http://localhost:" + httpPort + "/" + fileName);
driver.findElement(new ById("input")).clear();
driver.findElement(new ById("output")).clear();
driver.findElement(new ById("errors")).clear();
driver.navigate().refresh();
driver.findElement(new ById("input")).sendKeys(input);
driver.findElement(new ById("load")).click();
driver.findElement(new ById("submit")).click();
String errors = driver.findElement(new ById("errors")).getAttribute("value");
if (errors != null && errors.length() > 0) {
this.stderrDuringParse = errors;
System.err.print(errors);
}
String value = driver.findElement(new ById("output")).getAttribute("value");
// mimic stdout which adds a NL
if (value.length() > 0 && !value.endsWith("\n"))
value = value + "\n";
return value;
} catch (Exception e) {
System.err.println("can't exec recognizer");
e.printStackTrace(System.err);
} finally {
if (thread.server != null) {
thread.server.stop();
while (!thread.server.isStopped()) Thread.sleep(10);
// ensure the port is freed
Thread.sleep(100);
}
}
return null;
}
Aggregations