重新运行失败的测试用例需要量角器 Flake 指导

重新运行失败的测试用例需要量角器 Flake 指导

问题描述:

请更正我对以下内容的理解:

Please correct my understanding for the below:

  • 我已经安装了量角器片
  • 从网站上,我们有 2 套代码

我的假设

我很确定 B 部分需要在 configuration.js 文件中给出我的量角器项目的一部分,但它应该写在哪里.作为一个单独的文件,我应该写它,然后在我正在运行的规范文件中要求它们.我需要精确的步骤来实现上述

I'm pretty sure the B part needs to be given in configuration.js file of my protractor project but the A part where exactly should it be written. As a separate file should i write it and then require them in the spec file which i'm running.I need exact steps as to achieve the above

以下面开头的使用部分:

The usage section which starts with below:

    **var protractorFlake = require('protractor-flake')
    // OR using es6 modules/typescript
    import protractorFlake = require('protractor-flake')**
    and ends with **process.exit(status)**

和以开头的解析器部分module.exports = { 直到返回 [...failedSpecs]

and the parsers section which starts with module.exports = { till return [...failedSpecs]

根据文档,

添加依赖

npm i protractor-flake

# or globally for easier cli usage 
npm i -g protractor-flake

运行测试

选项 1:通过 CLI:

# protractor-flake <protractor-flake-options> -- <options to be passed to protractor> 
protractor-flake --parser standard  --max-attempts=3 -- path/to/protractor.conf.js

假设您的 conf.js 文件位于 root 目录中.

Assuming that your conf.js file is in root directory.

可用的命令行选项.

  • color?: string |布尔值

此处选择颜色或将false设置为禁用着色

choose color from here or set false to disable coloring

用法:protractor-flake --parser standard --color=magenta --max-attempts=3 -- conf.js

protractorArgs?: string[]

protractorPath?: string:像这样的量角器位置 'node_modules/.bin/protractor',

用法:protractor-flake --parser standard --protractorPath=node_modules/.bin/protractor --max-attempts=3 -- conf.js

parser?: string:其中之一的名称 解析器

用法:protractor-flake --parser standard --color=magenta --max-attempts=3 -- conf.js

您可以从 此处参考其他选项

选项 2:以编程方式

在您的 root 目录中创建文件为 flake 并复制以下代码段.

Create file in your root directory as flake and copy below snippet.

flake 是一个节点脚本,它使用 protractor-flake 重新运行失败的测试.笔记它在 file 级别重新运行测试,因此如果一个测试失败,它将重新运行所有该文件中的测试.感谢 Brian Ray 这个存储库

flake is a node script that uses protractor-flake to re-run failed tests. Note that it reruns tests at the file level, so if one test fails, it will rerun all the tests in that file. Thanks Brian Ray to this repository

#!/usr/bin/env node

/**
 *
 * usage:
 * `./flake conf.js [other protractor args]`
 */

const protractorFlake = require('protractor-flake');
// skip first two passed args (node and self)
let protractorArgs = process.argv.splice(2);
console.log(protractorArgs);

protractorFlake({
    protractorPath: 'node_modules/.bin/protractor',
    maxAttempts: 3,
    parser: 'standard',
    nodeBin: 'node',
    protractorArgs: protractorArgs
}, (status, output) => {
    process.exit(status);
});

创建此文件后,为了避免权限错误,只需运行 chmod +x ./flake

After creating this file, for avoiding permission error's just run chmod +x ./flake

运行您的测试用例

./flake conf.js

如果您将 specs 保留在测试套件中,只需在 conf.js 之后通过即可.

If you are keeping specs in a test suite, just pass after conf.js.

./flake conf.js --suite steam_test

在跑步之前,请检查这些注意事项

Before you are running, check these Caveats