when:
doUserLogIn()
expect:
at HomePage
// The Firefox driver supports javascript
WebDriver driver = new FirefoxDriver();
// Go to the Google Suggest home page
driver.get("http://www.google.com/webhp?complete=1&hl=en");
// Enter the query string "Cheese"
WebElement query = driver.findElement(By.name("q"));
query.sendKeys("Cheese");
// Sleep until the div we want is visible or 5 seconds is over
long end = System.currentTimeMillis() + 5000;
while (System.currentTimeMillis() < end) {
WebElement resultsDiv = driver.findElement(By.className("gssb_e"));
// If results have been returned, the results are displayed in a drop down.
if (resultsDiv.isDisplayed()) {
break;
}
}
// And now list the suggestions
List<WebElement> allSuggestions = driver.findElements(By.xpath("//td[@class='gssb_a gbqfsf']"));
for (WebElement suggestion : allSuggestions) {
System.out.println(suggestion.getText());
}
driver.quit();
class GoogleHomePage extends Page {
static url = "http://google.com/?complete=0"
static at = { title == "Google" }
static content = {
searchField { $("input[name=q]") }
searchButton(to: GoogleResultsPage) { $("input[value='Google Search']") }
}
void search(String searchTerm) {
searchField.value searchTerm
searchButton.click()
}
}
class GoogleResultsPage extends Page { ... }
Browser.drive {
to GoogleHomePage
search "Chuck Norris"
at GoogleResultsPage
resultLink(0).text().contains("Chuck")
}
class GoogleHomePage extends Page { static url = "http://google.com/?complete=0" static at = { title == "Google" } static content = { searchField { $("input[name=q]") } searchButton(to: GoogleResultsPage) {
$("input[value='Google Search']")
} } void search(String searchTerm) { searchField.value searchTerm searchButton.click() } }
page.searchField
class ExampleModule extends Module {
static content = {
button { $("input", type: "submit") }
}
}
class ExamplePage extends Page {
static content = {
theModule { module ExampleModule }
}
}
"Run your web and mobile apptests across hundreds of realbrowsers and platforms instantly"
Mocha is a feature-rich JavaScript test framework running on node.js and the browser, making asynchronous testing simple and fun. Mocha tests run serially, allowing for flexible and accurate reporting, while mapping uncaught exceptions to the correct test cases.