问题标签 [python-behave]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
662 浏览

python - Behaviour Driven Development - Undefined steps in Behave using Python with Flask

I'm following a Flask tutorial and currently looking at Behaviour Driven Development using Behave.

My task is to build a very basic blog application that allows a single user to log in, log out and create blog posts, using BDD.

I've written the feature file, the steps file and the environment file. I've then written code to enable a user to log in and out.

When I run the application locally and manually test, it works as expected allowing the user to log in and out and displays the required text ("You were logged in" or "You were logged out"), so I'm assuming the problem is with the feature file or steps file rather than the application code.

When I run Behave, the final step appears to be "undefined".

The relevant part of the feature file is:

And my steps file is:

From the environment file:

It is the final "then" step that seems to be the problem. I've tried checking the tutorial solutions and searching elsewhere but I can't seem to solve this part of the code. I've had to encode the message as I am using Python version 3.5 (the tutorial was using version 2.7 if this is relevant).

Any pointers would be very much appreciated.

0 投票
1 回答
3575 浏览

python - 使用 Pycharm 调试 python-behave 步骤

我正在使用 Pycharm 编写测试并以行为方式运行它们。我正在使用 cli 运行行为命令。要编写我正在使用 Pycharm 的功能和场景。我如何调试每个步骤?

0 投票
1 回答
5740 浏览

python-2.7 - 行为 ImportError:没有名为 features.steps.pages.home_page 的模块

我在 Python Behave 中有一个示例 BDD 场景。当我运行该功能时,我收到错误:

我不确定它为什么抱怨。home_page.py 位于 pages 文件夹中, pages 位于 steps 文件夹中,而 steps 文件夹位于 features 文件夹中。在 pages 文件夹中,我有一个 init.py 文件。
为什么它抱怨找不到 home_page.py?

我的代码是: features\steps.py

features\steps\pages\home_page.py

特征\test_feature.feature

我的目录结构是:

完整的错误是:

我该如何解决这个问题?

谢谢,里亚兹

0 投票
1 回答
8033 浏览

python-2.7 - Python Behave 'Context' 对象没有属性 'find_element'

我有一个示例 BDD Python 行为代码。当我运行行为 test.feature 时,主页会打开,但随后出现以下错误:

完整的错误是:

我的代码片段是:

测试功能:

步骤.py

浏览器.py

环境.py

它没有找到 find_element,我想使用它以便可以在网页上找到元素。在 Behave 中使用 Fine_element 的正确语法是什么?

谢谢,里亚兹

0 投票
3 回答
4595 浏览

python - 未在行为步骤中捕获日志记录

好的,所以在我的 environment.py 文件中,我可以通过以下方式记录内容:

但是当我在步骤文件中时,我无法执行日志记录:

步骤内的日志消息不显示。我正在使用 python 行为模块。有任何想法吗?

我尝试在运行行为时启用和禁用日志捕获,但这没有区别。

0 投票
1 回答
1575 浏览

python-2.7 - Python - 行为 - 两个具有相同名称的不同步骤

我正在使用 Behave 运行我的 python 测试

我想要做的是在不同的步骤文件中实现相同的步骤,例如“UserA 调用 UserB”,并将测试指向正确的步骤教导时间。

例如:

.feature 文件内容:

然后,在 step 文件夹中,我将有一个 .py 文件,其中包含:

另一个步骤 .py 文件将包含:

我想控制将执行这些步骤中的哪一个。有没有一种干净的方法可以做到这一点?

0 投票
1 回答
392 浏览

python-behave - 执行行为时的python-behave-invalid命令

IDE PyCharm 专业版,python 3.4.5,behave 1.2.5,环境 Windows 7;注意:我正在从功能文件目录运行命令;当我尝试使用行为命令语法执行功能文件时(例如:行为 home_page.feature);行为解释器响应以下消息'invalid command name 'home_page.feature'。什么可能导致行为解释器将功能文件解析为命令名称?这会是环境问题吗?这不是 PyCharm 社区版“免费”的问题(我确实升级到专业版以获得对 PyChram 专业版中行为驱动开发 (BDD) 功能的完全访问权限)。

0 投票
1 回答
2217 浏览

python - 多个python Behave环境设置文件

我试图脱离行为框架中的一些标准并遇到一些问题。是否可以有多个具有 before* 和 after* 挂钩的 environment.py 文件?

我正在为一套微服务编写测试工具。我有以下目录树。

我的问题是它似乎没有在 step_definitions/service[1|2]/envrionment.py 文件中获取我的 before*、after* 挂钩。

为了组织目的,我希望将这些分开而不是放在 features 目录中。这些文件设置了一些对象并将它们附加到上下文以跟踪某些步骤之间的数据

0 投票
1 回答
744 浏览

python - 在运行时为行为表生成数据

我有一个行为测试,我希望在执行步骤后生成行为表中的部分数据。例如

执行该when步骤后,我想<val>根据该步骤修改为某个值。

0 投票
1 回答
263 浏览

python - Django + bdd + 硒

我正在使用 BDD 功能来描述我们的一些项目。然后使用 django 测试客户端https://docs.djangoproject.com/en/1.10/topics/testing/tools/实现大多数场景,但有些场景正在通过 selenium 进行测试。理论上,其中一些功能可以通过两种方法(通过 selenium 和测试客户端)进行测试,但我不知道如何从编码的角度来解决这个问题。我想让我的 bdd 场景实现免费(没有像“鉴于我使用 selenium 作为测试工具”)。

我正在考虑在可行的情况下对每个步骤进行多个定义,然后使用针对给定场景实现所有步骤的实现(甚至更多)。我猜这将需要更改 python-behave 实现。任何人都面临类似的问题?

编辑:

我发现的第一件事是使用阶段并为“阶段”设置每个实现: https ://pythonhosted.org/behave/new_and_noteworthy_v1.2.5.html#test-stages 这可以解决我的问题,我可以运行测试每个阶段。唯一要解决的是特定于实现(阶段)的功能。在最坏的情况下,我可以进行虚拟传递步骤。