appium .feature 文件中的 'Background' 注释是什么意思?
What does 'Background' annotation in appium .feature file mean?
我是 Appium 的新手,我不知道 Background:
在 Appium 的 .feature
文件中做了什么。任何人都可以向我解释一下吗?
据我了解,放在Background:
下的测试步骤是每次在一个场景结束后执行。
功能文件中的背景部分允许您指定一组步骤
对于文件中的每个场景都是通用的。因此,不必为每个场景一遍又一遍地重复这些步骤,您可以将它们移到背景中
元素。
这样做的好处是:
- 如果您需要更改这些步骤,只需更改它们
一处。
- 这些步骤的重要性逐渐淡出背景,因此当
您正在阅读每个单独的场景,您可以专注于独特之处
并且对这种情况很重要。
例如考虑以下两种情况:
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
我是 Appium 的新手,我不知道 Background:
在 Appium 的 .feature
文件中做了什么。任何人都可以向我解释一下吗?
据我了解,放在Background:
下的测试步骤是每次在一个场景结束后执行。
功能文件中的背景部分允许您指定一组步骤 对于文件中的每个场景都是通用的。因此,不必为每个场景一遍又一遍地重复这些步骤,您可以将它们移到背景中 元素。
这样做的好处是:
- 如果您需要更改这些步骤,只需更改它们 一处。
- 这些步骤的重要性逐渐淡出背景,因此当 您正在阅读每个单独的场景,您可以专注于独特之处 并且对这种情况很重要。
例如考虑以下两种情况:
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