我正在创建一个 Spring 框架来自动化 Google Calculator 我有一个功能文件,其中包含如下定义的一些值
Feature: Google Calculator
Calculator should calculate correct calculations
Scenario Outline: Add numbers
Given I am on google calculator page
When I add number "<number1>" to number "<number2>"
Then I should get an answer of "<answer>"
Examples:
| number1 | number2 | answer |
| 1 | 2 | 3 |
| 4 | 5 | 9 |
我正在尝试使用 Given, When , Then 创建一个测试,该功能文件中的任何数字都可以在计算器中使用我的步骤如下:
@Scope("test")
@ContextConfiguration("classpath:spring-context/test-context.xml")
public class GivenSteps {
@Autowired
private WebDriver webDriver;
@Given("^I am on google calculator page$")
public void iAmOnGoogleCalculatorPage() throws Throwable {
webDriver.get("https://www.google.ie/search?q=calculator");
}
@When("^I add number \"([^\"]*)\" to number \"([^\"]*)\"$")
public void i_add_number_to_number(Integer number1, Integer number2) throws Throwable {
WebElement googleTextBox = webDriver.findElement(By.id("cwtltblr"));
googleTextBox.sendKeys(Keys.ENTER);
throw new PendingException();
}
@Then("^I should get the correct answer again$")
public void thecorrectanswertest2() throws Throwable{
WebElement calculatorTextBox = webDriver.findElement(By.id("cwtltblr"));
String result = calculatorTextBox.getText();
}}
我的问题是如何编码可以选择数字并从功能表中验证答案的部分?