我有角度2应用程序。我写了基本的黄瓜测试。我已添加功能和步骤定义文件。我不明白为什么它不能读取步骤定义文件,即使我已明确定义它。当我尝试执行黄瓜测试,我得到这个错误信息:黄瓜 - 无法执行步骤定义文件
版本:量角器 - 5.1.2,节点-7.5,NPM -4.1.2,黄瓜-2.3.1, 量角器黄瓜-framewrok - 3.1.2
下面是示例代码:
//cucumber.conf.js
exports.config = {
framework: 'custom',
frameworkPath: require.resolve('protractor-cucumber-framework'),
//seleniumAddress: 'http://localhost:4444/wd/hub',
directConnect: true,
specs: ['test/e2e/cucumber/sample.feature'],
capabilities: {
'browserName': 'chrome',
chromeOptions: {
args: [
//"--headless",
"--disable-gpu",
'--disable-extensions',
'--no-sandbox',
'--disable-web-security'
],
},
},
baseUrl: 'http://localhost:8080/dashboard/#/',
useAllAngular2AppRoots: true,
// cucumber command line options
cucumberOpts: {
require: ['test/e2e/cucumber/menu.steps.js'],
tags: [],
strict: true,
format: ["pretty"],
dryRun: false,
compiler: []
},
onPrepare: function() {
browser.manage().window().maximize();
},
resultJsonOutputFile: './test/e2e/results.json'
}
/**
//test/e2e/cucumber/sample.feature
Feature: The Dashboard has 2 views, Main view and Status view
Scenario: I want to have 2 tabs with Displayed text "Main View"
and "Status View"
on the homepage
Given I go to Dashboard homepage
When I click on the Main view
Then the main view page is displayed
When I click on the Status view
Then the status view page is displayed
*/
//test/e2e/cucumber/menu.steps.js
var chai = require('chai');
var chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
var expect = chai.expect;
browser.ignoreSynchronization = true;
module.exports = function() {
this.Given(/^I go to Dashboard homepage$/, {
timeout: 100 * 1000
}, function() {
return browser.get('http://localhost:8080/dashboard/#/');
// browser.waitForAngular();
});
this.When(/^I click on the Main view$/, {
timeout: 100 * 1000
}, function() {
element(by.css('[href="#/mainView"]')).click();
});
this.Then(/^the main view page is displayed$/, function() {
return browser.getCurrentUrl().then(function(url) {
console.log("URL= " + url);
});
this.When(/^I click on the Status view$/, {
timeout: 100 * 1000
}, function() {
element(by.css('[href="#/statusView"]')).click();
});
this.Then(/^the status view page is displayed$/, function() {
return browser.getCurrentUrl().then(function(url) {
console.log("URL= " + url);
});
});
}
谢谢。是的,黄瓜版本是不同的。现在我降级到1.3.3,它工作。我添加了'browser.ignoreSynchronization = true;'以避免超时问题。这使得Protractor不会等待Angular promise,例如$ http或$ timeout中的那些promise。 (https://stackoverflow.com/questions/44672875/scripttimeouterror-timed-out-from-task-protractor-waitforangular) – Mythri