我正在编写一个自动化脚本,并使用Cucumber,Selenium WebDriver跟踪BDD框架。我不知道如何验证网页显示正确的代码,以及是否有多行代码按排序顺序显示。 测试用例:
Given that the Account Holder page is displayed,
When the user clicks on any member record
Then the latest information will be retrieved and displayed on the 'Record Page' page under the 'Financial' section:
Field Name - Financial Code - Indicates the 3-Character code that represents the type.
Valid values are: CBP, EBP, FBP, MNP, NNP, ONP.
我必须验证帐户持有人是否具有超出所提及的有效值的正确代码,以及是否有按行排序显示的多行。
public void verifyAccountHolderCode(WebDriver driver, By xpath,String Value) {
String ContrctCode = driver.findElement(xpath).getText();
if (ContrctCode.equals("CBP")) {
Assert.assertTrue(ContrctCode .contains(Value)); //Value represent the correct code which will be provided in Step Definition
System.out.println("Correct code displayed");
} else if (ContrctCode .contains("EBP")) {
Assert.assertTrue(ContrctCode .contains(Value));
System.out.println("Correct code displayed");
} else if (ContrctCode.contains("FBP")) {
Assert.assertTrue(ContrctCode.contains(Value));
System.out.println("Correct code displayed");
} else if (ContrctCode.contains("MNP")) {
Assert.assertTrue(ContrctCode.contains(Value));
System.out.println("Correct code displayed");
} else if (ContrctCode.equals("NNP")) {
Assert.assertTrue(ContrctCode.contains(Value));
System.out.println("Correct code displayed");
} else if (ContrctCode.contains("ONP")) {
Assert.assertTrue(ContrctCode.contains(Value));
System.out.println("Correct code displayed");
} else if (ContrctCode.equals("- -")) {
Assert.assertTrue(ContrctCode.contains(Value));
System.out.println("No code displayed");
}
}
@Then("^Account Infomation displayed under the Financial Tab$")
public void AccountInfo() {
AccountHolderPage AccountCode = AccountHolderPage();
driver.findElement(By.xpath(AccountCode.Xpath_1)).click();
AccountCode.verifyAccountHolderCode(driver,
AccountCode.(Xpath for valid value), "EBP");