我有角度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