带有黄瓜的量角器-场景未被调用

时间:2019-06-30 17:37:40

标签: protractor cucumber cucumberjs

我们是使用量角器的新手,已点击下面的链接尝试进行测试设置。 http://maushamgupta.blogspot.com/2016/09/getting-started-with-protractor-cucumber.html

下面是conf文件(名为protractor.conf.js)。

var config;
config = {

    //chromeDriver:'path\\to\\your\\chromedriver.exe',
    //seleniumArgs: ['-Dwebdriver.ie.driver=path\\to\\your\\IEDriverServer.exe'], //incase you want to test your application on internet explorer
    seleniumAddress: 'http://127.0.0.1:4444/wd/hub',

    specs: 'testwithpro.feature',

    capabilities: {
          browserName: 'chrome'
       },

    framework: 'custom', // need to add for protractor 3.x and above
    frameworkPath: './node_modules/protractor-cucumber-framework',  // need to add for protractor 
    output:'./output.json',                                                                          //3.x and above

    cucumberOpts: {
          // define your step definitions in this file
          require: ['./testwithpro.js'],
          //format: './node_modules/pretty',
          tags:'false'
       }
};

exports.config = config;

testwithpro.feature

功能:测试应用程序

方案:测试登录     鉴于我在登录页面上     当我输入用户名     然后输入密码     然后我单击登录按钮     那我应该看主页

testwithpro.js

var myStepDefinitionsWrapper = function () {

this.Given(/^I am on the login page$/, function (callback) {

  // Write code here that turns the phrase above into concrete actions

  console.log('testing');
  browser.ignoreSynchronization=true; // To be added if the application is non-angular
  browser.driver.manage().window().maximize(); // To maximize the window
  //browser.get("https://www.facebook.com").then(function(){
  //  callback(); // To tell the cucumber that we are done with this step
  //})

            browser.get("https://www.facebook.com");
        browser.wait(function () {
        browser.sleep(10000);
        callback(); // To tell the cucumber that we are done with this step
        }, 20 * 10000);



});

this.When(/^I enter username$/, function (callback) {
  // Write code here that turns the phrase above into concrete actions
element(by.id("email")).sendKeys("abc@gmail.com").then(function(){
  callback();
 });
});

this.When(/^I enter password$/, function (callback) {
  // Write code here that turns the phrase above into concrete actions
  element(by.id("pass")).sendKeys("*****").then(function(){
  callback();
 });
});

this.When(/^I click on login button$/, function (callback) {
  // Write code here that turns the phrase above into concrete actions 
  element(by.id("u_0_l")).click().then(function(){
  callback();
 });
});

};
module.exports = myStepDefinitionsWrapper;

package.json(量角器-黄瓜框架)

"chai": "^4.1.2",
"chai-as-promised": "^7.1.1",
"chai-like": "^0.2.14",
"eslint": "^5.4.0",
"eslint-config-prettier": "^3.0.1",
"eslint-plugin-mocha": "^5.2.0",
"eslint-plugin-prettier": "^2.6.2",
"express": "^4.16.3",
"httpster": "^1.0.4",
"mocha": "^5.2.0",
"multidep": "2.0.2",
"prettier": "^1.14.2",
"protractor": "^5.4.0"

package.json(量角器)

“依赖项”:{     “ @ types / q”:“ ^ 0.0.32”,     “ @ types / selenium-webdriver”:“ ^ 3.0.0”,     “ blocking-proxy”:“ ^ 1.0.0”,     “ browserstack”:“ ^ 1.5.1”,     “ chalk”:“ ^ 1.1.3”,     “ glob”:“ ^ 7.0.3”,     “茉莉花”:“ 2.8.0”,     “ jasminewd2”:“ ^ 2.1.0”,     “乐观主义者”:“〜0.6.0”,     “ q”:“ 1.4.1”,     “ saucelabs”:“ ^ 1.5.0”,     “ selenium-webdriver”:“ 3.6.0”,     “ source-map-support”:“〜0.4.0”,     “ webdriver-js-extender”:“ 2.1.0”,     “ webdriver-manager”:“ ^ 12.0.6”   },   “已弃用”:false,   “ description”:“用于Angular的Webdriver E2E测试包装器”,   “ devDependencies”:{     “ @ types / chalk”:“ ^ 0.4.28”,     “ @ types / glob”:“ ^ 5.0.29”,     “ @ types /茉莉花”:“ ^ 2.5.47”,     “ @ types / jasminewd2”:“ ^ 2.0.0”,     “ @ types / minimatch”:“ ^ 2.0.28”,     “ @ types / minimist”:“ ^ 1.1.28”,     “ @ types / node”:“ ^ 6.0.46”,     “ @ types / optimist”:“ ^ 0.0.29”,     “ body-parser”:“〜1.15.2”,     “ chai”:“〜3.5.0”,     “ chai-as-promise”:“〜5.3.0”,     “ clang-format”:“ 1.0.49”,     “ expect.js”:“〜0.3.1”,     “表达”:“〜4.14.0”,     “ gulp”:“ ^ 3.9.1”,     “ gulp-clang-format”:“ 1.0.23”,     “ gulp-tslint”:“ ^ 7.0.1”,     “ jshint”:“ ^ 2.9.2”,     “ lodash”:“ ^ 4.5.1”,     “已标记”:“ ^ 0.3.3”,     “ mocha”:“ 2.5.3”,     “ rimraf”:“〜2.5.3”,     “ run-sequence”:“ ^ 1.1.5”,     “ semver”:“ ^ 5.3.0”,     “ tslint”:“ ^ 4.1.1”,     “ tslint-eslint-rules”:“ ^ 3.1.0”,     “ typescript”:“ ^ 2.1.5”,     “ vrsource-tslint-rules”:“ ^ 4.0.1”   }

