我正在进行角度2应用。我写了基本的黄瓜测试。我添加了功能和步骤definiton file.I不明白为什么它无法读取步骤定义文件,即使我已经明确定义它。当我尝试执行黄瓜测试时,我收到此错误消息:
版本:量角器 - 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);
});
});
}
答案 0 :(得分:0)
如果您使用的是CucumberJS 2,则需要使用不同的方式编写步骤,有关详细信息,请参阅here。
示例:强>
// features/step_definitions/file_steps.js
var {
defineSupportCode
} = require('cucumber');
defineSupportCode(function({Given}) {
Given(/^I need to rewrite my steps$/, function() {
return Promise.resolve('pending');
});
});
其次要注意这个不起作用的事实,你将browser.ignoreSynchronization = true;
放在文件的顶部。当量角器读取文件时,浏览器尚未启动,因此它将很难失败。
如果您需要测试非角度页面,请将browser.ignoreSynchronization = true;
放在onPrepare()
的配置文件中。
答案 1 :(得分:0)
根据我的经验,功能文件对格式非常敏感。就像一个yml文件一样,我因为标签和空格而没有运行步骤,所以我也会检查它。