У меня есть следующий файл функций огурца:
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-адрес из примеров файлов функций). Однако я получаю следующую проблему no such element: Unable to locate element: {"method":"xpath","selector":"//a[@href='/<mainmenu>']"}
, когда он пытается получить доступ к примерам mainMenu.
Я пробовал такие примеры, как не использовать " "
и \"
. Я также переписал свой сценарий, но получаю ту же ошибку.
Я понимаю, почему он не может получить доступ к <mainmenu>
, потому что нет элемента с таким именем, но я не понимаю, почему он не использует данные значения.
Когда я отлаживаю значение <mainmenu>
равно <mainmenu>
в IntelliJ
Я совершил очень глупую ошибку.
Посмотрите таблицу данных у меня в Examples
, я забыл "закрыть" таблицу другой трубой |
.
Итак, это должно выглядеть так:
Examples:
|url |mainMenu |
|https://www.website.com/ |live |
|https://www.website.com/ |live games |
|https://www.website.com/ |live sports |