黄瓜+量角器-执行步骤时超时错误 [英] Cucumber + Protractor - timed out error while executing the steps

查看:84
本文介绍了黄瓜+量角器-执行步骤时超时错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用黄瓜和量角器编写行为驱动的测试。我的场景和所有步骤都可以通过,但最后会显示超时错误。主页将首先加载,以后将不执行步骤定义文件中描述的任何步骤。页面加载后,应单击选项卡。我已经在步骤定义文件中提到了这些步骤,但是这些步骤没有执行,它将显示在控制台中传递的所有步骤。我点击了此链接以供参考



请在下面找到示例代码。

  // sample.feature 
功能:仪表板有2个选项卡,即统计和结果

方案:我想在主页上有2个选项卡,其中显示文本统计和结果

鉴于我要进入仪表板主页
,然后单击#/结果
然后显示结果页面
,然后单击#/统计选项卡
然后显示统计信息页面

//menu.steps。 js
var chai = require('chai');
var chaiAsPromised = require(‘chai-as-promised’);

chai.use(chaiAsPromised);
var Expect = chai.expect;

module.exports = function(){
this.Given(/ ^我去仪表板主页$ /,function(){
browser.get('http:/ / localhost:8100 /#/');
browser.waitForAngular();
});

this.Then(/ ^我单击([[^] *) $ /,function(arg1){
element(by.css('[href = #/ results]'))。click();
});

this.Then(/ ^显示结果页面$ /,()=> {
browser.get('http:// localhost:8100 /#/ results');
});
this.When(/ ^我点击([^] *) tab $ /,function(arg1){
element(by.css('[href =#/ statistics]'))。click();
});


这。然后(/ ^显示统计信息页面$ /,()=> {
browser.get('http:// localhost:8100 /# / statistics');
});

//cucumber.conf.js
exports.config = {
框架: custom,//设置为 custom,而不是黄瓜。
frameworkPath:require.resolve('protractor-cucumber-framework'),
seleniumAddress:'http:// localhost:4444 / wd / hub',
specs:['test / e2e /cucumber/*.feature'],
功能:{
'browserName':'firefox',

},
baseUrl:'http:// localhost :8100 /#/',


//黄瓜命令行选项
黄瓜选项:{
要求:['test / e2e / cucumber / *。steps。 js'],//在执行功能
标记之前需要步骤定义文件:[],//< string []> (表达式)仅使用与表达式
strict匹配的标签执行功能或场景:true,//< boolean>如果存在任何未定义或待处理的步骤
格式,则失败:[ pretty],//< string []> (type [:path])指定输出格式,可以选择提供PATH来重定向格式化程序输出(可重复)
dryRun:false,//< boolean>调用格式化程序而不执行步骤
编译器:[] //< string []> ( extension:module)在需要MODULE(可重复)
},

onPrepare之后需要具有给定扩展名的文件:function(){
browser.manage()。window ()。最大化(); //在执行功能文件
},

resultJsonOutputFile:'./test/e2e/results.json'
}


解决方案

如果使用的是CucumberJS,则可以选择使用回调承诺。在您的代码中,您没有使用其中之一。在下面,您将找到一个示例示例,说明如何使用承诺,回调。



请注意,如果您实施两种解决方案之一,您的测试可能仍然会失败,但这与测试实现有关,而不是与回调/承诺的解决方案有关



  //使用promisesmodule.exports = function(){this.Given(/ ^我去仪表板主页$ /,function(){browser.get('http:// localhost:8100 /#/');返回browser.waitForAngular();});这。然后(/ ^我单击([[^] *) $ /,function(arg1){return element(by.css('[href =#/ results]')))。click( );}); this.Then(/ ^将显示结果页面$ /,()=> {return browser.get('http:// localhost:8100 /#/ results');}); this。当(/ ^我点击([^] *)标签$ /时,函数(arg1){返回元素(by.css('[href =#/ statistics]'))。click() ;});然后(/ ^显示统计信息页面$ /,()=> {return browser.get('http:// localhost:8100 /#/ statistics');});} //使用callbacksmodule.exports = function(){this.Given(/ ^我进入仪表板首页$ /,function(done){browser.get('http:// localhost:8100 /#/'); browser.waitForAngular()。then(完成);});然后。(/ ^我单击([^^] *) $ /,function(arg1,done){element(by.css('[href =#/ results]'))。click ().then(done);}); this.Then(/ ^结果页面显示$ /,(done)=> {browser.get('http:// localhost:8100 /#/ results') .then(done);}); this.When(/ ^我点击([^^]] *)标签$ /,function(arg1,done){element(by.css('[href = #/ statistics]'))。click()。then(done);});然后(/ ^显示统计页面$ /,(done)=> {browser.get('http:// localhost:8100 /#/ statistics').then(done);});}  


I am using cucumber and protractor to write behavioural driven tests.My scenarios and all the steps will pass but at the end it will show timed out error. The homepage will get loaded for the first step and later it will not perform any steps described in the steps definition file. Once the page is loaded it should click on the tabs. I have mentioned these steps in step definition file.But these steps are not executed and it will show all the steps passed in the console. I followed this link for reference https://semaphoreci.com/community/tutorials/getting-started-with-protractor-and-cucumber

This is the error message

Please find the sample code below.

//sample.feature
Feature: The Dashboard has 2 tabs, Statistics and Results 

Scenario: I  want to have 2 tabs with Displayed text "Statistics" and "Results" on the homepage 

Given I go to Dashboard homepage
And I click on the "#/results" 
Then the Results page is displayed
And I click on the "#/Statistics" tab
Then the Statistics page is displayed

//menu.steps.js
var chai = require('chai');
var chaiAsPromised = require('chai-as-promised');

chai.use(chaiAsPromised);
var expect = chai.expect;

module.exports = function() {
  this.Given(/^I go to Dashboard homepage$/, function() {
  browser.get('http://localhost:8100/#/');
  browser.waitForAngular();
  });

    this.Then(/^I click on the "([^"]*)"$/,function(arg1){
    element(by.css('[href="#/results"]')).click();    
   });

    this.Then(/^the results page is displayed$/, () => {
    browser.get('http://localhost:8100/#/results'); 
});
    this.When(/^I click on the "([^"]*)" tab$/, function(arg1) {
    element(by.css('[href="#/statistics"]')).click();     
    });


    this.Then(/^the statistics page is displayed$/,  () =>{         
    browser.get('http://localhost:8100/#/statistics');  
    });

