将浏览器名称添加到java生成的json结果中

将浏览器名称添加到java生成的json结果中,java,json,selenium,cucumber-jvm,Java,Json,Selenium,Cucumber Jvm,是否有办法将浏览器名称作为附加字段添加到cucumber java使用selenium生成的json结果中。当然。联合命令如下: import cucumber.api.Scenario; public class MyStepdefs { private Scenario scenario; private WebDriver driver; @Before public void before(Scenario scenario) { th

是否有办法将浏览器名称作为附加字段添加到cucumber java使用selenium生成的json结果中。

当然。联合命令如下:

import cucumber.api.Scenario;

public class MyStepdefs {
    private Scenario scenario;
    private WebDriver driver;

    @Before
    public void before(Scenario scenario) {
        this.scenario = scenario;
        driver = new FirefoxDriver();
    }

    @Given("^I have (\\d+) cukes in my belly$")
    public void cukes_in_my_belly(int cukes) {
         Capabilities cap = ((RemoteWebDriver) driver).getCapabilities();
         String browsername = cap.getBrowserName();
         scenario.write("Browser is " + browsername + "\n");
    }
}
你可以看官方的帖子

编辑

json部分由cucumber选项控制

@CucumberOptions(plugin = {"pretty", "json:target2/cucumber.json"}, ...)

当然。联合命令如下:

import cucumber.api.Scenario;

public class MyStepdefs {
    private Scenario scenario;
    private WebDriver driver;

    @Before
    public void before(Scenario scenario) {
        this.scenario = scenario;
        driver = new FirefoxDriver();
    }

    @Given("^I have (\\d+) cukes in my belly$")
    public void cukes_in_my_belly(int cukes) {
         Capabilities cap = ((RemoteWebDriver) driver).getCapabilities();
         String browsername = cap.getBrowserName();
         scenario.write("Browser is " + browsername + "\n");
    }
}
你可以看官方的帖子

编辑

json部分由cucumber选项控制

@CucumberOptions(plugin = {"pretty", "json:target2/cucumber.json"}, ...)

不是康纳要求的确切答案,但很接近。@djangofan怎么会这样?不是康纳要求的确切答案,但很接近。@djangofan怎么会这样?