Java Selenium:强制测试人员在参数的特定值之间进行选择

Java Selenium:强制测试人员在参数的特定值之间进行选择,java,selenium,Java,Selenium,这可能是一个完全愚蠢的问题,但在Java或Selenium中,是否有可能强制测试人员对方法参数使用特定的字符串或值 我正在编写一个测试人员将用来编写测试的Selenium框架。他们没有看到Selenium代码 我在框架中有一个名为setCustomerType的方法,它从GUI中的4个有效值中选择一个单选按钮:Phone、Store、Online、Home。我希望测试人员在他们的测试中不要选择将这些作为字符串参数输入,而是以某种方式从预定义的一组值中进行选择。这就是它目前的样子: SetCust

这可能是一个完全愚蠢的问题,但在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;
    }
}
public void setCustomerType(CustomerType salesType){
    WebElement salesTypeOption = driver.findElement(By.cssSelector("input[value=" + salesType.getId() + "][name='salesType']"));
    fixedTypeOptions.click();
}
然后您的setter可以如下所示:

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;
    }
}
public void setCustomerType(CustomerType salesType){
    WebElement salesTypeOption = driver.findElement(By.cssSelector("input[value=" + salesType.getId() + "][name='salesType']"));
    fixedTypeOptions.click();
}