我编写了一个小实用程序包来处理文件权限.该结构遵循Python包标准:
.
|-- __init__.py # All the code is here, for now
`-- tests
|-- __init__.py
|-- permission_mode.feature # Feature files for behave
|-- steps
| |-- __init__.py
| `-- steps.py # Step files for behave
`-- test_modtools.py # Nose tests
Run Code Online (Sandbox Code Playgroud)
鼻子和行为都可以从命令行运行测试而不会出现问题:
鼻子:
$ nosetests
.
----------------------------------------------------------------------
Ran 1 test in 0.002s
OK
Run Code Online (Sandbox Code Playgroud)
表现:
$ behave
Feature: Lots of cheese # permission_mode.feature:1
Scenario: blah # permission_mode.feature:2
Given a # steps/steps.py:1 0.000s
Then b # steps/steps.py:5 0.000s
1 feature …Run Code Online (Sandbox Code Playgroud) 我想使用Splinter测试自动完成框。我需要将“向下”和“输入”键发送到浏览器,但是这样做很麻烦。
我目前正在寻找一个输入框,并在该框中成功输入“ tes”
context.browser.find_by_xpath(\\some\xpath\).first.type('tes')
Run Code Online (Sandbox Code Playgroud)
我接下来要做的是向浏览器发送一些键,特别是“向下”键(选择第一个自动完成建议),然后发送“ enter”键选择该自动完成元素。
我已经尝试了广泛的搜索,但不知道如何执行此操作。
我什至尝试了一些JavaScript
script = 'var press = jQuery.Event("keypress"); press.keyCode = 34; press.keyCode = 13;'
context.browser.execute_script(script)
Run Code Online (Sandbox Code Playgroud)
但这不幸的是没有做任何事情
我正在使用的软件包:
django 1.6 django-behave == 0.1.2碎片0.6
当前配置是:
从splinter.browser import从django.test.client import浏览器import Client
context.browser = Browser('chrome')
context.client = Client()
Run Code Online (Sandbox Code Playgroud) 有没有办法从python中运行python行为而不是通过命令行?
默认用法:在具有功能/步骤的基本文件夹中运行behave命令
所需用法:调用一个函数(或具有某个导入),该函数执行指定文件夹中的行为测试
当我运行行为时,它似乎是从python2.7运行的,并且无法找到为python3.4安装的硒。我是否需要配置行为以便在某个地方运行python3.4-在行为网站或其他地方什么也看不到。有关于在Python 3.4中使用行为的文章,因此是可能的。
这是我看到的:
$ behave
...
File "/usr/local/lib/python2.7/dist-packages/behave/runner.py", line 304, in exec_file
exec(code, globals, locals)
File "features/steps/home_page.py", line 2, in <module>
from selenium import webdriver
ImportError: No module named selenium
Run Code Online (Sandbox Code Playgroud)
我已经PYTHONPATH指向python 3.4 / dist-packages:
$ echo $PYTHONPATH
/usr/local/lib/python3.4/dist-packages
$ ls /usr/local/lib/python3.4/dist-packages/selenium
common __init__.py __pycache__ selenium.py webdriver
Run Code Online (Sandbox Code Playgroud)
我/usr/local/lib/pythonX.X/dist-packages在XX是2.7和3.4的地方都安装了行为
任何帮助,不胜感激。
我试图摆脱行为框架中的某些标准并遇到一些问题.是否可以拥有多个具有before*和after*钩子的environment.py文件?
我正在为一套微服务编写测试工具.我有以下目录树.
root
|-- step_defintions
| |-- service1
| |-- environment.py
| |-- __init__.py (steps, imports root.step_defintions.service1.envrionment)
| |-- service2
| |-- environment.py
| |-- __init__.py (steps, imports root.step_defintions.service2.envrionment)
|-- features
| |-- environment.py
| |-- steps
| |-- __init__.py (imports root.step_definitions *)
| |-- service1
| |-- 000_service1.feature
| |-- 001_service1.feature
| |-- service2
| |-- 000_service2.feature
Run Code Online (Sandbox Code Playgroud)
我的问题是它似乎没有在step_definitions/service [1 | 2] /envrionment.py文件中的*hook之后获取我之前的*.
我想将这些分开而不是在功能目录中用于组织目的.文件设置一些对象并将它们附加到上下文以跟踪某些步骤之间的数据
对于Java,有外部报告生成工具,如extent-report,testNG.Junit为单个要素文件生成xml格式输出.为了获得详细的报告,我在Behave框架中没有看到选项或广泛的方法或解决方案.
如何在Behave中生成报告,是否需要为Behave中的报告生成添加任何其他工具或框架?
我正在使用Python来做我的测试.在步骤文件中,我想获取当前步骤名称,因为如果测试失败,我会截取屏幕截图并将文件重命名为步骤名称.
像这样的东西:
给定用户登录
当用户做某事时
然后发生了一些事情
我希望我的步骤代码如下:
@given('user is logged in')
try:
# MY CODE HERE
except:
# GET THE STEP NAME HERE
Run Code Online (Sandbox Code Playgroud)
任何人都知道如何做到这一点?
有没有办法编写适用于多个关键字的步骤。就像说我的特点是:
Scenario: Something happens after navigating
Given I navigate to "/"
And say some cookie gets set
When I navigate to "/some-other-page"
Then something happens because of that cookie
Run Code Online (Sandbox Code Playgroud)
我试图避免同时定义:
@given('I navigate to "{uri}"')
def get(context, uri):
current_url = BASE_URL + uri
context.driver.get(current_url)
@when('I navigate to "{uri}"')
def get(context, uri):
current_url = BASE_URL + uri
context.driver.get(current_url)
Run Code Online (Sandbox Code Playgroud)
如果您只定义一个并尝试将其用作两者,则会出现raise NotImplementedError(u'STEP:错误。在上面的例子中,它并没有那么糟糕,因为这一步很简单,但重复代码似乎是一种不好的做法,而且你可能会在更复杂的事情上发生同样的事情,对我来说,如果有像一个@all 或 @any 关键字。
抱歉,如果这已在某处得到解答,但很难搜索,因为很难找到此类问题的独特搜索词
我想在执行我的函数之前执行某个步骤。该步骤将变量作为参数。我无法在 context.execute_steps 中传递它。
eg.
call1 = "version"
call1_method = "get"
context.execute_steps('''When execute api{"method":call1_method, "call":call1}''')
Run Code Online (Sandbox Code Playgroud)
但是这不起作用。我在参数解析中出错,因为变量不在引号中。我在行为文档中没有看到任何这样的例子。任何帮助将非常感激。
我正在寻找重复运行行为功能测试,但每个测试都有不同的参数,有点像 pytest 的参数化https://docs.pytest.org/en/latest/reference.html#pytest-mark-parametrize-ref
我找不到任何表明这可以在一次行为运行中完成的内容。这是否必须在外部完成,例如通过 bash 脚本,该脚本多次调用行为,每次运行都使用例如 userdata http://behave.readthedocs.io/en/latest/behave.html传递参数?highlight=userdata#cmdoption-define,或者还有其他选择吗?
实际参数本身也在运行时动态找到,在一组动态确定的参数集上运行所有测试。
python-behave ×10
python ×8
bdd ×4
django ×1
python-3.x ×1
report ×1
setuptools ×1
splinter ×1