首页 > 解决方案 > Protractor - E2E 测试仅在我将鼠标移到每个 Cucumber 场景的浏览器窗口上时开始

问题描述

当我启动 E2E 测试时,我正在开发一个 Angular 6/Protractor/Cucumber 应用程序,它仅在我将鼠标移到浏览器窗口上时才会启动(对于每个 Cucumber 场景)。我的量角器.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'
    });
  },
};

以及 step 的一个例子:

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)

标签: angulargoogle-chromeprotractorcucumber

解决方案


我已经通过这样做解决了这些问题:

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

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

browser.waitForAngularEnabled(true);


推荐阅读