下面列出了怎么用cucumber.api.java.en.Then的API类实例代码及写法,或者点击链接到github查看源代码。
@Then("^s?he should see the list of (.*) with prices available for sale$")
public void she_should_see_the_list_of_items_with_prices_available_for_sale(List<String> items) {
theActorInTheSpotlight().should(
seeThat(SearchResults.resultsGrid(), is(Available)),
seeThat(SearchResults.checkForTitle(), containsString("product")),
seeThat(SearchResults.price(), is(Available))
);
}
@Then("^he should see the total cost including shipping:$")
public void he_should_see_the_total_cost_including_shipping(DataTable arg1) {
theActorInTheSpotlight().attemptsTo(ProceedToCheckOut.fromCartSummaryPopup());
theActorInTheSpotlight().attemptsTo(ProceedToCheckOut.fromCheckoutSummary());
theActorInTheSpotlight().should(
seeThat(Checkout.totalPrice(), containsString(arg1.raw().get(1).get(2)))
);
}
@Then("I have (\\d) items? in my cart")
public void one_item_in_cart(Integer items) {
String expected_items = items.toString();
By itemsInCart = By.className("shopping_cart_badge");
wait.until(ExpectedConditions.elementToBeClickable(getDriver().findElement(itemsInCart)));
Assert.assertEquals(getDriver().findElement(itemsInCart).getText(), expected_items);
}
@Then("^return error message \"(.*)\"$")
public void return_error_message_indicating_product_is_not_found(String errMsg) throws Throwable {
Assert.assertTrue(errResponse.getBody().contains(errMsg));
}
@Then("^return error message \"(.*)\"$")
public void return_error_message_indicating_product_is_not_found(String errMsg) throws Throwable {
Assert.assertTrue(errResponse.getBody().contains(errMsg));
}
@Then("^I receive (.*) as a result$")
public void i_receive_as_a_result(String expectedResult) throws Throwable {
assertEquals(expectedResult, result);
}
@Then("^I receive (.*) as a result$")
public void i_receive_as_a_result(String expectedResult) throws Throwable {
assertEquals(expectedResult, result);
}
@Then("^verify: \\$\\{([^\"]*)}<long: ([^\"]*)$")
public void verifyVariableLessThanLong(String expression, String expected) {
assertThat((Long) variables.get(expression), lessThan(parseLong(expected)));
}
@Then("^verify: \\$\\{([^\"]*)}>=long: ([^\"]*)$")
public void verifyVariableGreaterThanOrEqualToLong(String expression, String expected) {
assertThat((Long) variables.get(expression), greaterThanOrEqualTo(parseLong(expected)));
}
@Then("^I receive (.*) as a result$")
public void i_receive_as_a_result(String expectedResult) throws Throwable {
assertEquals(expectedResult, result);
}
@Then("^[a-z,A-Z]{1,50} debe ver la pagina de inicio$")
public void debeVerLaPaginaDeInicio() {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
@Then("^verify: '([^\"]*)'=code file: ([^\"]*)$")
public void verifyEqualsCodeInFile(String path, String file) throws IOException, ScriptException {
assertThat(actual.json(path), is(eval(expressions.evaluate(read(configuration.classpathFile(file))))));
}
@Then("^verify: '([^\"]*)'<float: (\\d+\\.\\d+)$")
public void verifyLessThanFloat(String path, String expected) throws Throwable {
assertThat((Float) actual.json(path), lessThan(parseFloat(expected)));
}
@Then("^book title will be ([^\"]*)$")
public void book_title_will_be(String bookTitle) throws Throwable {
assertNotNull(loadedBook);
assertEquals(bookTitle, loadedBook.getTitle());
}
@Then("^verify: \\$\\{([^\"]*)}<=double: (\\d+\\.\\d+)$")
public void verifyVariableLessThanOrEqualToDouble(String expression, String expected) {
assertThat((double) variables.get(expression), lessThanOrEqualTo(Double.parseDouble(expected)));
}
@Then("^verify: \\$\\{([^\"]*)} length: (\\d+)$")
public void verifyVariableStringLength(String expression, int length) {
assertThat(String.valueOf(variables.get(expression)).length(), is(length));
}
@Then("^book title will be ([^\"]*)$")
public void book_title_will_be(String bookTitle) throws Throwable {
assertNotNull(loadedBook);
assertEquals(bookTitle, loadedBook.getTitle());
}
@Then("^verify: '([^\"]*)'>(\\d+)$")
public void verifyGreaterThanInteger(String path, final int expected) throws Throwable {
assertThat((int) actual.json(path), greaterThan(expected));
}
@Then("^response content contains ([^\"]*)$")
public void response_content_contains(String content)
throws Throwable {
assertNotNull(result);
result.andExpect(content().string(containsString(content)));
}
@Then("^book title will be ([^\"]*)$")
public void book_title_will_be(String bookTitle) throws Throwable {
assertNotNull(loadedBook);
assertEquals(bookTitle, loadedBook.getTitle());
}
@Then("^status code will be ([\\d]*)$")
public void status_code_will_be(int code) throws
Throwable {
assertNotNull(result);
result.andExpect(status().is(code));
}
@Then("^response content contains ([^\"]*)$")
public void response_content_contains(String content)
throws Throwable {
assertNotNull(result);
result.andExpect(content().string(containsString(content)));
}
@Then("^book title will be ([^\"]*)$")
public void book_title_will_be(String bookTitle) throws Throwable {
assertNotNull(loadedBook);
assertEquals(bookTitle, loadedBook.getTitle());
}
@Then("^verify: '([^\"]*)'=long: ([^\"]*)$")
public void verifyEqualsLong(String path, String expected) throws Throwable {
assertThat(actual.json(path), is(parseLong(expected)));
}
@Then("^response content contains ([^\"]*)$")
public void response_content_contains(String content)
throws Throwable {
assertNotNull(result);
result.andExpect(content().string(containsString(content)));
}
@Then("^book title will be ([^\"]*)$")
public void book_title_will_be(String bookTitle) throws Throwable {
assertNotNull(loadedBook);
assertEquals(bookTitle, loadedBook.getTitle());
}
@Then("^verify: '([^\"]*)' has size: (\\d+)$")
public void hasSize(String path, Integer size) throws IOException {
assertThat(size(actual.json(path)), is(size));
}
@Then("^I validate the outcomes$")
public void i_validate_the_outcomes() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
@Then("^verify: '([^\"]*)'>=long: ([^\"]*)$")
public void verifyGreaterThanOrEqualToLong(String path, String expected) throws Throwable {
assertThat((Long) actual.json(path), greaterThanOrEqualTo(parseLong(expected)));
}
@Then("^verify: \\$\\{([^\"]*)}<double: (\\d+\\.\\d+)$")
public void verifyVariableLessThanDouble(String expression, String expected) {
assertThat((double) variables.get(expression), lessThan(Double.parseDouble(expected)));
}