【问题标题】:Parameters passed in cucumber feature file, not working in step defination script在黄瓜特征文件中传递的参数,在步骤定义脚本中不起作用
【发布时间】:2020-04-03 07:49:09
【问题描述】:

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

    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)

有人可以帮我吗?

【问题讨论】:

    标签: selenium-webdriver cucumber bdd


    【解决方案1】:

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

    功能:场景列表。

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

    【讨论】:

    • 这也行不通,但是如果我想将浏览器名称作为参数发送,那么我可以在相同的情况下发送。
    【解决方案2】:

    如果您在步骤定义中使用 (.*) 正则表达式,则功能文件中不需要双引号。请确保使用 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")
    

    【讨论】:

      猜你喜欢
      • 2020-01-13
      • 2016-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-12
      • 1970-01-01
      • 2014-01-10
      相关资源
      最近更新 更多