未为自定义protractor.conf文件创建Webdriver实例

问题描述 投票:2回答:1

我想在Travis中集成我的E2E套件,所以我遵循了this的文章。正如文章中提到的,我创建了一个Travis构建的自定义protractor.ci.conf.js文件。我把这个文件放在我的e2e文件夹里(路径:e2e/protractor.ci.conf.js)。

我的自定义e2e/protractor.ci.conf.js和角度生成的protractor.conf.js文件的唯一区别是下面显示的args属性中的值。

E2E / protractor.ci.conf.js

chromeOptions: {
      args: [
        '--headless',
        'window-size=1920,1080'
      ]
    }

protractor.conf.js

const SpecReporter = require('jasmine-spec-reporter').SpecReporter;

exports.config = {
  allScriptsTimeout: 11000,
  specs: [
   './e2e/**/*.e2e-spec.ts'
  ],
  capabilities: {
    shardTestFiles: true,
    maxInstances: 2,
    'browserName': 'chrome',
    chromeOptions: {
      args: ['--start-maximized']
    }
  },
  directConnect: true,
  baseUrl: 'localhost:4000/',
  framework: 'jasmine',
  jasmineNodeOpts: {
    showColors: true,
    defaultTimeoutInterval: 300000,
    print: function () {
    }
  },
  useAllAngular2AppRoots: true,
  onPrepare: function () {
    jasmine.getEnv().addReporter(new SpecReporter());
    require('ts-node').register({
      project: 'e2e/tsconfig.json'
    });
  }
};

在我的package.json文件中,有两个脚本用于本地运行测试,一个用于Travis。

Package.json(与protractor.conf.js所在的同一级别)

 "scripts": {
    ...
    "test": "ng test --watch=false",
    "pree2e": "webdriver-manager update",
    "e2e": "concurrently --kill-others \"ng e2e --port=4000\" \"npm run _server:run\"",
    "e2e:ci": "concurrently --kill-others \"ng e2e --port=4000 --protractor-config=e2e/protractor.ci.conf.js\" \"npm run _server:run\"",
    "_server:run": "tsc -p ./server && concurrently \"tsc -w -p ./server\" \"nodemon dist/server/index.js\" ",
    ...
  },

.travis.yml

branches:
 only:
  - staging
  - prod
  - functional-testing
 script:
   ...
  - if [[ $TRAVIS_COMMIT_MESSAGE == *"[skip e2e]"* ]]; then echo "skipping E2E test"; else npm run e2e:ci; fi
  ...
before_deploy:
  - sed -i '/dist/d' .gitignore
  - git add . && git commit -m "latest build"
  - cd $TRAVIS_BUILD_DIR/dist

问题

当简单地运行npm run e2e时,每个测试都运行正常。但是当我使用npm run e2e:ci命令脚本时,挂起并且没有运行WebDriver的实例。

I / launcher - 运行WebDriver的0个实例

来了而不是1或2个实例。

selenium selenium-webdriver protractor travis-ci
1个回答
2
投票

那是因为你创建了一个新的配置文件,显然放在文件夹/e2e而不是默认的根文件夹中。

还应更新案例中测试文件的路径。

所以'./e2e/**/*.e2e-spec.ts'将改为'./**/*.e2e-spec.ts'

由于目前测试无法找到任何指定的文件,因此它不会运行任何实例。

© www.soinside.com 2019 - 2024. All rights reserved.