这可能是一个完全愚蠢的问题,但是在 Java 或 Selenium 中是否有可能强制测试人员为方法参数使用特定的字符串或值?
我正在编写一个 Selenium 框架,测试人员将用它来编写测试。他们看不到 Selenium 代码。
我在框架中有一个名为 setCustomerType
的方法,它从 GUI 中的 4 个有效值中选择一个单选按钮:Phone、Store、Online、Home
。我希望测试人员在测试中不要选择将这些作为字符串参数输入,而是以某种方式从一组预定义的值中进行选择。这是它目前的样子:
SetCustomerDetails.java
public void setCustomerType(String salesType){
WebElement salesTypeOption = driver.findElement(By.cssSelector("input[value=" + salesType + "][name='salesType']"));
fixedTypeOptions.click();
}
SetCustomerTypeTest.java
@Test
public void setCustomerType() {
SetCustomerDetails customerDetails = new SetCustomerDetails();
customerDetails.setCustomerType("Online");
}
最佳答案
使用枚举。这可能看起来像这样:
public enum CustomerType {
Phone("Phone"), Store("Store"), Online("Online"), Home("Home");
private String id;
public CustomerType(String id) {
this.id = id;
}
public String getId() {
return id;
}
}
那么你的 setter 可能看起来像这样:
public void setCustomerType(CustomerType salesType){
WebElement salesTypeOption = driver.findElement(By.cssSelector("input[value=" + salesType.getId() + "][name='salesType']"));
fixedTypeOptions.click();
}
关于java - Selenium:强制测试人员在参数的特定值之间进行选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31105474/