获取错误 - 执行量角器黄瓜打字稿功能文件时“未定义。使用以下代码段实现”

时间:2018-06-07 08:30:16

标签: typescript protractor cucumber cucumberjs

我使用量角器打字稿和黄瓜进行自动化 - 我在e2e项目中阅读了一些文章并添加了特征文件和步骤定义 -

功能文件:

功能:主页

  Scenario: Visit Homepage
    Given I am on the homepage
    Then I should see a "navbar"
    And I should see a "login" link
    And I should see a "register" link

步骤定义如下:

var pc = require('protractor-cucumber');    module.exports = steps; var steps = function() {
     this.Given('I am on the homepage', function (callback) {
    support.get(this, 'http://localhost:5000', function(result){
      setTimeout(callback, 1000);
    });   });

      this.Then('I should see a {stringInDoubleQuotes}', function (link, callback) {
    support.findByBinding(this, link, function(result){
      result.getText().then (function(text){
        text.trim().toLowerCase().should.equal(link.trim().toLowerCase());
        setTimeout(callback, 1000);
      });
    });   });
     };

我的Support.ts如下 -

var support = require('../support');
var Support = function(){
};

Support.prototype.get = function(sut, url, callback){
  sut.browser.get(url).then(function(result) {
    callback(result)
  });
};

Support.prototype.findByBinding = function(sut, item, callback){
  sut.browser.findElement(sut.by.binding(item)).then(function(result) {
    callback(result);
  });
};

Support.prototype.isElementPresent = function(sut, find, callback){
  sut.browser.isElementPresent(sut.by.linkText(find)).then(function(result) {
     callback(result)
  });
};

Support.prototype.isElementPresentByClass = function(sut, find, callback){
  sut.browser.isElementPresent(sut.by.css('.'+find)).then(function(result) {
     callback(result)
  });
};

module.exports = new Support();

我的Protractor.conf.js如下 -

exports.config = {
  allScriptsTimeout: 11000,
  autoStartStopServer: true,

  multiCapabilities: [
    {
      browserName: "chrome"
    }
  ],

  directConnect: false,
  baseUrl: "example.com",
  seleniumAddress: "http://localhost:4444/wd/hub",

  framework: "custom",
  frameworkPath: require.resolve("protractor-cucumber-framework"),
  //specs: ["./e2e/**/*.feature"],
  specs: ["./e2e/**/*google.feature"],

  // cucumber command line options
  cucumberOpts: {
    //require: "./e2e/**/*.steps.ts",
    require: "Google.steps.ts",
    tags: [],
    strict: true,
    format: ["pretty"],
    "dry-run": false,
    compiler: []
  },

  onPrepare() {
    browser
      .manage()
      .window()
      .maximize();
  }
};

我的package.json如下 -

{
  "name": "test",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build --extract-css",
    "build:ssr": "npm run build -- --app=ssr --output-hashing=media",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "6.0.0",
    "@angular/common": "6.0.0",
    "@angular/compiler": "6.0.0",
    "@angular/core": "6.0.0",
    "@angular/forms": "6.0.0",
    "@angular/http": "6.0.0",
    "@angular/platform-browser": "6.0.0",
    "@angular/platform-browser-dynamic": "6.0.0",
    "@angular/platform-server": "^2.0.1",
    "@angular/router": "6.0.0",
    "@nguniversal/module-map-ngfactory-loader": "^5.0.0-beta.5",
    "aspnet-prerendering": "^3.0.1",
    "bootstrap": "^3.3.7",
    "browserstack-local": "^1.3.3",
    "core-js": "^2.4.1",
    "cucumber-tsflow": "^2.2.0",
    "domino": "2.0.1",
    "jasmine-bail-fast": "0.0.1",
    "jquery": "^3.3.1",
    "pretty-bytes": "^5.0.0",
    "protractor-jasmine2-screenshot-reporter": "^0.5.0",
    "rxjs": "^6.1.0",
    "zone.js": "^0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.6.0",
    "@angular/cli": "6.0.0",
    "@angular/compiler-cli": "6.0.0",
    "@angular/language-service": "6.0.0",
    "@types/chai": "^4.1.3",
    "@types/chai-as-promised": "^7.1.0",
    "@types/cucumber": "^4.0.4",
    "@types/jasmine": "~2.5.53",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "~6.0.60",
    "chai": "^4.1.2",
    "chai-as-promised": "^7.1.1",
    "codelyzer": "^4.0.1",
    "cucumber": "^2.3.1",
    "grunt-protractor-cucumber-html-report": "^0.2.8",
    "jasmine-core": "~2.6.2",
    "jasmine-spec-reporter": "~4.1.0",
    "karma": "^1.7.1",
    "karma-chrome-launcher": "^2.1.1",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "^1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "multiple-cucumber-html-reporter": "^1.10.1",
    "protractor": "~5.1.2",
    "protractor-cucumber": "^0.1.8",
    "protractor-cucumber-framework": "^3.1.0",
    "protractor-jasmine2-html-reporter": "0.0.7",
    "ts-node": "~3.2.0",
    "tslint": "~5.7.0",
    "typescript": "2.7.2"
  }
}

