当前位置: 首页 > news >正文

南海营销网站开发网络推广的方法你知道几个?

南海营销网站开发,网络推广的方法你知道几个?,南充网站建设服务商,超级滚轴wordpress企业主题BDD - Python Behave Retry 机制 引言Behave RetryBehave Retry 应用feature 文件创建 step 文件Retry运行 Behave 并生成 rerun 文件重新运行失败的场景 引言 在日常运行测试用例,有时因为环境不稳定造成一些测试用例跑失败了,如果能将这些失败的测试用…

BDD - Python Behave Retry 机制

  • 引言
  • Behave Retry
  • Behave Retry 应用
    • feature 文件
    • 创建 step 文件
    • Retry
      • 运行 Behave 并生成 rerun 文件
      • 重新运行失败的场景

引言

在日常运行测试用例,有时因为环境不稳定造成一些测试用例跑失败了,如果能将这些失败的测试用例再跑一遍,排除环境问题导致的不稳定,从而可以节省每天 triage 的时间。Behave 也有 retry 机制,今天就来了解一下吧。

想了解更多 Behave 相关的文章,欢迎阅读《Python BDD Behave 系列》,持续更新中。

Behave Retry

behave -f rerun 是 Behave 提供的一种输出格式(formatter),用于生成 “rerun” 格式的输出。-f rerun 选项可用于将测试失败的场景(Scenarios)输出到一个文件,然后可以使用这个文件来重新运行失败的测试。

以下是使用 behave -f rerun 的简单示例:

  1. 运行 Behave 并将失败的场景输出到 rerun 文件:
behave -f rerun -o failed_scenarios.txt

这个命令将运行测试并将失败的场景信息输出到 failed_scenarios.txt 文件中。生成的 rerun 文件包含了失败场景的标识符,如 features/my_feature.feature:3,这样 Behave 能够准确识别并重新运行这些场景。

  1. 重新运行失败的场景:
behave @failed_scenarios.txt

此命令将重新运行 failed_scenarios.txt 文件中列出的所有失败场景。

注意上面的命令有可能会执行失败因为 @ 符号异常,我们可以换另外一种方式执行,加上双引号""

behave "@failed_scenarios.txt"

Behave Retry 应用

举个简单的例子,项目结构如下:

在这里插入图片描述

feature 文件

创建 my_feature.feature 文件

Feature: Example FeatureScenario: Failing ScenarioGiven I have a failing stepWhen I perform an actionThen I should see a result

创建 step 文件

创建 my_steps.py 文件

from behave import given, when, then@given('I have a failing step')
def step_given(context):assert False, "Simulating a failure in the Given step"@when('I perform an action')
def step_when(context):print("When step executed")@then('I should see a result')
def step_then(context):print("Then step executed")

Retry

运行 Behave 并生成 rerun 文件

执行测试用例: behave Features/Retry -f rerun -o failed_scenarios.txt
将跑失败的测试用例输出到 failed_scenarios.txt 文件中。

PS C:\Automation\Test\bdd> behave Features/Retry -f rerun -o failed_scenarios.txtFailing scenarios:Features/Retry/my_feature.feature:3  Failing Scenario0 features passed, 1 failed, 0 skipped
0 scenarios passed, 1 failed, 0 skipped
0 steps passed, 1 failed, 2 skipped, 0 undefined       
Took 0m0.000s

当前目录生成 failed_scenarios.txt,文件内容列出失败 Scenario 的路径及行数。
在这里插入图片描述

重新运行失败的场景

执行命令 behave @failed_scenarios.txt
抛异常了:The splatting operator '@' cannot be used to reference variables in an expression

PS C:\Automation\Test\bdd> behave @failed_scenarios.txt      
At line:1 char:8
+ behave @failed_scenarios.txt
+        ~~~~~~~~~~~~~~~~~
The splatting operator '@' cannot be used to reference variables in an expression. '@failed_scen 
arios' can be used only as an argument to a command. To reference variables in an expression use '$failed_scenarios'.+ CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException+ FullyQualifiedErrorId : SplattingNotPermitted

换另外一种方式,将 @failed_scenarios.txt 用双引号包装一下。
执行命令 behave “@failed_scenarios.txt”

此命令将重新运行 failed_scenarios.txt 文件中列出的所有失败场景。在这个例子中,由于步骤定义中的 Given 步骤故意失败,Behave 将重试执行这个场景,并且你会看到类似于以下的输出:

PS C:\Automation\Test\bdd> behave "@failed_scenarios.txt"
Feature: Example Feature # Features/Retry/my_feature.feature:1Scenario: Failing Scenario    # Features/Retry/my_feature.feature:3Given I have a failing step # steps/my_steps.py:3Assertion Failed: Simulating a failure in the Given stepWhen I perform an action    # NoneThen I should see a result  # NoneFailing scenarios:Features/Retry/my_feature.feature:3  Failing Scenario0 features passed, 1 failed, 0 skipped
0 scenarios passed, 1 failed, 0 skipped
0 steps passed, 1 failed, 2 skipped, 0 undefined
Took 0m0.000s
http://www.mmbaike.com/news/40138.html

相关文章:

  • 什么网站访问量百度推广平台首页
  • 阿里巴巴上做网站要多少钱百度推广中心
  • 医院网站建设seo网站推广实例
  • 柬埔寨做网站赌博在那边违反吗在线网页服务器
  • 温州市网站销售网站有哪些
  • 怎么在网上做外贸苏州关键词优化排名推广
  • 新手怎么优化网站百度推广是什么意思
  • 纵横网站建立郑州seo关键词优化公司
  • 国内永久免费的crm深圳seo网站推广方案
  • 聊城网站营销信息免费网页制作网站
  • 新版在线天堂网品牌搜索引擎服务优化
  • 廊坊seo推广公司河南靠谱seo地址
  • WordPress做app下载企业网站优化推广
  • .net 网站模板 下载网站策划书模板范文
  • b2b综合平台和b2b垂直平台杭州关键词优化平台
  • 建筑建设行业网站抖音推广网站
  • 网站建设推广图片seo全网图文推广
  • 湖南郴州疫情最新消息排名优化关键词
  • 华为云速建站模板百度信息流开户多少钱
  • 在自己的网站里做讲课视频简述seo对各类网站的作用
  • 招商网站建设方案百度推广怎么操作
  • 做网站编码百度网站权重查询
  • 新企业名录数据免费网站推广优化的公司
  • 上海网站建设公司 珍岛网络营销的分类
  • 厦门网站建设公司排行榜搜索引擎有哪些类型
  • ps做网站框架搭建seo优化推广
  • 部门子网站建设方案线上运营的5个步骤
  • 做网站可以用海外空间吗做一个网站的步骤
  • 食品核酸第三方检测机构seo技术优化技巧
  • 邯郸建设网站的公司哪家好杭州百度seo