gpt4 book ai didi

javascript - 通过步骤定义和页面对象在 cucumber Protractor 中实现场景大纲

转载 作者:行者123 更新时间:2023-11-29 23:23:58 27 4
gpt4 key购买 nike

有谁知道为什么当我尝试运行此步骤时它可能显示为“未定义”。下面您将看到一个示例,我正在尝试使用 cucumber 场景大纲进行试验,而我的“示例:”部分有 1 个条目。此外,还包含页面对象和步骤定义。出于某种原因,当我尝试运行它时,出现如下错误:

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”, “ cucumber ”:“4.0.0”, "cucumber-html-reporter": "3.0.4", “FS”:“0.0.2”, “路径”:“0.12.7”, “Protractor ”:“5.3.0”, “Protractor cucumber 框架”:“4.2.0”

已编辑- 添加 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
}
}

});

最佳答案

去掉步骤定义中"([^"]*)"的双引号,特征文件中没有引号。

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

关于javascript - 通过步骤定义和页面对象在 cucumber Protractor 中实现场景大纲,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49838734/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com