Selenium 如何在报告中显示动态值

Selenium 如何在报告中显示动态值,selenium,cucumber,extent,Selenium,Cucumber,Extent,我想在报告中显示动态值 例: 功能文件 给定用户ID,请按以下方式输入用户ID: 并将当前时间输入为 示例: @And("^enter the current time as (.*)") public void currenttime(String arg1) { SimpleDateFormat formatter = new SimpleDateFormat("HH:MM"); Date date = new Date(); System.out.println

我想在报告中显示动态值

例:

功能文件

给定用户ID,请按以下方式输入用户ID:

并将当前时间输入为

示例:

@And("^enter the current time as (.*)")
public void currenttime(String arg1) {
    SimpleDateFormat formatter = new SimpleDateFormat("HH:MM");  
    Date date = new Date();
    System.out.println(formatter.format(date)); 
    if (arg1 == "today") {
        driver.findElement(By.id("period")).sendKeys(formatter.format(date));
    }
}
|用户ID |当前时间|

|10002 |今天|

定义文件:

@And("^enter the current time as (.*)")
public void currenttime(String arg1) {
    SimpleDateFormat formatter = new SimpleDateFormat("HH:MM");  
    Date date = new Date();
    System.out.println(formatter.format(date)); 
    if (arg1 == "today") {
        driver.findElement(By.id("period")).sendKeys(formatter.format(date));
    }
}
在黄瓜范围报告中:只显示“今天”而不是动态值(current time=“07:18”)


请告诉我。

您是指“范围”报告吗?如果是这样,你应该给它贴上标签。此外,您根本不显示代码,只显示功能文件。“today”是作为一个参数传递的,很可能您的代码专门将其转换为当前日期,但是Gherkin只会将“today”传递到步骤,而不是为您进行转换,因此报告同样不会转换要素线。我已经更新了定义文件,这里恐怕没有快捷方式,因为您几乎可以肯定地使用扩展报告的功能来自动与Cucumber交互。另一种方法是按照文档中BDD部分的示例编写数据块报告,而不使用该自动选项,并手动传递步骤(在确定当前时间之后)。这需要您编写更多的代码,但它可以工作。这就是我用JBehave做iit的方式,因为没有自动接口,只有Cucumber。