Java 无法在Cucumber&;中运行并行测试;Testng

Java 无法在Cucumber&;中运行并行测试;Testng,java,cucumber,testng,parallel-testing,Java,Cucumber,Testng,Parallel Testing,我正在尝试使用Testng和cucumber在两个浏览器中运行并行测试 获取以下异常 cucumber.runtime.CucumberException:钩子声明参数时 它必须是cumber.api.Scenario类型。公共空间 com.sample.data\u republic.sample\u ebay.EbayTest.loadBrowser(java.lang.String) 在 cucumber.runtime.java.JavaHookDefinition.execute(Ja

我正在尝试使用Testng和cucumber在两个浏览器中运行并行测试

获取以下异常

cucumber.runtime.CucumberException:钩子声明参数时 它必须是cumber.api.Scenario类型。公共空间 com.sample.data\u republic.sample\u ebay.EbayTest.loadBrowser(java.lang.String) 在 cucumber.runtime.java.JavaHookDefinition.execute(JavaHookDefinition.java:52) atcumber.runtime.runtime.runHookIfTagsMatch(runtime.java:224)

下面给出了代码示例

import cucumber.api.java.After;
import cucumber.api.java.Before;

import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

import org.testng.annotations.Parameters;

public class EbayTest extends EbayPageObjects {

    public WebDriver driver;
    Properties propertyObj;

    @Before
    @Parameters("browser")
    public void loadBrowser(String browser) {
        // If the browser is Firefox, then do this
        if (browser.equalsIgnoreCase("firefox")) {
            System.setProperty("webdriver.gecko.driver", "src/test/resources/drivers/geckodriver");
            driver = new FirefoxDriver();
        } else if (browser.equalsIgnoreCase("chrome")) {
            System.setProperty("webdriver.chrome.driver", "src/test/resources/drivers/chromedriver");
            driver = new ChromeDriver();
        }

        propertyObj = readPropertyFile();
        driver.get(propertyObj.getProperty("url"));
    }

hook之前的
是cucumber方法,而不是testNg方法,它只注入
场景
对象。因此,无法在其上使用
@Parameters
注释来传递参数值。如下图所示,您需要在挂钩前使用

@Before
public void beforeScenario(Scenario scenario) {
或者没有场景对象

 @Before
    public void beforeScenario() {
您可以将浏览器值存储在属性文件中,并在挂钩之前访问它。或者在runner类中的testNg的BeforeClass或BeforeMethod中实例化驱动程序,您可以在其中使用参数注释

@BeforeClass
@Parameters("browser")
public void loadBrowser(String browser) {