java - Cucumber examples pulled through literally and not using the values - no such element: Unable to locate element:
问题描述
I have the following cucumber feature file:
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
My Java code:
@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));
}
The test navigates to the correct url (meaning it gets the url from the feature file examples). However I get the following issue no such element: Unable to locate element: {"method":"xpath","selector":"//a[@href='/<mainmenu>']"}
when it tries to access the mainMenu examples.
I have tried examples such as not using the " "
and the \"
I have also rewrote my scenario but I get the same error.
I understand why it cant access <mainmenu>
because there is no element with that name but I don't understand why it does not use the given values.
When I debug the value of <mainmenu>
is <mainmenu>
in IntelliJ
解决方案
我犯了一个非常愚蠢的错误。看看我的数据表Examples
,我忘了用另一个管道“关闭”表|
。
所以它应该是这样的:
Examples:
|url |mainMenu |
|https://www.website.com/ |live |
|https://www.website.com/ |live games |
|https://www.website.com/ |live sports |
推荐阅读
- java - 多线程时线程“主”java.util.ConcurrentModificationException 中的异常
- javascript - 在 Recharts 中按月创建 X 轴
- asp.net - 将 PDF 从 Angular 发送到 .NetCore 服务器?
- scala - Scala 应用在 Heroku 上启动时崩溃,包括基本的 hello world
- javascript - JavaScript if/else 语句输入数据
- machine-learning - 编码逻辑回归时成本函数是否重要
- java - `System.currentTimeMillis()` 在多个进程中是否正确?
- php - 获取分类名称
- python - 3D散点图动画
- 3d - 获取 xC0000005: 调用 vkCreateGraphicsPipelines() 函数时访问冲突读取位置 0xCCCCCCCC 错误