package.json(黄瓜)

“依赖项”:{     “ @ babel / polyfill”:“ ^ 7.2.3”,     “ assertion-error-formatter”:“ ^ 2.0.1”,     “ bluebird”:“ ^ 3.4.1”,     “ cli-table3”:“ ^ 0.5.1”,     “ colors”:“ ^ 1.1.2”,     “ commander”:“ ^ 2.9.0”,     “交叉生成”:“ ^ 6.0.5”,     “ cucumber-expressions”:“ ^ 6.0.0”,     “ cucumber-tag-expressions”:“ ^ 1.1.1”,     “ duration”:“ ^ 0.2.1”,     “ escape-string-regexp”:“ ^ 1.0.5”,     “数字”:“ 2.0.0”,     “ gherkin”:“ ^ 5.0.0”,     “ glob”:“ ^ 7.1.3”,     “ indent-string”:“ ^ 3.1.0”,     “ is-generator”:“ ^ 1.0.2”,     “ is-stream”:“ ^ 1.1.0”,     “ knuth-shuffle-seeded”:“ ^ 1.0.6”,     “ lodash”:“ ^ 4.17.10”,     “ mz”:“ ^ 2.4.0”,     “ progress”:“ ^ 2.0.0”,     “ resolve”:“ ^ 1.3.3”,     “ serialize-error”:“ ^ 3.0.0”,     “ stack-chain”:“ ^ 2.0.0”,     “ stacktrace-js”:“ ^ 2.0.0”,     “ string-argv”:“ 0.1.1”,     “ title-case”:“ ^ 2.1.1”,     “ util-arity”:“ ^ 1.0.2”,     “ verror”:“ ^ 1.9.0”   },   “已弃用”:false,   “ description”:“ Cucumber的官方JavaScript实现。”,   “ devDependencies”:{     “ @ babel / cli”:“ ^ 7.2.3”,     “ @ babel / core”:“ ^ 7.2.2”,     “ @ babel / plugin-proposal-function-bind”:“ ^ 7.2.0”,     “ @ babel / preset-env”:“ ^ 7.2.3”,     “ @ babel / register”:“ ^ 7.0.0”,     “ ansi-html”:“ ^ 0.0.7”,     “ babel-eslint”:“ ^ 10.0.1”,     “ babel-plugin-istanbul”:“ ^ 5.1.0”,     “ babelify”:“ ^ 10.0.0”,     “ browserify”:“ 16.2.2”,     “ chai”:“ ^ 4.0.1”,     “ coffee-script”:“ ^ 1.10.0”,     “ connect”:“ ^ 3.4.0”,     “ coveralls”:“ ^ 3.0.0”,     “ dependency-lint”:“ ^ 5.0.1”,     “ eslint”:“ ^ 5.10.0”,     “ eslint-config-prettier”:“ ^ 3.3.0”,     “ eslint-config-standard”:“ ^ 12.0.0”,     “ eslint-plugin-babel”:“ ^ 5.3.0”,     “ eslint-plugin-import”:“ ^ 2.14.0”,     “ eslint-plugin-node”:“ ^ 8.0.0”,     “ eslint-plugin-prettier”:“ ^ 3.0.0”,     “ eslint-plugin-promise”:“ ^ 4.0.1”,     “ eslint-plugin-standard”:“ ^ 4.0.0”,     “ fs-extra”:“ ^ 6.0.1”,     “ mocha”:“ ^ 5.2.0”,     “小胡子”:“ ^ 2.3.0”,     “ nyc”:“ ^ 12.0.2”,     “更漂亮”:“ ^ 1.5.2”,     “ serve-static”:“ ^ 1.10.0”,     “ sinon”:“ ^ 6.0.0”,     “ sinon-chai”:“ ^ 3.2.0”,     “流到字符串”:“ ^ 1.1.0”,     “ tmp”:“ ^ 0.0.33”   }

当我们运行cmd“ protractor protractor.conf.js”时,终端显示的输出是这个-

[23:02:58] I /启动器-运行1个WebDriver实例 [23:02:58]我/已托管-使用http://127.0.0.1:4444/wd/hub上的硒服务器

0个场景 0步 0分00.000秒 [23:03:02] I /启动器-0个WebDriver实例仍在运行 [23:03:02] I /启动器-chrome#01通过了

它不处理功能部件文件中的方案,并且不启动测试定义js文件中定义的网页。奇怪的是,即使我们将specs文件名更改为“ 1testwithpro.feature”(也不存在),也会显示相同的输出。没有错误。

请让我们知道我们可能做错了什么。感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

specs: 'testwithpro.feature'更改为specs: ['./testwithpro.feature']

删除tags对象中的cucumberOpts

    cucumberOpts: {
      require: ['./testwithpro.js']
   },
   specs: ['./testwithpro.feature']