【问题标题】:Protractor Flake with Typescript implementation not working带有 Typescript 实现的 Protractor Flake 不起作用
【发布时间】:2018-07-18 08:33:11
【问题描述】:

所以我有以下场景。

我们有一个基于this 框架的Protractor-Cucumber 框架。

该框架已被修改为配置文件是用 TS 编写的。这是一个示例配置:

import { browser, Config } from 'protractor';
import { Reporter } from '../support/reporter';

const jsonReports = process.cwd() + '/reports/json';

export const config: Config = {

    directConnect: true,
    SELENIUM_PROMISE_MANAGER: false,

    stackTrace: true,

    capabilities: {
        browserName: 'chrome'
    },

    framework: 'custom',
    frameworkPath: require.resolve('protractor-cucumber-framework'),

    specs: [
        '../../features/*.feature',
        '../../features/**/*.feature',
    ],

    onPrepare: () => {
        browser.manage().window().maximize();
        Reporter.createDirectory(jsonReports);
    },

    cucumberOpts: {
        compiler: 'ts:ts-node/register',
        format: 'json:./reports/json/cucumber_report.json',
        require: [
            '../../stepdefinitions/*.ts',
            '../../stepdefinitions/**/*.ts',
            '../../support/*.ts'
        ],
        strict: true,
        tags: '(@e2e) and (not @ignore) and (not @notImplemented)',
        keepAlive: false,
    },
    allScriptsTimeout: 10000,
    getPageTimeout: 5000,
    onComplete: () => {
        return Reporter.generateReports();
    },
    afterLaunch: exitCode => {
        if (exitCode === 1) {
            console.log('Actual Exit code: ' + exitCode);
            process.exit(0);
        }
    }
};

回顾一下这个实现的框架,现在他们已经实现了 protractor-flake,这是我需要包含的东西。

我已经尝试使用正在使用的实际配置,并且可以看到 here 但是当我尝试运行它时,我收到以下错误:

E/configParser - Error code: 105
[09:14:04] E/configParser - Error message: failed loading configuration file ./build/config/conf.debug.js
[09:14:04] E/configParser - Error: Cannot find module 'C:\Users\Protractor\build\config\conf.debug.js'

请注意,我已更改量角器参数以加载上面显示的配置,因此显示无法加载 config.debug.js。

我还浏览了 Nick Tomlin 的 protractor flake 和 cucumber 特定文档的存储库,并在 After support 代码中添加了必要的 console.log 并测试了从 cli 运行的 protractor flake,但似乎没有任何效果。我收到上面的错误,然后是:

使用黄瓜解析输出 测试失败,但未找到规范。

将再次运行所有规范。重新运行测试:测试尝试 2

但是没有运行测试。即根本不跑。

当我使用 npm 运行常规配置时,一切运行良好,无需重新运行量角器薄片。

谁能在这个问题上提供他们的 2 美分,我错过了什么?

我已经搜索了相当多的内容以找到一个打字稿示例,但目前还没有,除非我错过了。

对不起,我知道它很长,但想尝试涵盖我尝试过的所有内容。

提前致谢。

【问题讨论】:

  • 能否提供测试启动命令及其参数?
  • 当然。 npm run build && protractor-flake --parser cucumber --max-attempts=3 ./build/config/config.debug.js

标签: typescript protractor cucumberjs


【解决方案1】:

我在嵌入 protractor-flake 时遇到了类似的问题。

1) 检查您当前的debug.conf.js 是否有效。通过将debug.conf.js 复制到计算机上的某个文件夹并运行protractor-flake 并在args 中使用debug.conf.js 的绝对路径来实现此目的。

2) 如果第 1 步有效,您必须将 debug.conf.js 迁移到 typescript,只需将 .ts 放在末尾并将内容更改为:

// debug.conf.ts
const protractorFlake = require('protractor-flake');
const argv = require('yargs').argv;

export default (function () {
  protractorFlake({
    maxAttempts: 2,
    parser: 'cucumber',
    protractorArgs: [
      './e2e-tests/config/protractor.e2e.conf.js',
      `--feature=${argv.feature || '*'}`,
      `--tags=${argv.tags || ''}`
    ]
  }, (status) => {
    process.exit(status);
  });
})();

您必须在配置中调整此路径:'./e2e-tests/config/protractor.e2e.conf.js',它应该是指向已构建javascriptprotractor.e2e.conf.js 的正确相对路径。

debug.conf.ts中你可以看到一个默认的export,它是一个函数,这个函数会立即执行。也就是说,如果我们运行require('./somePath/debug.conf'),或者ts-node debug.conf.tsprotractor-flake将直接被执行。然后,您可以例如存储以下 npm 脚本以运行 protractor-flake

// ...
"scripts": {
   "protractor.flake": "ts-node ./somePath/debug.conf.ts"
}
// ...

如果有什么不清楚或不起作用,请告诉我,干杯!

【讨论】:

  • 感谢您的宝贵时间。我一步一步地尝试了这个,并认为我确实做到了这一点。但是这一次在这之后它起作用了。再次感谢西尔万。现在我只需要看看如何合并每次运行创建的报告以包含所有通行证:)
  • 如果您需要帮助,请告诉我 :),gl
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-04-02
  • 1970-01-01
  • 1970-01-01
  • 2019-11-02
  • 1970-01-01
  • 2012-10-10
  • 2015-03-12
相关资源
最近更新 更多