所以我有一个测试,我填写表格。我想要的是多次运行此测试,每次使用不同的输入值,如不同的名称。我想我可以使用某种单词列表来做到这一点?但我不确定如何去做。
.completePersonalAddressDetails("04/06/2017","NONE","Mr","Ohaye",
"04/05/1985","Tester","British","123 boombastic avenue","G412LQ")
public NewStartPage completePersonalAddressDetails(String startDate, String NINumber,
String title, String Name, String DOB, String LastName,
String nationality, String addressLine, String postcode) {
helper.switchToMainFrame();
startDateInput.sendKeys(startDate);
helper.sleep();
payrollCompanyLookUp.click();
helper.switchToLookUpFrame();
firstPayrollCompany.click();
helper.switchToMainFrame();
payrollCompanySelectButton.click();
niNumberInput.clear();
niNumberInput.sendKeys(NINumber);
Select selectTitle = new Select(titleSelect);
selectTitle.selectByValue(title);
firstNameInput.sendKeys(Name);
maritalStatusInput.click();
helper.switchToLookUpFrame();
helper.sleep();
maritalStatusDivorced.click();
helper.switchToMainFrame();
maritalStatusSelectButton.click();
DOBInput.sendKeys(DOB);
lastNameInput.sendKeys(LastName);
Select selectNationality = new Select(nationalitySelect);
selectNationality.selectByVisibleText(nationality);
genderInput.click();
helper.switchToLookUpFrame();
helper.sleep();
genderMale.click();
helper.switchToMainFrame();
genderSelect.click();
helper.sleep();
addressLineInput.sendKeys(addressLine);
postcodeInput.sendKeys(postcode);
driver.switchTo().defaultContent();
return PageFactory.initElements(driver, NewStartPage.class);
}
答案 0 :(得分:0)
您可以创建一种生成随机文本的方法。见下面的
public String generateRandomName(int length) {
char[] chars =abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
.toCharArray();
StringBuilder sb = new StringBuilder();
Random random = new Random();
for (int i = 0; i < length; i++) {
char c = chars[random.nextInt(chars.length)];
sb.append(c);
}
String randomString = sb.toString();
return randomString;
}
然后,当您想要填写表格时,您可以执行以下操作:
String firstName = ClassName.generateRandomName(9); // 9 Characters long
driver.findElement(By.xpath("Your xpath")).sendKeys(firstName);
您可以在任何想要调用随机文本字符串的位置调用该方法。希望能帮助到你。