Selenium webdriver 参数在cucumber功能文件中传递,在步骤定义脚本中不起作用

Selenium webdriver 参数在cucumber功能文件中传递,在步骤定义脚本中不起作用,selenium-webdriver,cucumber,bdd,Selenium Webdriver,Cucumber,Bdd,查询:参数在cucumber特征文件中传递,在步骤定义脚本中不起作用。我试图从cucumber传递浏览器名称,脚本应该按照输入运行。 下面是预期工作的功能文件和步骤定义 Feature: List of scenarios. Scenario Outline: Add a Bank in application Given Open "browser" and enter a URL When Login to application and

查询:参数在cucumber特征文件中传递,在步骤定义脚本中不起作用。我试图从cucumber传递浏览器名称,脚本应该按照输入运行。 下面是预期工作的功能文件和步骤定义

    Feature: List of scenarios.

      Scenario Outline: Add a Bank in application
        Given Open "browser" and enter a URL
        When Login to application and navigate to bank master
        Then Click on create bank and enter "Code" and "Short name" and "Description" save details
        Then Logout and Approve the Bank from checker
        Then Verify the bank is added successfully
        Then Logout the application and close the browser

    Examples: 
          | browser | Code  | Short name | Description     |
          | chrome  | Bank2 | Bank Two   | Bank Two Desc   |
          | Firefox | Bank3 | Bank Three | Bank Three Desc |

    **Step Defination is:**

    @Given("^Open (.*). and enter a URL$")
        public void open_and_enter_a_URL(String browser) throws Throwable {
            // 'firefox'
            if (browser.equalsIgnoreCase("firefox")) {
                System.setProperty("webdriver.firefox.marionette", ProjectPath+"/Drivers/geckodriver.exe");
                driver = new FirefoxDriver();
            }
            // 'chrome'
            else if (browser.equalsIgnoreCase("chrome")) {
                System.setProperty("webdriver.chrome.driver", ProjectPath+"/Drivers/chromedriver.exe"); 
                driver = new ChromeDriver();
            } // 'Edge'
            else if (browser.equalsIgnoreCase("IE")) { // set path to Edge.exe
                System.setProperty("webdriver.edge.driver", ProjectPath+"/Drivers/MicrosoftWebDriver.exe");
            } else {
                // If no browser passed throw exception
                throw new Exception(**"Browser is not correct");**
                 //Giving this error for incorrect browser as parameter is not identified in step defination 
            }
            driver.manage().window().maximize();
            driver.get(URL);
            driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        }

 **Getting error as:**
    java.lang.Exception: Browser is not correct
        at.stepDefination.addbankSteps.open_and_enter_a_URL(addbankSteps.java:42)
        at ✽.Given Open chrome and enter a URL(Features/TC_001.feature:4)

有人能帮我吗?

在您的功能文件中,您需要提供浏览器名称,如chrome、firefox、IE,而不是文本“browser”

功能:场景列表

  Scenario Outline: Add a Baak in Liquidice
    Given Open firefox and enter a URL

在您的功能文件中,您需要提供浏览器名称,如chrome、firefox、IE,而不是文本“browser”

功能:场景列表

  Scenario Outline: Add a Baak in Liquidice
    Given Open firefox and enter a URL

如果在步骤定义中使用(.*)正则表达式,则要素文件中不需要双引号。请确保使用cucumber 4.x.x或更高版本,并更新插件和IDE

功能文件:

Feature: List of scenarios.

  Scenario Outline: Add a Bank in application
    Given Open browser and enter a URL
@Given("Open (.*) and enter a URL")
步骤定义:

Feature: List of scenarios.

  Scenario Outline: Add a Bank in application
    Given Open browser and enter a URL
@Given("Open (.*) and enter a URL")

如果在步骤定义中使用(.*)正则表达式,则要素文件中不需要双引号。请确保使用cucumber 4.x.x或更高版本,并更新插件和IDE

功能文件:

Feature: List of scenarios.

  Scenario Outline: Add a Bank in application
    Given Open browser and enter a URL
@Given("Open (.*) and enter a URL")
步骤定义:

Feature: List of scenarios.

  Scenario Outline: Add a Bank in application
    Given Open browser and enter a URL
@Given("Open (.*) and enter a URL")

这也不起作用,但如果我想以prameters的形式发送浏览器名称,那么我可以在相同的场景中发送。这也不起作用,但如果我想以prameters的形式发送浏览器名称,那么我可以在相同的场景中发送。