运行命令Protractor Protractor.conf.js

后出现完全错误
C:\Source\ClientApp>protractor protractor.conf.js
(node:11828) [DEP0022] DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
[13:06:14] I/launcher - Running 1 instances of WebDriver
[13:06:14] I/hosted - Using the selenium server at http://localhost:4444/wd/hub
Feature: Homepage

  Scenario: Visit Homepage
  ? Given I am on the homepage
  ? Then I should see a "navbar"
  ? And I should see a "login" link
  ? And I should see a "register" link

Warnings:

1) Scenario: Visit Homepage - e2e\Feature\google.feature:3
   Step: Given I am on the homepage - e2e\Feature\google.feature:4
   Message:
     Undefined. Implement with the following snippet:

       Given('I am on the homepage', function (callback) {
         // Write code here that turns the phrase above into concrete actions
         callback(null, 'pending');
       });

2) Scenario: Visit Homepage - e2e\Feature\google.feature:3
   Step: Then I should see a "navbar" - e2e\Feature\google.feature:5
   Message:
     Undefined. Implement with the following snippet:

       Then('I should see a {stringInDoubleQuotes}', function (stringInDoubleQuotes, callback) {
         // Write code here that turns the phrase above into concrete actions
         callback(null, 'pending');
       });

3) Scenario: Visit Homepage - e2e\Feature\google.feature:3
   Step: And I should see a "login" link - e2e\Feature\google.feature:6
   Message:
     Undefined. Implement with the following snippet:

       Then('I should see a {stringInDoubleQuotes} link', function (stringInDoubleQuotes, callback) {
         // Write code here that turns the phrase above into concrete actions
         callback(null, 'pending');
       });

4) Scenario: Visit Homepage - e2e\Feature\google.feature:3
   Step: And I should see a "register" link - e2e\Feature\google.feature:7
   Message:
     Undefined. Implement with the following snippet:

       Then('I should see a {stringInDoubleQuotes} link', function (stringInDoubleQuotes, callback) {
         // Write code here that turns the phrase above into concrete actions
         callback(null, 'pending');
       });

1 scenario (1 undefined)
4 steps (4 undefined)
0m00.000s
[13:06:20] I/launcher - 0 instance(s) of WebDriver still running
[13:06:20] I/launcher - chrome #01 failed 1 test(s)
[13:06:20] I/launcher - overall: 1 failed spec(s)
[13:06:20] E/launcher - Process exited with error code 1

3 个答案:

答案 0 :(得分:0)

正如我所说,您使用的是错误的依赖项/版本。您还使用了不再维护的select t.trxid ,m.mid ,row_number() over (partition by t.trxid order by m.mid) as id ,t.data1 ,t.data2 ,m.mname ,m.mdate from @t1 t inner join @m m on(t.trxid = m.trxid)

我刚刚创建了一个可能有帮助的样板,但请记住,版本也没有更新到最新版本的例如Cucumber(仍在CucumberJS 3上)。你可以在https://github.com/wswebcreation/protractor-cucumber-typescript-boilerplate

找到它

答案 1 :(得分:0)

尝试更改此内容

this.Given('I am on the homepage', function (callback)

对此

this.Given(/^I am on the homepage$/, function (callback)

答案 2 :(得分:0)

将此添加到您的黄瓜选择中:

//Your step definition file name require: ["Google.steps.ts", "StepsDefinition.steps.ts"]