Прежде всего, мы поймем, что Cucumber был создан как способ преодоления неоднозначных требований и недоразумений, нацеленный как на нетехнических, так и на технических членов команды проекта, но если кто-то думает, что Cucumber является инструментом тестирования, то мы ошибаемся.
Параметризация данных должна передаваться из файла признаков в методы реализации Step.Таким образом, Cucumber не предоставляет такую возможность параметризации напрямую за один раз.
Единственное, что можно сделать для реализации вашего сценария, - это использовать теговые зацепки.
Feature File :- 3 Scenarios
@Chrome
Scenario: This is First Scenario running on chrome browser
Given this is the first step
When this is the second step
Then this is the third step
@Firefox
Scenario: This is Second Scenario running on firefox browser
Given this is the first step
When this is the second step
Then this is the third step
@IE
Scenario: This is Third Scenario running on ie browser
Given this is the first step
When this is the second step
Then this is the third step
@Before("@Chrome")
public void beforeFirst(){
Log.startLog("Start of Test cases ");
TPBaseSteps.openBrowser("Chrome");
System.out.println("This will run only before the chrome Scenario");
}
@Before("@Firefox")
public void beforeSecond(){
Log.startLog("Start of Test cases ");
TPBaseSteps.openBrowser("firefox");
System.out.println("This will run only before the firefox Scenario");
}
@Before("@IE")
public void beforeThird(){
System.out.println("This will run only before the ie Scenario");
}
TPBaseSteps class :
public static WebDriver openBrowser(String browserName) throws Exception {
log.info("Chosen browser is " + browserName);
if (!grid) {
switch (browserName.toLowerCase()) {
case "chrome":
log.info("Launching Browse as : " + browserName);
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();
driver.manage().deleteAllCookies();
case "firefox":
log.info("Launching Browse as : " + browserName);
WebDriverManager.firefoxdriver().setup();
driver = new FirefoxDriver();
driver.manage().deleteAllCookies();
break;
Или Pass Chrome|FF |IE как параметр в Scenario / Scenario Outline и получить значение параметра в шаге реализации метода.Но в этом случае открытый браузер не должен вызываться в хуке, но это не рекомендуется, как я понимаю.
Надеюсь, это помогло вам.