cucumber示例按字面理解,不使用值-没有这样的元素:找不到元素:

cvxl0en2  于 2021-06-29  发布在  Java
关注(0)|答案(1)|浏览(275)

我有以下特性文件:

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> 在intellij中

pkbketx9

pkbketx91#

我犯了一个非常愚蠢的错误。请看我电脑里的数据表 Examples ,我忘了用另一根管子“关”table | .
所以应该是这样的:

Examples:
|url                       |mainMenu    |
|https://www.website.com/  |live        |
|https://www.website.com/  |live games  |
|https://www.website.com/  |live sports |

相关问题