【发布时间】:2018-04-15 05:18:21
【问题描述】:
有谁知道为什么当我尝试运行此步骤时可能会显示为“未定义”。下面您将看到一个示例,我正在尝试使用黄瓜场景大纲进行试验,而我的“示例:”部分有 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|
这里是步骤定义:
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 步一直显示未定义的问题吗?
使用关注
“依赖”:{ “柴”:“4.1.2”, "chai-as-promised": "7.1.1", “脉轮”:“1.5.0”, “黄瓜”:“4.0.0”, “黄瓜-html-reporter”:“3.0.4”, “fs”:“0.0.2”, “路径”:“0.12.7”, “量角器”:“5.3.0”, “量角器黄瓜框架”:“4.2.0” }
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
}
}
});
【问题讨论】:
标签: javascript angular protractor cucumber scenarios