什么'背景' appium .feature文件中的注释是什么意思?

时间:2016-07-14 10:51:05

标签: cucumber appium

我是Appium的新手,我不知道Background:在Appium的.feature文件中做了什么。有人可以向我解释一下吗?

根据我的理解,每次在一个场景结束后执行Background:下的测试步骤。

1 个答案:

答案 0 :(得分:0)

要素文件中的背景部分允许您指定一组步骤 对于文件中的每个方案都是通用的。因此,不必为每个场景反复重复这些步骤,您可以将它们移动到背景中 元件。

这样做的好处是:

  • 如果您需要更改这些步骤,则必须仅更改它们 一个地方。
  • 这些步骤的重要性逐渐消失在背景中,以便何时 您正在阅读每个单独的场景,您可以专注于独特的内容 这个场景很重要。

例如,考虑以下两种情况:

Scenario: Change PIN successfully
  Given I have been issued a new card
  And I insert the card, entering the correct PIN
  When I choose "Change PIN" from the menu
  And I change the PIN to 9876
  Then the system should remember my PIN is now 9876

Scenario: Try to change PIN to the same as before
  Given I have been issued a new card
  And I insert the card, entering the correct PIN
  When I choose "Change PIN" from the menu
  And I try to change the PIN to the original PIN number
  Then I should see a warning message
  And the system should not have changed my PIN

从上述2个场景中,您可以看到前几个步骤在每个场景中重复出现。所以我们可以做的是将它们移到后台,然后它们将在每个场景的开头自动执行。

Background:
  Given I have been issued a new card
  And I insert the card, entering the correct PIN
  And I choose "Change PIN" from the menu

Scenario: Change PIN successfully
  When I change the PIN to 9876
  Then the system should remember my PIN is now 9876

Scenario: Try to change PIN to the same as before
  When I try to change the PIN to the original PIN number
  Then I should see a warning message
  And the system should not have changed my PIN