2

我的应用程序中有四个非常相似的部分,并且我尝试使用场景大纲将足够相似的测试组合在一起以方便维护,并将它们所在的部分(页面)作为参数提供。但是,这些测试单独编写时在其数据表下包含不同数量的项目(但仍执行相同的断言),所以我想知道是否可以为每个示例部分提供不同的数据表?

就像是:

Scenario Outline: Verify that the user is able to see the details recorded on the note 
And I navigate to the "<page>" screen
Then the following items are displayed for their respective fields

@page1
Examples:
Then the following items are displayed for their respective fields
  | field   | text       |
  | title   | My title   |
  | history | My history |

@page2
Then the following items are displayed for their respective fields
  | field   | text       |
  | comment | My comment |
  | details | My details |
  | status  | My status  |

注意我省略了 page 参数,因为不确定它应该去哪里,好像做下面这样的事情意味着它们将在每个示例中运行多次

@page1
Examples:
Then the following items are displayed for their respective fields
  | page  | field   | text       |
  | page1 | title   | My title   |
  | page1 | history | My history |

我也不能有类似的东西:

Scenario Outline: Verify that the user is able to see the details recorded on the note 
Then the following items are displayed for their respective fields

@page1
Examples:
Then the following items are displayed for their respective fields
  | field   | text  | item1 | item2 |

因为这些数量会发生变化,所以我可以在一个页面上测试三个项目,但另一个页面上有两个项目,另一个可能有四个项目。

我希望我对我想要实现的目标足够清楚?

非常感谢。

4

1 回答 1

2

您编写的场景非常像描述每个步骤的测试脚本。这不适用于 Gherkin。它不是一种编程语言,尝试用它编程很困难。尝试写下应用程序的行为。

Scenario: Details of the note can be seen on page1 and page2
  Given Claire has created a note
   | property | value    | 
   | title    | My title |
   | ect ....
  When she views the notes details
  Then on "Notes Overview" she can see:
   | field   | text       |
   | title   | My title   |
   | history | My history |
  And on "Note Details" she can see:
   | field   | text       |
   | comment | My comment |
   | details | My details |
   | status  | My status  |

在该Given步骤中,您创建一个名为 Claire 的用户,打开应用程序并创建便笺。在When步骤中,您导航到正确的页面,并在Then步骤中检查正确的内容是否在正确的字段中可见。

于 2020-03-14T11:50:38.523 回答