API automation cases,有时会因为环境的问题 fail 了一些 case,Triage 的时候把 fail 的 case 再本地重跑验证一下。怎样才能快捷方便的重跑呢?

Cucumber Rerun Formatter

Cucumber 提供 Rerun formatter,可以将跑 fail 的 cases 记录到一个文本中,然后直接运行这介文本就能重跑所有 fail 的 cases 了。

第一次运行,将 fail 的 cases 记录到 target/rerun-first.txt中,执行命令中options设置--format rerun:rerun txt path

mvn clean test -Dprofile=profile -Dcucumber.options="--tags '(tag filter expression)' --format rerun:target/rerun-first.txt"

target 目录下会生成 rerun-first.txt 的文本文件,内容类似下面这种,数字代码cases 对应的行号:
src/test/resources/features/…/feature1.feature:130:132:134
src/test/resources/features/…/feature.feature:82:83

重跑 rerun-first.txt 中 fail 的 cases,options 设置 @rerun txt path, 还可以继续记录 fail 的 cases 到文本 rerun-second.txt
注意:执行命令不要加 clean,不然 target 目录清掉了,前面保存的 rerun-first.txt 就清掉了。

mvn test -Dprofile=profile -Dcucumber.options="@target/rerun-first.txt --format rerun:target/rerun-second.txt"

Parallel run 的 Rerun

前面有篇文章介绍了有关 Cucumber Parallel Run,大大提高了cases 的运行时间,但是后面麻烦也来了,在 cucumber-jvm-parallel-plugin 中设置了 rerun plugin, 因为是按 feature 并行跑的,所以每个 feature 都产生了一个rerun 文本文件, 有多少个 feature,就生成多少个 rerun 文本文件,只是全 pass 的 feature 的 rerun 文本是空的而已,要是有一个汇总的 rerun文本就好了。

<plugins><plugin><name>json</name><extension>json</extension><outputDirectory>${project.build.directory}/cucumber-parallel/json</outputDirectory></plugin><plugin><name>html</name><extension>html</extension><outputDirectory>${project.build.directory}/cucumber-parallel/html</outputDirectory></plugin><plugin><name>rerun</name><extension>txt</extension><outputDirectory>${project.build.directory}/rerun</outputDirectory></plugin>
</plugins>

实在忍受不了人力一个个 case 重跑,或则一个个 rerun 的文本重跑,还是自己merge 一个总的 rerun 文本吧,哈哈。说干就干,还是用 Python 比较方便,在本地把脚本写好,测试没有问题。

import os
from os.path import abspath,getsize,curdir,joindef mergeRerunFiles(dirName):dir = abspath(join(curdir, dirName, "rerun"))file_list = os.listdir(dir)newFile = dir + '/rerun.txt'print(len(file_list))lines = []for f in file_list:file_path = abspath(join(dir,f))if getsize(file_path) > 0:with open(file_path,'r',encoding='utf-8') as fr:for line in fr.readlines():lines.append(line[line.find('src'):])with open(newFile, 'w') as fw:fw.writelines(lines)mergeRerunFiles("target")

再移步到 Jenkins 上,遇到 2 个问题

当 cases 执行完再执行这段 python 脚本。

  1. 执行 Shell 脚本跑 case,如果 case 都 PASS,会执行 python 脚本,但 case有 Failed,Python 脚本根本不会执行,
    解决方法:
    Execute shell 点击Advance…,在展开的 Exit code to set build unstable 中输入 1,这时如果该 shell 执行失败了,jenkins 的执行结果将不是 failure,而是unstable,执行后续的流程。

    下面这段是对 Exit code to set build unstable 设置的解释:

If set, the shell exit code that will be interpreted as an unstable build result. If the exit code matches the value, the build results will be set to ‘unstable’ and next steps will be continued. On Unix-like it is a value between 0-255. The value 0 is ignored and does not make the build unstable to keep the default behaviour consistent.

  1. 执行 Python 脚本有遇到异常
    with open(file_path,‘r’,encoding=‘utf-8’) as fr:
    TypeError: 'encoding' is an invalid keyword argument for this function
    解决方案:
    是因为 Jenkins 上的 Python 解释器版本比较老,不兼容,导入 io 便可解决。
import io
with io.open(file_path,'r',encoding='utf-8') as fr:

以上就是我在工作中遇到的问题,花时间研究并解决了,一劳永逸,提高 了工作效率,很开心,哈哈!

