Reputation: 229
I am trying to run parallel tests in 2 browsers using, Testng and cucumber.
Getting the below exception ,
cucumber.runtime.CucumberException: When a hook declares an argument it must be of type cucumber.api.Scenario. public void com.sample.data_republic.sample_ebay.EbayTest.loadBrowser(java.lang.String) at cucumber.runtime.java.JavaHookDefinition.execute(JavaHookDefinition.java:52) at cucumber.runtime.Runtime.runHookIfTagsMatch(Runtime.java:224)
Code sample given below.
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"));
}
Upvotes: 0
Views: 496
Reputation: 9058
The Before hook
is a cucumber method, not a testNg method, which is injected only with the Scenario
object. So cannot use the @Parameters
annotation on it to pass parameter values. You need to use before hook like below.
@Before
public void beforeScenario(Scenario scenario) {
or without the scenario object
@Before
public void beforeScenario() {
Either you can store the browser value in a properties file and access it in before hook. Or instantiate the driver in the BeforeClass or BeforeMethod of testNg in the runner class where you can use the parameters annotation.
@BeforeClass
@Parameters("browser")
public void loadBrowser(String browser) {
Upvotes: 1