夜间守夜并行运行测试

时间:2018-06-22 21:00:33

标签: nightwatch.js

需要一些帮助来确定如何并行运行测试。 这是项目的配置方式以及我用来运行测试的命令。

在终端窗口中运行命令-'npm run test-qa',实际调用'package.json',其中有一个脚本标签称为'test-qa'。 这是我的package.json的样子:

{
  "name": "Project",
  "version": "2.0.0",
  "dependencies": {
    "babel-core": "^6.8.0",
    "babel-eslint": "^7.2.3",
    "babel-loader": "^7.1.2",
    "babel-polyfill": "^6.8.0",
    "babel-preset-es2015": "^6.6.0",
    "babel-preset-react": "^6.5.0",
    "babel-preset-react-hmre": "^1.1.1",
    "babel-preset-stage-0": "^6.5.0",
    "babel-register": "^6.26.0",
    "eslint-loader": "^1.9.0",
    "gulp": "^3.9.1",
    "gulp-eslint": "^4.0.0",
    "gulp-nightwatch": "^0.2.6",
    "handlebars": "^4.0.10",
    "json-parser": "^1.1.5",
    "json-stringify": "^1.0.0",
    "oracledb": "^1.13.1",
    "webpack-nightwatch-plugin": "^1.0.0"
  },
  "scripts": {
    "test-local": "eslint . && gulp local:e2e --compilers js:babel-core/register --require babel-polyfill",
    "test-dev": "eslint . && gulp dev:e2e --compilers js:babel-core/register --require babel-polyfill",
    ***"test-qa": "eslint . && gulp qa:e2e --compilers js:babel-core/register --require babel-polyfill --env local",***
  },
  "devDependencies": {
    "gulp": "^3.9.1",
    "moment-timezone": "^0.5.20",
    "selenium-server-standalone-jar": "2.47.1"
  }
}

在这种情况下,来自package.json的test-qa标签又调用gulpfile.js来执行实际任务(qa:e2e)。这是我的gulp文件代码:

const gulp = require('gulp');
const nightwatch = require('gulp-nightwatch');

const eslint = require('gulp-eslint');

gulp.task('qa:e2e', function qaSpec() {
    process.env.seleniumon = 'qa';
    return gulp.src('')
        .pipe(nightwatch({
            configFile: 'nightwatch.json',
            cliArgs: ['--env local', '--reporter html-reporter.js']
        }));
});

gulp.task('local:e2e', function localSpec() {
    process.env.seleniumon = 'local';
    return gulp.src('')
        .pipe(nightwatch({
            configFile: 'nightwatch.json',
            cliArgs: ['--env local', '', '--reporter html-reporter.js']
        }));
});

gulp.task('dev:e2e', function devSpec() {
    process.env.seleniumon = 'dev';
    return gulp.src('')
        .pipe(nightwatch({
            configFile: 'nightwatch.json',
            cliArgs: ['--env local', '--reporter html-reporter.js']
        }));
});

gulp.task('lint', function srcSpec() {
    return gulp.src(['**/*.js', '!node_modules/**'])
        .pipe(eslint())
        .pipe(eslint.format())
        .pipe(eslint.failAfterError());
});

gulp.task('default', ['lint']);

来自gulpfile.js的qa:e2e任务现在调用nightwatch.json文件以获取设置并继续执行。这是我的nightwatch.json文件:

{
  "src_folders": ["tests"],
  "output_folder": "reports",
  "custom_commands_path": [ "commons/util", "commons/up", "commons/searchPane", "commons/EditorValidations", "commons/model"],
  "custom_assertions_path": "",
  "page_objects_path": ["pages/admin", "pages/UP", "pages/searchPane", "pages/EditorValidations/CMO", "pages/EditorValidations/CPO", "pages/EditorValidations/GMO", "pages/EditorValidations/GPO", "pages/model"],
  "globals_path": "",

  "selenium" : {
    "start_process" : true,
    "server_path" : "./node_modules/selenium-server-standalone-jar/jar/selenium-server-standalone-2.47.1.jar",
    "host" : "127.0.0.1",
    "port" : 4444,
    "cli_args" : {
      "webdriver.chrome.driver" : "drivers/chromedriver",
      "webdriver.ie.driver" : ""
    }
  },

  "test_settings": {
    "chrome": {
      "selenium_port": 4444,
      "selenium_host": "selenium-hub.nikedev.com",
      "skip_testcases_on_fail": true,
      "end_session_on_fail":false,
      "globals": {
        "platform": "desktop"
      },
      "screenshots": {
        "enabled": true,
        "on_failure": true,
        "on_error": true,
        "path": "screenshots/chrome"
      },
      "desiredCapabilities": {
        "browserName": "chrome",
        "javascriptEnabled": true,
        "acceptSslCerts": true
      }
    },
    "local": {
      "selenium_port": 4444,
      "selenium_host": "127.0.0.1",
      "skip_testcases_on_fail": true,
      "end_session_on_fail":false,
      "globals": {
        "platform": "desktop"
      },
      "screenshots": {
        "enabled": true,
        "on_failure": true,
        "on_error": true,
        "path": "screenshots/chrome"
      },
      "desiredCapabilities": {
        "browserName": "chrome",
        "javascriptEnabled": true,
        "acceptSslCerts": true
      }
    }
  }
}

此设置能够无缝执行。 我想并行运行测试用例,为此,我在“ global_path”之后将以下行添加到nightwatch.json中   “ test_workers”:{“ enabled”:true,“ workers”:“ auto”},

更改此配置后,永远不会以错误启动测试'throw new Error('指定的无效测试环境:'+ envs [i]);'即使我的gulp文件提到了我们希望其运行的环境。 cliArgs:['--env local','--reporter html-reporter.js']

有人可以帮助我了解我需要进行哪些更改才能并行运行测试用例吗?

1 个答案:

答案 0 :(得分:0)

workers选项配置可以同时运行多少个子进程。     •“自动”-由CPU数量决定,例如4个CPU意味着4个工人     •{number}-指定确切的工人数 测试并发在文件级别完成。每个测试文件将填充一个测试工作程序插槽。测试文件中的各个测试/步骤不会同时运行。 0.9版改进了对并行运行测试时显示输出的支持。建议在测试设置中将detailed_output设置为false,以提高输出的可读性。

请参阅此链接:

  

https://github.com/nightwatchjs/nightwatch-docs/blob/master/guide/running-tests/run-parallel.md