功能、場景和具有Lettuce的功能引擎的Python對象的步驟。
在這里,你會(huì)發(fā)現(xiàn)關(guān)于這些對象的非?!胺爆崱钡募?xì)節(jié)。如果你在這里找不到一個(gè)好的介紹,你可能去閱讀feature的介紹比較好。
為了舉例說明下面的屬性和方法的使用,我們認(rèn)為有一個(gè)功能文件叫做some.feature
# language: en
# just a comment
# another one
Feature: some feature
Here comes
The feature
Description
Scenario: try out something
Given I show lettuce running
Then I should be happy
功能
Feature.name
包含了功能名字的字符串
feature.name == 'some feature'
Feature.scenarios
場景對象列表
場景豎線可以如下使用
feature.scenarios[0].name == 'try out something'
Feature.described_at
一個(gè)功能描述對象,有對功能進(jìn)行了介紹的文件和行。Lettuce使用它輸出這些元數(shù)據(jù)。
屬性described_at可以如下使用
# the line in which the feature started
feature.described_at.line == 5
# the filename path
'some.feature' in feature.described_at.file
# a tuple with the lines that contains the feature description
feature.described_at.description_at == (6, 7, 8)
Feature.max_length
計(jì)算組成該功能的所有行的最大長度的屬性。
主要用于shell輸出,查找哪里打印功能描述。
例如:
feature.max_length == 21
Feature.get_head
以當(dāng)前語言中的第一個(gè)陳述來表示這個(gè)功能,后面是冒號和功能名。
例如:
feature.get_head() == 'Feature: some feature'
但是,如果用巴西葡萄牙語編寫同樣的功能,例如:
# language: pt-br
# apenas um comentário
# e outro
Funcionalidade: alguma funcionalidade
Aqui vem
a descri??o
da funcionalidade
Cenário: ...
...
Feature.get_head()將會(huì)給出
feature.get_head() == 'Funcionalidade: alguma funcionalidade'
totalresult
totalresult.features_ran
整數(shù),執(zhí)行過的全部功能
totalresult.features_passed
整數(shù),執(zhí)行通過的全部功能
totalresult.scenarios_ran
整數(shù),執(zhí)行過的所有場景
totalresult.scenarios_passed
整數(shù),執(zhí)行通過的所有場景
totalresult.steps
整數(shù),執(zhí)行過的步驟數(shù)
totalresult.proposed_definitions
沒有步驟定義的步驟列表
場景
scenario.steps
場景對象列表
場景屬性可以如下使用
scenario.steps[0].sentence == 'try out something'
步驟
Step.sentence
展示步驟字符串
step.sentence == 'Given I show lettuce running'
Step.passed
布爾類型,如果步驟執(zhí)行正確
Step.failed
布爾類型,如果步驟在執(zhí)行中出錯(cuò)
step definition
一個(gè)可用于任何Python函數(shù)的修飾,以一個(gè)正則表達(dá)式字符串作為參數(shù),函數(shù)參照以下步驟。
from lettuce import step
@step('I am (happy|sad)')
def show_lettuce_running_here(step, action):
if action == 'happy':
return # everything is fine!
else:
assert False, 'you should be happy, dude!'