Cucumber 示例从字面上提取而不使用值 - 没有这样的元素:无法定位元素:
Cucumber examples pulled through literally and not using the values - no such element: Unable to locate element:
我有以下黄瓜功能文件:
Feature: When a user is not logged in they should be able to view and use the main menu navigation bar
Scenario Outline: Navigate to the company site as a guest and interact with the main navigation bar
Given I access "<url>" main landing page
When I select the "<mainMenu>" tab
Then the url should change
Examples:
|url |mainMenu
|https://www.website.com/ |live
|https://www.website.com/ |live games
|https://www.website.com/ |live sports
我的Java代码:
@Given("^I access \"([^\"]*)\" main landing page$")
public void i_access_something_main_landing_page(String url) throws Throwable , InterruptedException {
getDriver().get(url);
}
@When("^I select the \"([^\"]*)\" tab$")
public void i_select_the_something_tab(String mainmenu) throws Throwable {
menuOptionWithoutSpace = mainmenu.toLowerCase().replaceAll("\s","");
driver.findElement(By.xpath("//a[@href='/"+ menuOptionWithoutSpace+ "']")).click();
System.out.println("menuOptionWithoutSpace: " + menuOptionWithoutSpace);
}
@Then("^the url should change$")
public void the_url_should_change() throws Throwable {
String mainMenuUrl = driver.getCurrentUrl();
Assert.assertTrue(mainMenuUrl.contains(menuOptionWithoutSpace));
}
测试导航到正确的 url(意味着它从功能文件示例中获取 url)。但是,当它尝试访问 mainMenu 示例时,我遇到了以下问题 no such element: Unable to locate element: {"method":"xpath","selector":"//a[@href='/<mainmenu>']"}
。
我试过一些例子,比如不使用 " "
和 \"
我也重写了我的场景,但我得到了同样的错误。
我明白为什么它无法访问 <mainmenu>
因为没有具有该名称的元素但我不明白为什么它不使用给定的值。
当我调试时 <mainmenu>
的值在 IntelliJ
中是 <mainmenu>
我犯了一个非常愚蠢的错误。
看看我的Examples
里的数据table,我忘了用另一个管道|
.
“关闭”table
所以它应该是这样的:
Examples:
|url |mainMenu |
|https://www.website.com/ |live |
|https://www.website.com/ |live games |
|https://www.website.com/ |live sports |
我有以下黄瓜功能文件:
Feature: When a user is not logged in they should be able to view and use the main menu navigation bar
Scenario Outline: Navigate to the company site as a guest and interact with the main navigation bar
Given I access "<url>" main landing page
When I select the "<mainMenu>" tab
Then the url should change
Examples:
|url |mainMenu
|https://www.website.com/ |live
|https://www.website.com/ |live games
|https://www.website.com/ |live sports
我的Java代码:
@Given("^I access \"([^\"]*)\" main landing page$")
public void i_access_something_main_landing_page(String url) throws Throwable , InterruptedException {
getDriver().get(url);
}
@When("^I select the \"([^\"]*)\" tab$")
public void i_select_the_something_tab(String mainmenu) throws Throwable {
menuOptionWithoutSpace = mainmenu.toLowerCase().replaceAll("\s","");
driver.findElement(By.xpath("//a[@href='/"+ menuOptionWithoutSpace+ "']")).click();
System.out.println("menuOptionWithoutSpace: " + menuOptionWithoutSpace);
}
@Then("^the url should change$")
public void the_url_should_change() throws Throwable {
String mainMenuUrl = driver.getCurrentUrl();
Assert.assertTrue(mainMenuUrl.contains(menuOptionWithoutSpace));
}
测试导航到正确的 url(意味着它从功能文件示例中获取 url)。但是,当它尝试访问 mainMenu 示例时,我遇到了以下问题 no such element: Unable to locate element: {"method":"xpath","selector":"//a[@href='/<mainmenu>']"}
。
我试过一些例子,比如不使用 " "
和 \"
我也重写了我的场景,但我得到了同样的错误。
我明白为什么它无法访问 <mainmenu>
因为没有具有该名称的元素但我不明白为什么它不使用给定的值。
当我调试时 <mainmenu>
的值在 IntelliJ
<mainmenu>
我犯了一个非常愚蠢的错误。
看看我的Examples
里的数据table,我忘了用另一个管道|
.
所以它应该是这样的:
Examples:
|url |mainMenu |
|https://www.website.com/ |live |
|https://www.website.com/ |live games |
|https://www.website.com/ |live sports |