有谁知道为什么这个步骤可能会显示为" undefined"当我试图运行它。下面你将看到一个例子,我试图尝试黄瓜场景大纲和我的"例子:"部分有1个条目。此外,还包含页面对象和步骤def。出于某种原因,当我尝试运行它时,我收到如下错误:
1) Scenario: Verify user can search # ..\features\automation\regression\samplezz.feature:13
√ Before # ..\support\world.js:21
√ Given I navigate to the ea site # ..\step_definitions\ea_page_steps.js:4
√ Then I click on the search icon # ..\step_definitions\ea_page_steps.js:8
? When I search for the word angular
Undefined. Implement with the following snippet:
When('I search for the word angular', function (callback) {
// Write code here that turns the phrase above into concrete actions
callback(null, 'pending');
});
这是功能文件
Feature: sampleZZ
The purpose of this feature file is to navigate to the eaAutomationa site
Scenario Outline: Verify user can search
Given I navigate to the ea site
Then I click on the search icon
When I search for the word <word>
Examples:
|word|
|angular|
这是步骤def:
let {Given, Then, When} = require('cucumber');
Given(/^I navigate to the ea site$/, function(){
return browser.get(this.url.ud); });
Then(/^I click on the search icon$/, function(){
return this.pages.udPage.click_Search();
});
When(/^I search for the word "([^"]*)" $/, function(word){
return this.pages.udPage.enter_SearchText(word) });
以下是页面对象
class UDPage extends require('../base_page.js') { constructor() {
super();
this.eaautomation = by.css('#new_searchicon > i');
this.eaLogo = by.css('//#header_logo'); }; click_Search() {
return element(this.eaautomation).click(); }
enter_SearchText(text){
return element(this.eaautomation).sendKeys(text); }
} module.exports = UDPage;
注意:我在框架中有一个通用构造函数,因此在编写测试时我不必导入任何页面。 有人可以帮我理解第3步有什么不对,它一直显示未定义吗?
使用以下
&#34;依赖&#34;:{ &#34; chai&#34;:&#34; 4.1.2&#34;, &#34; chai-as-promised&#34;:&#34; 7.1.1&#34;, &#34; chakram&#34;:&#34; 1.5.0&#34;, &#34;黄瓜&#34;:&#34; 4.0.0&#34;, &#34; cucumber-html-reporter&#34;:&#34; 3.0.4&#34;, &#34; fs&#34;:&#34; 0.0.2&#34;, &#34;路径&#34;:&#34; 0.12.7&#34;, &#34;量角器&#34;:&#34; 5.3.0&#34;, &#34;量角器 - 黄瓜 - 框架&#34;:&#34; 4.2.0&#34; }
EDITED-添加config.js
let path = require('path'),
environment = require('./environment');
exports.config = Object.assign({}, environment, {
seleniumAddress: 'http://localhost:4444/wd/hub', // 'http://localhost:4444/wd/hub' to run locally
capabilities: {
"browserName": "chrome",
"shardTestFiles": true,
"maxInstances": 1,
"ignoreProtectedModeSettings": true
},
specs:[
'../features/automation/regression/sample2.feature',
],
params: {
environment: 'qa1', // dit, qa4, or qa1
platform: 'browser', // browser or mobile
path: {
page_objects: path.resolve(__dirname + '/../page_objects'), // Default directory for the page objects
page_factory: path.resolve(__dirname + '/../page_objects/page_factory.js'), // Default page factory location
projectRoot: path.resolve(__dirname + '/../') // Default root for the automation
}
}
});
答案 0 :(得分:1)
在步骤定义中删除"([^"]*)"
周围的双引号,功能文件中没有引号。
When(/^I search for the word ([^"]*)$/, function(word){});
enter_SearchText(text) {
var me = this;
// wait 15 seconds
return browser.sleep(15*1000).then(function(){
return element(me.eaautomation).sendKeys(text);
});
}