没有“webdriver-manager start”运行量角器测试

时间:2018-03-08 07:24:31

标签: typescript webdriver protractor automated-tests

我可以在没有手动编写命令行“webdriver-manager start”的情况下运行量角器测试吗?如何在代码中运行“webdriver-manager start”? 我用TypeScript编写。

2 个答案:

答案 0 :(得分:1)

将评论扩展为答案

带有“&&”

的NPM脚本

一个想法是使用NPM脚本块基本上只生成一个运行的命令,它将启动服务器然后启动测试。您只需运行此命令并启动webdriver,然后执行测试 - 如果您需要在控制台窗口中进行测试,则可以按CTRL + C服务器。

时序

Webdriver-Manager可能需要一些时间来启动服务器。如果第一个脚本不起作用,请尝试第二个脚本并注意包含“sleep()”以创建webdriver的启动延迟。

(bootup> pretest> test)package.json

{
  "name": "protractorautomation",
  "version": "1.0.0",
  "description": "Protractor Typescript automation framework",
  "main": "config.js",
  "dependencies": {
    "protractor": "^4.0.11"
  },
  "devDependencies": {},
  "scripts": {
    "pretest": "npm run tsc",
    "test": "protractor ConvertedJSFiles/config.js",
    "tsc": "tsc",
    "webdriver:start": "webdriver-manager start",
    "webdriver:update": "webdriver-manager update",
    "dev": "npm run webdriver:start && npm run pretest && npm run test"
  },
  "keywords": [
    "Protractor",
    "Typescript"
  ],
  "license": "ISC"
}

(启动>睡眠/延迟> pretest>测试)package.json

{
  "name": "protractorautomation",
  "version": "1.0.0",
  "description": "Protractor Typescript automation framework",
  "main": "config.js",
  "dependencies": {
    "protractor": "^4.0.11"
  },
  "devDependencies": {
    "sleep": "*"
  },
  "scripts": {
    "pretest": "npm run tsc",
    "test": "protractor ConvertedJSFiles/config.js",
    "tsc": "tsc",
    "sleep": "node sleep.js",
    "webdriver:start": "webdriver-manager start",
    "webdriver:update": "webdriver-manager update",
    "dev": "npm run webdriver:start && npm run sleep && npm run pretest && npm run test"
  },
  "keywords": [
    "Protractor",
    "Typescript"
  ],
  "license": "ISC"
}

<强> sleep.js

require('sleep').sleep([n seconds to sleep])

答案 1 :(得分:0)

您可以改为定义gulp任务。使用npm install gulp&amp;创建一个gulpfile.js

有关更多信息,请参阅我的github回购:github-repo-tyaga001

var gulp = require('gulp');
var gulpProtractor = require('gulp-angular-protractor');
var params = process.argv;
var args = process.argv.slice(3);
var paths = require('../paths.js');

// Execute e2e Tests
 gulp.task('e2e-test', function(callback) {
     gulp.src(paths.tests)
         .pipe((gulpProtractor({
                 configFile: 'protractor.conf.js',
                 args: args
         })).on('error', function(e) {
                 console.log(e);
             }).on('end', callback));
 });


 gulp.task('webdriver-update', gulpProtractor.webdriver_update);
gulp.task('webdriver-standalone', ['webdriver-update'], gulpProtractor.webdriver_standalone);