量角器-仅当我针对每种Cucumber场景将鼠标移到浏览器窗口上时,才开始E2E测试

时间:2018-10-26 09:05:22

标签: angular google-chrome protractor cucumber

当我启动E2E测试时,我正在使用Angular 6 / Protractor / Cucumber应用程序,仅当我将鼠标移到浏览器窗口上时(对于每个Cucumber场景),它才开始。 我的protractor.conf.js

exports.config = {
  allScriptsTimeout: 100000,
  capabilities: {
    'browserName': 'chrome'
  },
  multiCapabilities: [
    {
      browserName: 'chrome',
      specs: 'e2e/features/*.feature'
    }
  ],
  directConnect: true,
  baseUrl: 'http://localhost:4201/',

  // Use a custom framework adapter and set its relative path
  framework: 'custom',
  frameworkPath: require.resolve('protractor-cucumber-framework'),

  // cucumber command line options
  cucumberOpts: {
    // require step definition files before executing features
    require: ["supports/timeout.js", './e2e/steps/**/*.ts', './cucumber/*.js'],
    // <string[]> (expression) only execute the features or scenarios with tags matching the expression
    tags: [],
    // <boolean> fail if there are any undefined or pending steps
    strict: true,
    // <string[]> (type[:path]) specify the output format, optionally supply PATH to redirect formatter output (repeatable)
    format: [
      'json:e2e/reports/summary.json'
    ],
    // <boolean> invoke formatters without executing steps
    dryRun: false,
    // <string[]> ("extension:module") require files with the given EXTENSION after requiring MODULE (repeatable)
    compiler: []
  },

  // Enable TypeScript for the tests
  onPrepare() {
    require('ts-node').register({
      project: './e2e/tsconfig.e2e.json'
    });
  },
};

第一个步骤的示例:

import {Before, Given} from 'cucumber';
import {browser} from 'protractor';
import {StepsUtils} from '../utils';


const {setDefaultTimeout} = require('cucumber');

Before(() => {
  setDefaultTimeout(60 * 15000);
});

Given('J\'ouvre Google Chrome en mode plein écran', function () {
  StepsUtils.navigateToRoot();
  browser.manage()
    .window()
    .maximize()
    .catch(ignoreVoid => {
      return;
    });
  return browser.getTitle();
});

浏览器已最大化,但是直到我将鼠标移到浏览器上时,后续步骤才会继续。如果我不将鼠标移到控制台上,则会显示以下错误:

E/launcher - script timeout: result was not received in 100 seconds
  (Session info: chrome=69.0.3497.100)

1 个答案:

答案 0 :(得分:0)

我已通过以下方法解决了这些问题:

在打开浏览器之前,我将waitForAngularEnabled设置为false,然后在对应用程序进行身份验证之后,将其设置为true。

通过以下方法更改waitForAngularEnabled的值:

browser.waitForAngularEnabled(true);