在黄瓜特征文件中传递的参数,在步骤定义脚本中不起作用

问题描述 投票:0回答:1

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

    Feature: List of scenarios.

      Scenario Outline: Add a Baak in Liquidice
        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)
    Can someone please help me on this ?
selenium-webdriver cucumber bdd
1个回答
0
投票

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

功能:方案列表。

  Scenario Outline: Add a Baak in Liquidice
    Given Open "firefox" and enter a URL
© www.soinside.com 2019 - 2024. All rights reserved.