【发布时间】:2020-06-10 08:57:16
【问题描述】:
我看到当 BDD 中描述的表有标题时,可以从 Behave 访问 context.table 中的数据。例如:
Scenario: Add new Expense
Given the user fill out the required fields
| item | name | amount |
| Wine | Julie | 30.00 |
要访问此代码,只需:
for row in context.table:
context.page.fill_item(row['item'])
context.page.fill_name(row['name'])
context.page.fill_amount(row['amount'])
这很好用,而且非常干净,但是,当我有大量输入数据行时,我必须重构代码。例如:
Given I am on registration page
When I fill "test@test.com" for email address
And I fill "test" for password
And I fill "Didier" for first name
And I fill "Dubois" for last name
And I fill "946132795" for phone number
And I fill "456456456" for mobile phon
And I fill "Company name" for company name
And I fill "Avenue Victor Hugo 1" for address
And I fill "97123" for postal code
And I fill "Lyon" for city
And I select "France" country
...
15 more lines for filling the form
如何在行为中使用下表:
|first name | didier |
|last name | Dubois |
|phone| 4564564564 |
So on ...
我的步骤定义如何?
【问题讨论】:
标签: python bdd python-behave