大量集成期间在本地主机服务器中运行量角器

时间:2019-02-27 21:24:11

标签: angularjs testing protractor integration-testing

我一直在研究量角器,并使用我们的生产网络应用程序编写了一些测试。现在,我想将此测试集成到我们的持续集成中。如果测试失败,则不应继续持续发布。

为实现这一目标,我计划在要生产的目标版本的本地服务器中运行相同的测试。我的项目是用angularjs编码的。我的package.json文件具有启动本地服务器和其他要测试的脚本,但是在运行测试之前,我无法等待服务器完全启动。

问题是:如何在localhost Web服务器上运行测试?

我的硒配置文件

exports.config = {
    framework: 'jasmine',
    seleniumAdress: 'http://localhost:4444/wd/hub',
    suites: {
        fluxos: './specs/fluxos/spec.js',
        validacoes: './specs/validacoes/spec.js'
    },
    capabilities: {
        browserName: 'chrome'
    },
}

我的package.json

{
  "scripts": {
    "build": "gulp build:dev",
    "build:hmg": "gulp build:hmg",
    "build:hmgi": "gulp build:hmgInterno",
    "build:prod": "gulp build:prod",
    "coverage": "gulp test:build",
    "lint": "./node_modules/.bin/eslint **/*.js",
    "precommit": "npm run lint",
    "prepush": "npm run coverage",
    "start": "gulp serve:dev",
    "start:hmg": "gulp serve:hmg",
    "start:hmgi": "gulp serve:hmgInterno",
    "start:prod": "gulp serve:prod",
    "test": "gulp test",
    "integration:validacoes": "gulp serve:prod && protractor ./tests/integration/conf.js --suite validacoes",
    "integration:fluxos": "gulp serve:prod && protractor ./tests/integration/conf.js --suite fluxos"
  },
  "dependencies": {
    "@uirouter/angularjs": "^1.0.15",
    "@uirouter/core": "^5.0.17",
    "angular": "^1.6.8",
    "angular-cookies": "^1.6.8",
    "angular-format-masks": "^1.0.2",
    "angular-i18n": "^1.6.8",
    "angular-input-masks": "^4.1.0",
    "angular-sanitize": "^1.6.8",
    "angular-spinner": "^1.0.1",
    "angular-touch": "^1.6.8",
    "angulartics": "^1.6.0",
    "angulartics-google-tag-manager": "0.0.1",
    "ng-accessibility-bar": "^1.2.3",
    "spin.js": "^2.3.2"
  },
  "devDependencies": {
    "angular-mocks": "^1.6.10",
    "autoprefixer": "^8.1.0",
    "babel-preset-env": "^1.6.1",
    "babel-preset-es2015": "^6.24.1",
    "browser-sync": "^2.23.7",
    "browser-sync-spa": "^1.0.3",
    "del": "^2.2.2",
    "eslint": "^3.12.2",
    "eslint-config-airbnb": "^13.0.0",
    "eslint-config-angular": "^0.5.0",
    "eslint-plugin-angular": "^1.6.1",
    "eslint-plugin-import": "^2.11.0",
    "eslint-plugin-jsx-a11y": "^2.0.0",
    "eslint-plugin-react": "^6.8.0",
    "gulp": "^3.9.1",
    "gulp-cachebust": "0.0.6",
    "gulp-clean-css": "^3.9.3",
    "gulp-eslint": "^4.0.2",
    "gulp-group-css-media-queries": "^1.2.2",
    "gulp-gzip": "^1.4.2",
    "gulp-htmlmin": "^3.0.0",
    "gulp-if": "^2.0.1",
    "gulp-imagemin": "^3.4.0",
    "gulp-ng-annotate": "^2.1.0",
    "gulp-ng-constant": "^2.0.0-3",
    "gulp-postcss": "^7.0.1",
    "gulp-rename": "^1.2.2",
    "gulp-sass": "^3.2.1",
    "gulp-sourcemaps": "^2.6.4",
    "gulp-uglify": "^1.5.4",
    "gulp-uglify-es": "^1.0.4",
    "gulp-uncss": "^1.0.6",
    "gulp-useref": "^3.1.5",
    "husky": "^0.12.0",
    "imagemin-gifsicle": "^5.2.0",
    "imagemin-jpegtran": "^5.0.2",
    "imagemin-optipng": "^5.2.1",
    "imagemin-svgo": "^5.2.4",
    "jasmine": "^2.99.0",
    "jasmine-core": "^2.99.1",
    "karma": "^1.7.1",
    "karma-babel-preprocessor": "^6.0.1",
    "karma-chrome-launcher": "^2.2.0",
    "karma-coverage": "^1.1.1",
    "karma-jasmine": "^1.1.1",
    "karma-junit-reporter": "^1.2.0",
    "karma-phantomjs-launcher": "^1.0.2",
    "karma-spec-reporter": "0.0.26",
    "karma-threshold-reporter": "^0.1.15",
    "postcss-pxtorem": "^4.0.1",
    "protractor": "^5.4.2",
    "protractor-helper": "^3.7.0",
    "run-sequence": "^1.2.2"
  }
}

1 个答案:

答案 0 :(得分:0)

您可以使用Shell脚本来检查服务器是否处于无限循环状态,并在服务器启动后退出。然后您可以运行测试

示例:./wait-for.sh && npm test

另一种方法是使用dockerdocker-compose容器化所有内容,然后运行测试。