通过步骤定义和页面对象在黄瓜量角器中实现方案大纲



>有谁知道为什么当我尝试运行此步骤时可能会显示为"未定义"。 下面您将看到一个示例,我正在尝试尝试黄瓜场景大纲,我的"示例:"部分有 1 个条目。此外,还附有页面对象和步骤 def。由于某种原因,当我尝试运行它时,我收到这样的错误:

1) Scenario: Verify user can search # ..featuresautomationregressionsamplezz.feature:13
√ Before # ..supportworld.js:21
√ Given I navigate to the ea site # ..step_definitionsea_page_steps.js:4
√ Then I click on the search icon # ..step_definitionsea_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", "柴如承诺": "7.1.1", "查克拉姆": "1.5.0", "黄瓜": "4.0.0", "Cucumber-html-reporter": "3.0.4", "fs": "0.0.2", "路径": "0.12.7", "量角器": "5.3.0", "量角器-黄瓜框架":"4.2.0" }

已编辑 - 以添加配置.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
}
}
});

删除步骤定义中"([^"]*)"两边的双引号,功能文件中没有引号。

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);
});
}

最新更新