Cucumber Rerun Formatter相关推荐

  1. Cucumber使用进阶

    摘要 本文从实际使用Cucumber这一工具的角度,以Cucumber-JVM实现为基础,采用了不同的事例阐述了:如何编写feature文件,如何从feature文件生成对应的Steps,如何生成不同 ...

  2. cucumber学习笔记 -- 测试报告

    目录 1.谷歌浏览器查看用户配置路径 2.feature关键字中英文映射 3.cucumber测试报告 1). Pretty Report 2). HTML Reports 3). JSON Repo ...

  3. Cucumber Parallel Run

    篇幅比较长,列个提要吧: 背景 核心思想 方案一 方案二 方案三 方案四 执行策略 执行结果 POM 详细配置 背景: 日积月累 Smoke + Regression Test Cases 总数达 1 ...

  4. 【Cucumber】【命令行】

    知识点 参考:https://www.cnblogs.com/worklog/p/5253297.html cucumber的命令行选项 首先查看命令行选项.和其它命令行工具一样,cucumber提供 ...

  5. Cucumber入门之_World

    1. World: World可以看做是Cucumber在运行每个场景之前所要创建的对象的实例,它不仅使得每一个Step Definition可以调用该实例的方法,而且使得为该项目定义的Ruby类是也 ...

  6. Cucumber之五Cucumber Options详解

    英文视频教程地址是百度网盘,后续会放到微信公众号:[软测小生]里面,请关注公号更新相关文章和视频资源. ****************************分割线***************** ...

  7. cucumber Hooks @Before @After 不执行

    有时候我们会遇到, cucumber Hooks文件里的@Before @After不执行,通常是因为下面的几个原因: Before , After 需来自于Cucumber的包, eg: io.cu ...

  8. oozie调度中的重试和手工rerun一个workflow

    在oozie中有Bundle.Coordinator和Workflow三种类型的job,他们之间可以有以下包含关系. Bundle > Coordinator > Workflow. 1. ...

  9. Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo

    更新了xcode后使用goland运行项目时提示 Agreeing to the Xcode/iOS license requires admin privileges, please re-run ...

最新文章

  1. 二十一世纪贫穷人的2008条语录
  2. ajax发送post请求_按键精灵安卓版发送post和get请求
  3. 8天玩转并行开发——第八天 用VS性能向导解剖你的程序
  4. ITK:全局注册两个图像(仿射)
  5. dx postprocess
  6. OpenJudge/Poj 1226 Substrings
  7. string index out of range_Java 12 骚操作, String居然还能这样玩!
  8. javascript数字格式化通用类——accounting.js使用
  9. HttpWebRequest POST 数据时请求头多了一行Expect: 100-continue,少了数据行
  10. Gitlab-API各状态码解释
  11. MATLAB 工具箱傻瓜式求解 NS(Navier Stoke)方程
  12. 2014计算机科学与技术学科国际学术会议ei检索目录,2014年Ei核心期刊源目录(Ei Compendex)...
  13. Qt图形视图框架:图形形状图形项
  14. 我们为什么需要数字化转型?
  15. 浅谈微信三级分销系统的漏洞
  16. Python实现办公自动化
  17. Jerry Wang的SAP工作日志 - 2016年1月
  18. 微信小程序:全新独家云开发微群人脉
  19. sql服务器查看版本信息,SQL Server 各种版本号的查看
  20. springboot吕梁学院导师制管理系统 毕业设计-附源码251022

热门文章

  1. 【回归预测-lssvm分类】基于最小二乘支持向量机lssvm实现数据分类代码
  2. C4D模型工具—创建点/添加点
  3. 32、网络工程师必知的华为命令大全
  4. Atitit 手机号码选号 规范 流程 attilax总结 v4 s81.docx 1. Keyword关键词 2 2. 靓号的定义 2 3. 靓号的重要意义 与解决问题 为什么我们需要靓号
  5. 服务器系统导致无盘客户机usb失灵,无盘客户机无法启动/故障排查过程
  6. 惠普笔记本HP m4-1009tx安装mac os 10.11 笔记(uefi+clover+GPT)
  7. WorkNC配置与MAKINO牧野 MCC2013 6轴加工中心
  8. Windows聚焦功能失效怎么办?
  9. 计算机科学导论与前沿,计算机科学导论(英中双语版)
  10. 文件查找(locate、find)