有人可以告诉我"我怎样才能在使用python的行为中再次运行失败的测试".
如果失败,我想自动重新运行失败的测试用例.
任何帮助赞赏.
谢谢
我目前正在使用 Behave(用于 Python 的 BDD)并且一直在挖掘源代码以了解@given,@when和@then装饰器是如何声明的。
我走得最远的是看看step_registry.py我在哪里找到了setup_step_decorators(context=None, registry=registry)似乎在做这项工作的功能。
但是,我不太明白这些装饰器是如何创建的,因为它们似乎没有在源代码中以def when(...):. 我的印象是它们是基于字符串 ( for step_type in ('given', 'when', 'then', 'step'):)列表声明的,然后通过调用make_decorator().
有人可以引导我完成代码并解释这些装饰器的声明位置/方式吗?
我有一个行为场景大纲,我需要在其中使用管道字符 -|作为示例表中的单元格值。但我不知道如何转义这个字符不被视为列分隔符。我得到Malformed table的错误,当我尝试使用\|序列。
我已经安装了Pycharm社区版并使用以下命令安装了behave 1.2.5 。
pip install behave
Run Code Online (Sandbox Code Playgroud)
它已成功安装,并且可以在Pycharm 项目解释器中使用,如下所示。
但当我右键单击项目时,我没有看到创建 .feature 文件(Gherkin 文件)的选项
我是否错过了这里的任何内容,在 Pycharm professional 中默认 Behave BDD 可用。如何配置 Pycharm 社区的行为。
ExamplesGherkin 语法功能使用示例进行自动化测试:
Feature: Scenario Outline (tutorial04)
Scenario Outline: Use Blender with <thing>
Given I put "<thing>" in a blender
When I switch the blender on
Then it should transform into "<other thing>"
Examples: Amphibians
| thing | other thing |
| Red Tree Frog | mush |
| apples | apple juice |
Examples: Consumer Electronics
| thing | other thing |
| iPhone | toxic waste |
| Galaxy Nexus | toxic waste |
Run Code Online (Sandbox Code Playgroud)
测试套件将运行四次,每个示例运行一次,给出类似于以下内容的结果: …
我正在尝试使用行为框架、python 通过 BDD 测试来覆盖项目。问题是所有 BDD 材料都使用不真实的玩具示例。我的项目相当大,我遇到了以下问题
我是 Python 中的 BDD 新手,我正在尝试创建一个框架。根据文档,我创建了environment.py 文件,其中有一个方法:
def before_all(context):
context.config.setup_logging(configfile="test.ini", filename="AppLog.log")
Run Code Online (Sandbox Code Playgroud)
但我不确定需要在步骤(步骤方法)中添加什么,以便我的 AppLog.log 文件包含日志。我需要在步骤文件中初始化记录器吗?如果是的话,这个setup_logging将如何在那里使用?
如果可以提供示例代码,那么它将非常有帮助。
谢谢和问候, 苏尼尔
我不明白如何使用库正确运行简单的测试(功能文件和 python 文件)pytest-bdd。
从官方文档中,我无法理解要发出什么命令来运行测试。
我尝试使用pytest命令,但我看到没有测试运行。我是否需要使用另一个库behave来运行功能文件?
使用 Python/Selenium/Behave:
我想知道如何正确地将等待/睡眠装饰器添加到步骤函数中?
我用我的装饰器函数设置了一个 helper.py :
import time
def wait(secs):
def decorator(func):
def wrapper(*args, **kwargs):
ret = func(*args, **kwargs)
time.sleep(secs)
return ret
return wrapper
return decorator
class Helper(object):
pass
Run Code Online (Sandbox Code Playgroud)
在我的步骤文件中,我在行为装饰器之后调用等待装饰器以匹配步骤:
from behave import step
from features.helper import wait
@step('I observe a login error')
@wait(3)
def step_impl(context):
#time.sleep(3)
assert context.login_page.check_login_error() is not None
Run Code Online (Sandbox Code Playgroud)
但是,当我从功能文件执行该步骤时,没有执行等待/睡眠,并且断言失败。在这种情况下我该如何执行等待装饰器?