【问题标题】:Implement Scenario outline in a cucumber-protractor through step definitions and page objects通过步骤定义和页面对象在黄瓜量角器中实现场景大纲
【发布时间】: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


    【解决方案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);
        });
     }
    

    【讨论】:

    • 感谢工作。现在,我收到一个不同的错误,例如“×当我搜索单词 angular # ..\step_definitions\ea_page_steps.js:19 WebDriverError: unknown error: cannot focus element”你认为我需要在点击之间引起等待吗和文字输入?你能分享一个例子吗?
    • 您可以在 sendKeys 之前添加睡眠,但我不确定它是否能解决您的问题。该错误可能由多种原因引起。
    • 试过了。浏览器从不睡觉只是微风就过去了 sleep()
    • 请在您的问题中显示您的量角器 conf.js
    • 添加了 config.js 文件
    猜你喜欢
    • 1970-01-01
    • 2011-04-06
    • 1970-01-01
    • 1970-01-01
    • 2018-07-25
    • 1970-01-01
    • 1970-01-01
    • 2020-07-11
    • 2019-12-15
    相关资源
    最近更新 更多