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

标签 java selenium

这可能是一个完全愚蠢的问题,但是在 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/

相关文章:

java - rclick注册表运行java程序

selenium - 在 selenium 自动结束 2 结束测试期间关闭浏览器

python - 从 PHP 脚本在 Python 中调用 Webdriver 时,Firefox 无法打开

java - 在Android上使用JDom2编写XML文件

java - 从 JTextArea 获取文本的单个 MouseListener 事件

java - Wildfly 8.1 ClassNotFound org.apache.http.conn.ClientConnectionManager

python - 使用 Python 和 Selenium 向 Facebook 中的 friend 发送消息

java - 让后台服务始终运行并且不会自杀或系统破坏它

java - 如果我不使用selenium服务器独立文件,是否需要selenium服务器使用selenium客户端创建selenium自动化?

Selenium Webdriver 拖放不适用于 google.com