提高行为测试的性能

improving performance of behave tests

我们 运行 在我们的管道中执行 BDD 测试。我们 运行 docker 容器中的测试作为 jenkins 管道的一部分。目前 运行 所有测试需要大约 10 分钟。我们正在添加大量测试,几个月后,它可能会增加到 30 分钟。它正在输出大量信息。我相信,如果我减少它输出的信息量,我可以更快地让测试达到 运行。有没有办法控制行为输出的信息量?我只想在出现故障时打印信息。 我看了一下行为平行。看起来它在 python 2.7 中。我们在 python3。 我正在查看 behave 提供的各种选项。

behave -verbose=false folderName (I assumed that it will not output all the steps) behave --logging-level=ERROR TQXYQ (I assumed it will print only if there is an error) behave --logging-filter="Test Step" TQXYQ (I assumed it will print only the tests that has "Test Step" in it) 以上 None 个有效。

当前输出如下所示

场景大纲:IsError 已根据测试 ID 正确填充 -- @1.7 # TestName/Test.feature:187 鉴于测试文件夹设置为 /TestName/steps/ # common/common_steps.py:22 0.000s 服务是 运行ning # common/common_steps.py:10 0.000s 使用的给定请求是 current.json # common/common_steps.py:26 0.000s 并且请求修改为将X设置为str类型的q#common/common_steps.py:111 0.000s 并修改请求以将 Y 设置为 str 类型的 null # common/common_steps.py:111 0.000s 并修改请求以将 Z 设置为 str 类型的美元 # common/common_steps.py:111 0.000s<br> 修改请求时#common/common_steps.py:37 0.203s 然后它 returns 200 状态码 # common/common_steps.py:47 0.000s 转换后的结果有 IsError,类型为 0 # common/common_steps.py:92 0.000s 转换后的结果有 ErrorMessages 包含 [] # common/common_steps.py:52 0.000s

我只想在出现错误时才打印所有这些东西。如果一切顺利,我不想显示此信息。

我认为默认日志级别 INFO 不会影响您的测试性能。
我还使用 docker 容器来 运行 回归套件,运行 2300 个测试场景需要大约 2 个小时。花了将近一天的时间,这就是我所做的:
1。 运行 所有测试套件并行
这是减少执行时间的最重要原因。
我们花了很多努力将回归套件变成可并行的。
- 进行原子的、自主的和独立的测试 这样您就可以运行 有效地并行进行所有测试。
- 在多个进程上创建并行 运行ner 到 运行 测试。 我正在使用多处理和子处理库来执行此操作。
我不会推荐 behave-parallel,因为它不再受到主动支持。
你可以参考这个 link :
http://blog.crevise.com/2018/02/executing-parallel-tests-using-behave.html?m=1
- 使用 Docker Swarm 将更多节点添加到 Selenium Grid 中。
您可以向上扩展以添加更多节点,最大节点数取决于 cpu 的数量。最佳做法是节点数 = cpu 的数量。
我有 4 台 PC,每台都有 4 个内核,因此我可以扩展到 1 个集线器和 15 个节点。

2。优化框架中的同步。
删除 time.sleep()
删除隐式等待。改用显式等待。

希望对您有所帮助。

好吧,我已经用传统方法解决了这个问题,但我不确定它的效果如何。我昨天才开始做这件事,现在正试图从中构建报告。做法如下,欢迎指教

这也解决了驱动示例中的并行执行问题。

parallel_behave.py 运行 命令(模仿 behave 命令的所有参数) py parallel_behave.py -t -d -f ......

initial_command = 'behave -d -t <tags>'
'''
the above command returns the eligible cases. may not be the right approach,                  but works well for me
'''

r = subprocess.Popen(initial_command.split(' '), stdout=subprocess.PIPE, bufsize=0)
finalsclist = []

_tmpstr=''
for out in r.stdout:
    out = out.decode('utf-8')
    # print(out.decode('utf-8'))
    if shellout.startswith('[') :
        _tmpstr+=out
    if shellout.startswith('{') :
        _tmpstr+=out
    if shellout.startswith(']'):
        _tmpstr+=out
        break

scenarionamedt = json.loads(_tmpstr)

for sc in scenarionamedt:
    [finalsclist.append(s['name']) for s in sc['elements']]

now the finalsclist contains the scenario name
ts = int(timestamp.timestamp)
def foo:
   cmd = "behave -n '{}' -o ./report/output{}.json".format(scenarioname,ts)

pool = Pool(<derive based on the power of the processor>) 
pool.map(foo, finalsclist)

这将创建多个单独的 behave 调用进程,并在报告文件夹

下生成 json 输出

*** 有来自 https://github.com/hugeinc/behave-parallel 的参考,但这是在功能级别。我只是将它扩展到场景和示例 ****