跳到内容

从父故事继承的子故事可以有

  • 以下步骤
  • 替换步骤
  • steps: (如果父故事本身没有步骤)

代码示例

example.story

Login:
  given:
    url: /loginurl
    browser: firefox
  steps:
  - Fill form:
      username: hello
      password: password
  - Click: login

Visit inbox:
  about: uses parent login and following steps.
  based on: login
  following steps:
  - Click: inbox

Login as hiya and visit inbox:
  about: uses parent properties but replaces its own steps.
  based on: login
  replacement steps:
  - Fill form:
      username: hiya
      password: password
  - Click: login
  - Click: inbox

Login as hiya and visit different pages:
  about: login as hiya and visit inbox
  based on: Login as hiya and visit inbox
  variations:
    Dashboard:
      replacement steps:
      - Fill form:
          username: hiya
          password: password
      - Click: login
      - Click: dashboard
engine.py

from hitchstory import BaseEngine, GivenDefinition, GivenProperty
from strictyaml import Map, Int, Str, MapPattern, Optional


class Engine(BaseEngine):
    given_definition = GivenDefinition(
        url=GivenProperty(schema=Str()),
        browser=GivenProperty(schema=Str()),
    )

    def set_up(self):
        print("use browser {0}".format(self.given["browser"]))
        print("visit {0}".format(self.given['url']))

    def fill_form(self, **textboxes):
        for name, text in sorted(textboxes.items()):
            print("with {0}".format(name))
            print("enter {0}".format(text))

    def click(self, item):
        print("clicked on {0}".format(item))

带代码

from hitchstory import StoryCollection
from engine import Engine
from pathlib import Path

collection = StoryCollection(Path(".").glob("*.story"), Engine())

父级

collection.named("Login").play()

将输出

RUNNING Login in /path/to/working/example.story ... use browser firefox
visit /loginurl
with password
enter password
with username
enter hello
clicked on login
SUCCESS in 0.1 seconds.

以下步骤

collection.named("Visit inbox").play()

将输出

RUNNING Visit inbox in /path/to/working/example.story ... use browser firefox
visit /loginurl
with password
enter password
with username
enter hello
clicked on login
clicked on inbox
SUCCESS in 0.1 seconds.

替换步骤

collection.named("Login as hiya and visit inbox").play()

将输出

RUNNING Login as hiya and visit inbox in /path/to/working/example.story ... use browser firefox
visit /loginurl
with password
enter password
with username
enter hiya
clicked on login
clicked on inbox
SUCCESS in 0.1 seconds.

带变体和替换步骤

collection.named("Login as hiya and visit different pages/Dashboard").play()

将输出

RUNNING Login as hiya and visit different pages/Dashboard in /path/to/working/example.story ... use browser firefox
visit /loginurl
with password
enter password
with username
enter hiya
clicked on login
clicked on dashboard
SUCCESS in 0.1 seconds.

可执行规范

inheritance-steps.story storytests. 自动生成的文档。