实验性
此功能处于 alpha 阶段。API 可能会在次要版本增量中更改。
子故事可以基于父故事。
注意:此功能存在错误,现在避免将继承和参数化一起使用。
代码示例
example.story
Login:
given:
url: /loginurl
browser: firefox
with:
username: AzureDiamond
password: hunter2
steps:
- Fill form:
username: (( username ))
password: (( password ))
- Click: login
- Click: inbox
Visit inbox:
based on: login
with:
username: DonaldTrump
password: Th3Don@ld
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 (( username ))
clicked on login
clicked on inbox
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 (( username ))
clicked on login
clicked on inbox
SUCCESS in 0.1 seconds.
可执行规范
从 inheritance-parameters.story storytests 自动生成的文档。