得到未定义。使用以下代码段实施: - >量角器+黄瓜

时间:2018-05-20 08:33:18

标签: typescript protractor cucumber yarnpkg

尝试将我的jasmine框架转换为黄瓜框架,尝试了很多选项。但仍然低于错误

命令

protractor protractor.conf.js --cucumberOpts.tags="@login" 

也厌倦了纱线,但结果却出现了同样的错误

yarn e2e

错误

warnings:
1) Scenario: Login - Admin Login with 'VALID' UserName and Password - e2e/features/login.feature:6
   Step: Given I navigate to application - e2e/features/login.feature:7
   Message:
     Undefined. Implement with the following snippet:
       this.Given(/^I navigate to application$/, function (callback) {
         // Write code here that turns the phrase above into concrete actions
         callback(null, 'pending');
       });
1 scenario (1 undefined)
1 step (1 undefined)
0m00.001s
[09:17:59] I/launcher - 0 instance(s) of WebDriver still running
[09:17:59] I/launcher - chrome #01 failed 1 test(s)
[09:17:59] I/launcher - overall: 1 failed spec(s)
[09:17:59] E/launcher - Process exited with error code 1
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! ir-backoffice@0.11.9 e2e: `ng e2e`
npm ERR! Exit status 1

功能文件。

login.feature

Feature: Login Regression Feature
  As a IR admin, I want to Login through IR Application
  So that Client can access application features

  @login
  Scenario:Login - Admin Login with 'VALID' UserName and Password
    Given I navigate to application

和步骤定义文件

import { LoginDriver } from '../../drivers/login.driver';

const loginDriver = new LoginDriver();
import { browser } from 'protractor';
import { defineSupportCode } from 'cucumber';


defineSupportCode(({After, Given, Then, When}) => {

  Given(/^I navigate to application$/, function () {
   loginDriver.navigateByUrl();
  });

});

和protractor.config.ts

    // Protractor configuration file, see link for more information
    // https://github.com/angular/protractor/blob/master/lib/config.ts

    // const { SpecReporter } = require('jasmine-spec-reporter');

    exports.config = {
      allScriptsTimeout: 11000,
      specs: [
        './e2e/features/*.feature'
      ],
      capabilities: {
        browserName: 'chrome',
        chromeOptions: {
          // args: [ "--headless", "--disable-gpu", "--window-size=1980,1080" ]
        }
      },
      directConnect: true,
      baseUrl: 'http://localhost:4200/',
      framework: 'custom',
      frameworkPath: require.resolve('protractor-cucumber-framework'),
      cucumberOpts: {
        require: ["./e2e/features/**/*.steps.js"],
        tags: [],
        strict: true,
        format: ["progress"],
        dryRun: false,
        // compiler: [ 'ts:ts-node']
        compiler: "ts:ts-node/register"

      }
    }

;

这是我的文件夹Structure

enter image description here

我花了5-6个小时才找到解决方案,但我无法通过它

请帮忙,非常感谢

2 个答案:

答案 0 :(得分:0)

这是一个非常简单的问题,您在.ts使用了错误的文件扩展名。应该是.js,而不是require: ["./e2e/features/**/*.steps.ts"],

tar xvfz freetype-2.9.1.tar.gz
cd freetype-2.9.1
sudo apt build-dep libfreetype6
./configure
make
sudo make install
sudo ldconfig

答案 1 :(得分:0)

错误日志本身说,它无法从步骤定义文件中调用所需的步骤,请务必检查以下内容,

i)确保功能文件和步骤定义文件,语句相同(不应该是不必要的空格,大写),

ii)确保您在配置文件中调用确切的文件名

iii)确保文件路径正确。