Lettuce:功能、場景和步驟參考

功能、場景和具有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!'

上一篇:Lettuce: Command Line
下一篇:Lettuce: Terrian

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 179,189評論 25 708
  • 地形是一個(gè)Lettuce“雙關(guān)語”,是它的“生活場所”,其安裝和拆卸,基本上嵌入在你的Lettuce測試。 ter...
    Ailsa的簡書閱讀 817評論 0 0
  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,653評論 19 139
  • 基本概念 behave要被執(zhí)行,需要運(yùn)行在滿足下面兩種情況的目錄下 有feature files。這個(gè)featur...
    做測試的DanteYu閱讀 16,461評論 0 7
  • 國家電網(wǎng)公司企業(yè)標(biāo)準(zhǔn)(Q/GDW)- 面向?qū)ο蟮挠秒娦畔?shù)據(jù)交換協(xié)議 - 報(bào)批稿:20170802 前言: 排版 ...
    庭說閱讀 12,448評論 6 13

友情鏈接更多精彩內(nèi)容