Selenium 黄瓜+;量角器-执行步骤时发生超时错误
我正在使用cucumber和Digrator编写行为驱动测试。我的场景和所有步骤都会通过,但最后会显示超时错误。主页将在第一步加载,之后不会执行步骤定义文件中描述的任何步骤。加载页面后,应单击选项卡。我在步骤定义文件中提到了这些步骤,但这些步骤并没有执行,它将显示控制台中传递的所有步骤。我跟随这个链接以供参考 这是错误消息 请在下面找到示例代码Selenium 黄瓜+;量角器-执行步骤时发生超时错误,selenium,protractor,cucumber,chai,Selenium,Protractor,Cucumber,Chai,我正在使用cucumber和Digrator编写行为驱动测试。我的场景和所有步骤都会通过,但最后会显示超时错误。主页将在第一步加载,之后不会执行步骤定义文件中描述的任何步骤。加载页面后,应单击选项卡。我在步骤定义文件中提到了这些步骤,但这些步骤并没有执行,它将显示控制台中传递的所有步骤。我跟随这个链接以供参考 这是错误消息 请在下面找到示例代码 //sample.feature Feature: The Dashboard has 2 tabs, Statistics and Results
//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'
}
//sample.feature
功能:仪表板有两个选项卡,统计信息和结果
场景:我想在主页上有两个显示文本“统计”和“结果”的选项卡
假设我进入仪表板主页
我点击“#/results”
然后显示结果页面
然后单击“#/Statistics”选项卡
然后显示统计信息页面
//menu.steps.js
var chai=需要(“chai”);
var ChaiasPromisted=require('chai-as-promisted');
柴。使用(柴);
var expect=chai.expect;
module.exports=函数(){
给定(/^I转到仪表板主页$/,函数(){
browser.get('http://localhost:8100/#/');
browser.waitForAngular();
});
然后(/^我单击“([^”]*)”$/,函数(arg1){
元素(by.css('[href=“#/results”]')。单击();
});
然后(/^结果页显示为$/,()=>{
browser.get('http://localhost:8100/#/results');
});
当(/^)我单击“([^”]*)”选项卡$/”时,函数(arg1){
元素(by.css('[href=“#/statistics”]')。单击();
});
然后(/^将显示统计信息页$/,()=>{
browser.get('http://localhost:8100/#/statistics');
});
//cucumber.conf.js
exports.config={
framework:'custom',//设置为“custom”,而不是cumber。
frameworkPath:require.resolve('dragrator-cumber-framework'),
赛琳娜的裙子:'http://localhost:4444/wd/hub',
规格:['test/e2e/cumber/*.feature'],
能力:{
'browserName':'firefox',
},
baseUrl:'http://localhost:8100/#/',
//cumber命令行选项
黄瓜:{
require:['test/e2e/cucumber/*.steps.js'],//在执行功能之前需要步骤定义文件
标记:[],//(表达式)仅使用与表达式匹配的标记执行功能或场景
strict:true,//如果有任何未定义或挂起的步骤,则失败
格式:[“pretty”],/(键入[:path])指定输出格式,可以选择提供重定向格式化程序输出的路径(可重复)
dryRun:false,//在不执行步骤的情况下调用格式化程序
编译器:[]/(“扩展名:模块”)在需要模块(可重复)后需要具有给定扩展名的文件
},
onPrepare:function(){
browser.manage().window().maximize();//在执行要素文件之前最大化浏览器
},
resultJsonOutputFile:“./test/e2e/results.json”
}
如果您使用的是CucumberJS,您可以选择使用回调或承诺。在您的代码中,您没有使用其中的一个。下面,您将找到如何使用承诺和回调的步骤示例
请注意,如果您实现了这两个解决方案中的一个,您的测试仍然可能失败,但这更多地与测试实现有关,而不是与回调/承诺解决方案有关
//有承诺
module.exports=函数(){
给定(/^I转到仪表板主页$/,函数(){
browser.get('http://localhost:8100/#/');
返回browser.waitForAngular();
});
然后(/^我单击“([^”]*)”$/,函数(arg1){
返回元素(by.css('[href=“#/results”]')。单击();
});
然后(/^结果页显示为$/,()=>{
返回browser.get('http://localhost:8100/#/results');
});
当(/^)我单击“([^”]*)”选项卡$/”时,函数(arg1){
返回元素(by.css('[href=“#/statistics”]')。单击();
});
然后(/^将显示统计信息页面$/,()=>{
返回browser.get('http://localhost:8100/#/statistics');
});
}
//回拨
module.exports=函数(){
此。给定(/^I转到仪表板主页$/,函数(完成){
browser.get('http://localhost:8100/#/');
browser.waitForAngular().then(完成);
});
然后(/^I单击“([^”]*)”$/,函数(arg1,完成){
元素(按.css('[href=“#/results”]')。单击(),然后单击(完成);
});
然后(/^结果页显示$/,(完成)=>{
browser.get('http://localhost:8100/#/results)。然后(完成);
});
当(/^I单击“([^”]*)”选项卡$/”时,函数(arg1,完成){
元素(按.css('[href=“#/statistics”]')。单击(),然后单击(完成);
});
然后(/^将显示统计信息页面$/,(完成)=>{
browser.get('http://localhost:8100/#/statistics)。然后(完成);
});
}
如果您使用的是CucumberJS,您可以选择使用回调或承诺。在您的代码中,您没有使用其中的一个。下面,您将找到如何使用承诺和回调的步骤示例
请注意,如果您实现了这两个解决方案中的一个,您的测试仍然可能失败,但这更多地与测试实现有关,而不是与回调/承诺解决方案有关
//有承诺
module.exports=函数(){
给定(/^I转到仪表板主页$/,函数(){
browser.get('http://localhost:8100/#/');
返回browser.waitForAngular();
});
然后(/^我单击“([^”]*)”$/,函数(arg1){
返回元素(by.css('[href=“#/results”]')。单击();
});
然后(/^结果页显示为$/,()=>{
返回browser.get('http://localhost:8100/#/results');
});
当(/^)我单击“([^”]*)”选项卡$/”时,函数(arg1){
返回元素