//cucumber.conf.js
exports.config = {
  framework: 'custom',  // set to "custom" instead of cucumber.
  frameworkPath: require.resolve('protractor-cucumber-framework'), 
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: ['test/e2e/cucumber/*.feature'],
  capabilities: {
    'browserName': 'firefox',

},
baseUrl: 'http://localhost:8100/#/',


   // cucumber command line options
  cucumberOpts: {
    require: ['test/e2e/cucumber/*.steps.js'],  // require step definition files before executing features
    tags: [],                      // <string[]> (expression) only execute the features or scenarios with tags matching the expression
    strict: true,                  // <boolean> fail if there are any undefined or pending steps
    format: ["pretty"],            // <string[]> (type[:path]) specify the output format, optionally supply PATH to redirect formatter output (repeatable)
    dryRun: false,                 // <boolean> invoke formatters without executing steps
    compiler: []                   // <string[]> ("extension:module") require files with the given EXTENSION after requiring MODULE (repeatable)
  },

 onPrepare: function () {
    browser.manage().window().maximize(); // maximize the browser before executing the feature files
  },

  resultJsonOutputFile: './test/e2e/results.json'
}

解决方案

If you are using CucumberJS, you can choose to use callbacks or promises. In your code, you didn't use one of them. Below, you will find an example of your steps how you can use promises, of callbacks.

Be aware of the fact that you if you implement one of the 2 solutions, your tests could still fail, but that has more to do with the test implementation instead of the solution for callbacks / promises

// With promises
module.exports = function() {
  this.Given(/^I go to Dashboard homepage$/, function() {
    browser.get('http://localhost:8100/#/');
    return browser.waitForAngular();
  });

  this.Then(/^I click on the "([^"]*)"$/, function(arg1) {
    return element(by.css('[href="#/results"]')).click();
  });

  this.Then(/^the results page is displayed$/, () => {
    return browser.get('http://localhost:8100/#/results');
  });
  this.When(/^I click on the "([^"]*)" tab$/, function(arg1) {
    return element(by.css('[href="#/statistics"]')).click();
  });

  this.Then(/^the statistics page is displayed$/, () => {
    return browser.get('http://localhost:8100/#/statistics');
  });
}

// With callbacks
module.exports = function() {
  this.Given(/^I go to Dashboard homepage$/, function(done) {
    browser.get('http://localhost:8100/#/');
    browser.waitForAngular().then(done);
  });

  this.Then(/^I click on the "([^"]*)"$/, function(arg1, done) {
    element(by.css('[href="#/results"]')).click().then(done);
  });

  this.Then(/^the results page is displayed$/, (done) => {
    browser.get('http://localhost:8100/#/results').then(done);
  });
  this.When(/^I click on the "([^"]*)" tab$/, function(arg1, done) {
    element(by.css('[href="#/statistics"]')).click().then(done);
  });

  this.Then(/^the statistics page is displayed$/, (done) => {
    browser.get('http://localhost:8100/#/statistics').then(done);
  });
}

这篇关于黄瓜+量角器-执行步骤时超时错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