【发布时间】: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