下面列出了怎么用cucumber.api.java.en.And的API类实例代码及写法,或者点击链接到github查看源代码。
@And("^send (.+) (.+)$")
public void sendMethodPath(String method, String path) {
URI fullUrl = URI.create(processFullUrl(path));
switch (method) {
case "GET":
response = request.get(fullUrl).then();
break;
case "POST":
final String fullUrlStr="http://127.0.0.1:" + port + path;
response = request.post(URI.create(fullUrlStr)).then();
break;
case "PUT":
response = request.put(fullUrl).then();
break;
case "PATCH":
response = request.patch(fullUrl).then();
break;
case "DELETE":
response = request.delete(fullUrl).then();
break;
default:
break;
}
}
@And("I remove an item")
public void remove_an_item(){
By itemButton = By.className("btn_secondary");
wait.until(ExpectedConditions.elementToBeClickable(getDriver().findElement(itemButton)));
getDriver().findElement(itemButton).click();
}
@And("^I see Unpack WAR checkbox is \"(.*)\"$")
public void checkUnpackWarFlag(final String flag) {
if (flag.equalsIgnoreCase("checked")){
assertTrue(jwalaUi.isCheckBoxChecked(By.name("unpackWar")));
} else if (flag.equalsIgnoreCase("unchecked")) {
assertFalse(jwalaUi.isCheckBoxChecked(By.name("unpackWar")));
}
}
@And("^I choose \"([^\"]*)\" as my city$")
public void iChooseAsMyCity(String city) throws Throwable {
new LandingPage(appiumDriver).skipToHomePage();
/* TODO - Assignment - Move the try catch logic to base page */
try {
if (appiumDriver.findElement(By.xpath("//android.widget.Button[@text='Later']")).isDisplayed())
appiumDriver.findElement(By.xpath("//android.widget.Button[@text='Later']")).click();
} catch (Exception e) {
//do nothing
}
new HomePage(appiumDriver).selectCity(city);
}
/**
* Производится сохранение заголовка страницы в переменную
*/
@И("^заголовок страницы сохранен в переменную \"([^\"]*)\"$")
@And("^page's header has been saved to the \"([^\"]*)\" variable$")
public void savePageTitleToVariable(String variableName) {
String titleName = getWebDriver().getTitle().trim();
akitaScenario.setVar(variableName, titleName);
akitaScenario.write("Значение заголовка страницы [" + titleName + "] сохранено в переменную [" + variableName + "]");
}
/**
* Посылается http запрос по заданному урлу без параметров и BODY.
* Проверяется, что код ответа соответствует ожиданиям.
* URL можно задать как напрямую в шаге, так и указав в application.properties
*/
@И("^выполнен (GET|POST|PUT|DELETE) запрос на URL \"([^\"]*)\". Ожидается код ответа: (\\d+)$")
@And("^(GET|POST|PUT|DELETE) request to URL \"([^\"]*)\" has been executed. Expected response code: (\\d+)$")
public void checkResponseCodeWithoutParams(String method, String address, int expectedStatusCode) throws Exception {
Response response = sendRequest(method, address, new ArrayList<>());
assertTrue(checkStatusCode(response, expectedStatusCode));
}
/**
* Посылается http запрос по заданному урлу с заданными параметрами.
* Проверяется, что код ответа соответствует ожиданиям.
* URL можно задать как напрямую в шаге, так и указав в application.properties
* Content-Type при необходимости должен быть указан в качестве header.
*/
@И("^выполнен (GET|POST|PUT|DELETE) запрос на URL \"([^\"]*)\" с headers и parameters из таблицы. Ожидается код ответа: (\\d+)$")
@And("^(GET|POST|PUT|DELETE) request to URL \"([^\"]*)\" with headers and parametres from the table has been executed. Expected response code: (\\d+)$")
public void checkResponseCode(String method, String address, int expectedStatusCode, List<RequestParam> paramsTable) throws Exception {
Response response = sendRequest(method, address, paramsTable);
assertTrue(checkStatusCode(response, expectedStatusCode));
}
/**
* Устанавливается значение переменной в хранилище переменных. Один из кейсов: установка login пользователя
*/
@И("^установлено значение переменной \"([^\"]*)\" равным \"(.*)\"$")
@And("^value of the variable \"([^\"]*)\" has been set to \"(.*)\"$")
public void setVariable(String variableName, String value) {
value = getPropertyOrValue(value);
akitaScenario.setVar(variableName, value);
}
@And("^I expect the response error message to include:$")
public void and_I_expect_the_response_error_message_include(String expected) {
assertNotNull(exception);
assertTrue(exception instanceof AmazonServiceException);
String actual = exception.getErrorMessage().toLowerCase();
assertTrue("Error message doesn't match. Expected : " + expected + ". Actual :" + actual,
actual.contains(expected.toLowerCase()));
}
@And("^I generate and start the webserver with the following parameters:$")
public void generateAndStartWebserver(Map<String, String> parameters) {
navigationRunSteps.goToOperationsTab();
navigationRunSteps.expandGroupInOperationsTab(parameters.get("group"));
generateWebServerRunSteps.generateIndividualWebserver(parameters.get("webserverName"), parameters.get("group"));
generateWebServerRunSteps.checkForSuccessfulGenerationOfAWebserver();
startWebServersOfGroup(parameters.get("webserverName"), parameters.get("group"));
startWebServerRunSteps.checkIfWebServerStateIsStarted(parameters.get("webserverName"), parameters.get("group"));
}
@And("^I generate and start the jvm with the following parameters:$")
public void generateAndStartJvm(Map<String, String> parameters) {
navigationRunSteps.goToOperationsTab();
navigationRunSteps.expandGroupInOperationsTab(parameters.get("group"));
generateJvmRunSteps.generateIndividualJvm(parameters.get("jvmName"), parameters.get("group"));
generateJvmRunSteps.checkForSuccessfulGenerationIndividualJvm();
startJvmOfGroup(parameters.get("jvmName"), parameters.get("group"));
startJvmRunSteps.checkIfJvmStateIsStarted(parameters.get("jvmName"), parameters.get("group"));
}
@And("^I go to the web-app file in resources under individual jvm with the following parameters:$")
public void goToResourceWebappUnderJvm(Map<String, String> parameters) {
navigationRunSteps.goToConfigurationTab();
navigationRunSteps.goToResourceTab();
uploadResourceRunSteps.expandNode(parameters.get("group"));
uploadResourceRunSteps.expandNode("JVMs");
uploadResourceRunSteps.expandNode(parameters.get("jvmName"));
uploadResourceRunSteps.clickNode(parameters.get("app"));
handleResourceRunSteps.selectFile(parameters.get("file"));
}
@And("^I created a group JVM resource with the following parameters:$")
public void createGroupJvmResource(Map<String, String> parameters) throws Throwable {
navigationRunSteps.goToResourceTab();
uploadResourceRunSteps.expandNode(parameters.get("group"));
uploadResourceRunSteps.expandNode("JVMs");
uploadResourceRunSteps.clickNode("JVMs");
uploadResourceRunSteps.clickAddResourceBtn();
uploadResourceRunSteps.setDeployName(parameters.get("deployName"));
uploadResourceRunSteps.setDeployPath(parameters.get("deployPath"));
uploadResourceRunSteps.selectResourceFile(parameters.get("templateName"));
uploadResourceRunSteps.clickUploadResourceDlgOkBtn();
uploadResourceRunSteps.checkForSuccessfulResourceUpload();
}
@And("^I enter attribute in the group file MetaData with the following parameters:$")
public void enterAttributeInGroupMetaData(Map<String, String> parameters) {
navigationRunSteps.goToConfigurationTab();
navigationRunSteps.goToResourceTab();
uploadResourceRunSteps.expandNode(parameters.get("group"));
uploadResourceRunSteps.expandNode(parameters.get("componentType"));
uploadResourceRunSteps.clickNode(parameters.get("componentType"));
handleResourceRunSteps.clickResource(parameters.get("fileName"));
handleResourceRunSteps.clickTab("Meta Data");
handleResourceRunSteps.enterAttribute(parameters.get("attributeKey"), parameters.get("attributeValue"));
handleResourceRunSteps.clickSaveButton("Meta Data");
//click ok to override popup
jwalaUi.clickOkWithSpan();
handleResourceRunSteps.waitForNotification("Saved");
}
@And("^I attempt to deploy the resource \"(.*)\"$")
public void deployFile(String file) {
handleResourceRunSteps.selectFile(file);
handleResourceRunSteps.rightClickFile(file);
handleResourceRunSteps.clickDeploy();
handleResourceRunSteps.confirmDeployPopup();
}
@And("^I attempt to deploy the jvm group resource \"(.*)\"$")
public void deployJvmGroupFile(String file) {
handleResourceRunSteps.selectFile(file);
handleResourceRunSteps.rightClickFile(file);
handleResourceRunSteps.clickDeploy();
handleResourceRunSteps.confirmOverride(file);
}
@And("^I click resource deploy option$")
public void clickDeploy() {
jwalaUi.click(By.xpath("//*[text()='deploy']"));
}
@And("return Product details with name (.*) and category (\\d+)$")
public void theResponseShouldContainTheMessage(String prodName, int categoryId) {
Product product = productResponse.getBody() ;
Assert.assertEquals(prodName, product.getName());
Assert.assertEquals(categoryId, product.getCatId());
}
@And("return Product details with name (.*) and category (\\d+)$")
public void theResponseShouldContainTheMessage(String prodName, int categoryId) {
Product product = productResponse.getBody() ;
Assert.assertEquals(prodName, product.getName());
Assert.assertEquals(categoryId, product.getCatId());
}
@And("^property (.*) contains (.*)$")
public void andPropertyContains(String property, String value) {
if (property!=null && !"".equals(property)) {
response.body(property, hasToString(value));
}
}
@And("^I see the following web app details in the web app table:$")
public void checkForWebApp(final Map<String, String> webAppDetails) {
jwalaUi.waitUntilElementIsVisible(By.xpath("//button[text()='" + webAppDetails.get("name") + "']"));
assertTrue(jwalaUi.isElementExists(By.xpath("//td[text()='" + webAppDetails.get("context") + "']")));
assertTrue(jwalaUi.isElementExists(By.xpath("//td[text()='" + webAppDetails.get("group") + "']")));
}
@And("^User inputs username ([^\"]*)$")
public void user_input_username(String username) {
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("username")));
driver.findElementById("username").sendKeys(username);
}
@And("^User inputs password ([^\"]*)$")
public void user_input_password(String password) {
driver.findElementById("password").sendKeys(password);
}
@And("^User clicks login button$")
public void user_click_login() {
driver.findElementByXPath("//button/i[contains(text(), 'Login')]").click();
}
@And("^User inputs username ([^\"]*)$")
public void input_username(String username) {
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("username")));
driver.findElementById("username").sendKeys(username);
}
@And("^User inputs password ([^\"]*)$")
public void input_password(String password) {
driver.findElementById("password").sendKeys(password);
}
@And("^I confirm to unable to save error popup$")
public void verifyUnableToSave() {
jwalaUi.isElementExists(By.xpath("//*[contains(text(),'Unable to save changes until the meta data errors are fixed: Unexpected token')]"));
jwalaUi.clickOk();
}
@And("^User clicks on Acura category$")
public void click_on_Acura_cateogry() {
driver.findElementByXPath("//*[@name='Acura']").click();
Utils.sleep(2);
}
@And("^User waits for Navigation Bar$")
public void wait_for_Navigation_bar() {
(new WebDriverWait(driver, 60))
.until(ExpectedConditions.elementToBeClickable(By.xpath("//XCUIElementTypeNavigationBar")));
}
@And("^I click the add web server dialog ok button$")
public void clickAddWebServerDialogOkBtn() throws InterruptedException {
jwalaUi.clickOkWithSpan();
}