在Behave中,可以使用Background关键字定义在每个Scenario之前执行的步骤。如果需要多个示例运行此Background步骤,可以使用Examples关键字来定义多个示例,每个示例都有自己的参数。以下是一个示例:
Feature: User login
Scenario Outline: User logs in
Given the user is on the login page
When they enter "
Examples: | username | password | | john | pass123 | | amy | pass456 |
Background: Given the user is on the website
在上面的示例中,Background步骤中的Given子步骤将在每个测试运行之前执行。由于该示例定义了两个示例,因此该步骤将在每个示例中执行两次。