【问题标题】:Using element locators in Cucumber tables在 Cucumber 表中使用元素定位器
【发布时间】:2018-06-19 09:38:46
【问题描述】:

我有一个登录测试,我使用黄瓜中的表运行正面和负面的场景。

场景大纲:登录

Given User navigates to Field
And User enters a "<Username>" username
And User enters a "<Password>" password
When User clicks on the login button
Then User should see the "<message>"

Examples:
  | Username | Password  | message |
  | name  | pwd | Logout |
  | name1 | pwd1 | Your login name or password is incorrect.|

我现在使用“消息”断言它。

我的问题是:是否可以使用 xpath 或其他元素定位器进行断言?这是推荐的方式还是我应该为每个案例创建不同的场景?

【问题讨论】:

    标签: java selenium cucumber gherkin


    【解决方案1】:

    是否可以使用 xpath 或其他元素定位器进行断言?

    是的,这是可能的。

    你可以这样断言:

    String successMsg = driver.findElement(By.xpath("some xpath")).getText();
    

    并且您已经期待了味精(意味着您已经知道应该期待什么)。

    String expected = "your expected msg";  
    

    现在您要做的就是比较这两个字符串。

    testng 中类似:

    Assert.assertEquals(successMsg, expected) 可以完成这项工作。

    参考:

    Cucumber assertion

    【讨论】:

      【解决方案2】:

      不要在一种情况下组合有效或无效的情况。在几乎所有情况下,都会有不同的页面流。您将需要使用 if 条件来处理它以考虑到这一点。将它们分开并避免复杂性。

      将它们分开的另一个好处是,如果您只想运行有效案例。只需在该场景上添加标签并在跑步者中提及即可。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-06-04
        • 2019-06-26
        • 2021-02-28
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多