2

Does anyone know why this step might be showing as "undefined" when I try to run it. below you will see an example where I am trying to experiment with cucumber scenario outline and my "examples:" section has 1 entry. Also, the page objects and step def is enclosed. For some reason when I try to run it , I get an error like this:

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

Here is the feature file

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|

here is the step 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) });

Here are the page objects

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;

Note: I have a universal constructor in the framework and therefore I don't have to import any pages when I write my test. Could someone help me understand what is the wrong with the step 3 that it keeps showing undefined?

using following

"dependencies": { "chai": "4.1.2", "chai-as-promised": "7.1.1", "chakram": "1.5.0", "cucumber": "4.0.0", "cucumber-html-reporter": "3.0.4", "fs": "0.0.2", "path": "0.12.7", "protractor": "5.3.0", "protractor-cucumber-framework": "4.2.0" }

EDITED- to add the 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
    }
  }

});
Monnie_tester
  • 439
  • 1
  • 6
  • 20

1 Answers1

2

Remove the double quote around "([^"]*)" in step definition, there is no quote in feature file.

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);
    });
 }
yong
  • 13,357
  • 1
  • 16
  • 27
  • Thanks that worked. Now, I am getting a different error like " × When I search for the word angular # ..\step_definitions\ea_page_steps.js:19 WebDriverError: unknown error: cannot focus element" do you think I need to induce a wait between the click and text entry? Could you please share an example? – Monnie_tester Apr 15 '18 at 14:20
  • You can add a sleep before sendKeys,but I'm not sure it will fix your problem. The error can be caused by several reason. – yong Apr 16 '18 at 01:33
  • Tried it. Browser never sleeps just breezes right past the sleep() – Monnie_tester Apr 16 '18 at 02:55
  • Please show your protractor conf.js in your question – yong Apr 16 '18 at 06:23
  • added the config.js file – Monnie_tester Apr 20 '18 at 02:35
  • I increase the sleep to 15 seconds and move the `sendKeys` into `browser.sleep().then()`. With such change `sendKeys` must be executed 15 seconds later. If this changes still report same error, please check the element represented by `this.eaautomation` is text box which allowed to input. – yong Apr 20 '18 at 03:11