【问题标题】:How can we use data-table across steps?我们如何跨步骤使用数据表?
【发布时间】:2021-07-17 13:32:33
【问题描述】:

我们在主页上有一些类别图块,通过这些图块过滤产品,例如:- 图块 1 属于衣服,单击以下页面应显示衣服,图块 2 属于鞋类,单击以下页面应该显示鞋子等等。

目标是点击tile1,验证文字和产品,点击tile 2验证文字和产品,以此类推。

我想用一个数据表来测试这个场景

这里是特征文件内容:-

Scenario Outline: Filtering the products on the home page
    Given the user is on the homepage
    When the user selects the <category> tile for filtering the products
      | category              |
      | cat 1                 |
      | cat 2                 |
      | cat 3                 |
      | cat 4                 |
   Then only the relevant products should be displayed to the user

问题是,我想在同一步骤中单击并验证,但使用上述设置,我将无法执行此操作。关于如何做到这一点的任何建议/意见?

详细信息:- 当我单击磁贴时,新页面将加载左侧的磁贴文本和相关产品,这两个操作依次发生,因此我想在同一步骤中执行此操作,但看起来不正确在给定的时间和然后的上下文中

【问题讨论】:

    标签: python selenium selenium-webdriver ui-automation python-behave


    【解决方案1】:

    如果要验证每个测试日期,category 表应该在Examples

    Scenario Outline: Filtering the products on the home page
        Given the user is on the homepage
        When the user selects the <category> tile for filtering the products
        Then only the relevant products should be displayed to the user
    
    Examples:
          | category              |
          | cat 1                 |
          | cat 2                 |
          | cat 3                 |
          | cat 4                 |
    

    【讨论】:

    • 如果是示例,它将多次登录。我想通过一次登录来执行此操作。
    • 将登录实现放在environment.py 中的before 挂钩中。无论如何,登录部分可能会成为其他场景/功能的先决条件
    • 有些功能文件不需要像注册场景那样登录,因此我将登录实现保留在各自的功能文件中。在某些情况下,我使用后台登录。
    • 也许把登录放在需要它的功能文件的背景中,而不是放在前面的钩子中
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-25
    • 2023-03-09
    • 1970-01-01
    • 1970-01-01
    • 2019-06-26
    • 2013-02-19
    相关资源
    最近更新 更多