nosequeweaponer
nosequeweaponer

Reputation: 668

Protractor - Cucumber - JS - Undefined Steps

I'm facing the next situation with Cucumber in Protractor (With Webstorm)

When I try to run the only feature that I have, it displays the next message (I have already defined the steps in a class)

 Undefined. Implement with the following snippet:

     Given('I open the url {string}', function (string) {
       // Write code here that turns the phrase above into concrete actions
       return 'pending';
     });
...
1 scenario (1 undefined)
4 steps (4 undefined)
0m00.000s

Process finished with exit code 1

This is my config file (conf.js)

exports.config = {

framework: 'custom',
frameworkPath: require.resolve('protractor-cucumber-framework'),
seleniumAddress: 'http://localhost:4444/wd/hub',
baseUrl: 'https://www.afphabitat.cl/portalPrivado_FIXWeb/public/login.htm',
ignoreSynchronization: true,
getPageTimeout: 60000,
allScriptsTimeout: 50000,
defaultTimeoutInterval: 30000,

specs: ['features/*.feature'],
cucumberOpts: {
    compiler: [],
    require: ['step_defs/*.js'],
    dryRun  : false,
    tags: ['@wip'],
    monochrome: true,
    strict: true,
    plugin: "json",
    format: 'json:reports/cucumber-report.json',
    resultJsonOutputFile: 'reports/cucumber-report.json'
},

multiCapabilities:
    [{
        'browserName': 'chrome',
        chromeOptions: {
            binary: process.env.CHROME_BIN,
            args: ['--no-sandbox', '--start-maximized']
        }
    },
        {
            'browserName': 'firefox',
            args: ['--no-sandbox','--start-maximized']
        }],
jasmineNodeOpts: {
    showColors: true,
    defaultTimeoutInterval: 30000,
}
}

Next one is my step definition file (step_defs_Login.js)

import { Given, Then, When } from "cucumber";
import { browser, by, element, } from 'protractor';

    Given('I open the url {string}', function (string) {
        browser.get(string);
        //    callback();
    });

    When('proceed to enter my username as {string}', function (string1) {
        let username = element(by.id('j_username_input')).clear();
        username = element(by.id('j_username_input')).sendKeys(string1);
        //    callback();
    });

    When('proceed to enter my password as {string}', function (string2) {
        let password = element(by.id('j_password')).clear();
        password = element(by.id('j_password')).sendKeys(string2);
        //    callback();
    });

    Then('I have been logged in successfully', function () {
        element(by.id('button')).click();
        //   callback();
    });

Don't forget the JSON File (package.json)

    {
  "name": "package",
  "version": "1.0.0",
  "description": "First Protractor Cucumber project",
  "main": "conf.js",
  "scripts": {
    "test": "cucumberjs"
  },
  "keywords": [
    "TAE"
  ],
  "author": "zzz",
  "license": "ISC",
  "devDependencies": {
    "cucumber": "^5.1.0",
    "selenium-webdriver": "^4.0.0-alpha.5"
  },
  "dependencies": {
    "protractor": "latest"
  }
}

I don't know if this is necessary or not, but this is my Hooks file (hooks.js)

let {defineSupportCode} = require('cucumber');
defineSupportCode (function ({After, Before}){

    Before(function () {
     //   return this.driver.manage().window().maximize()
     return this.browser.manage().window().maximize();
    })

    After(function () {
        return this.driver.quit()
    })

});

I have installed the next ones:

Protractor version 5.4.2 
Node version 10.16.3 
NPM 6.9.0

This is the project structure:

Project Structure

And this is the Run Configurations

Run Configurations

Can anybody please help me with this???

Upvotes: 0

Views: 1140

Answers (3)

Sreenivasulu
Sreenivasulu

Reputation: 514

Looks like you are using Webstrom to work on this cucumber framework. As I know, Webstrom will find the respective step definition for that step automatically. Coming to the issue,

1) Open your feature file and check that particular step is showing as implemented or not 2) Try to replace {string} with regular expression (.*) which will accept any type of data and check same step in feature file- step

Check both above cases

Upvotes: 0

MonkeyTester
MonkeyTester

Reputation: 139

Have you got the string you are passing in the feature file enclosed in "double quotes"?

I open the url "myUrl"

Upvotes: 1

Ray
Ray

Reputation: 1214

Try

require: ['../step_defs/*.js']

or

require: ['./step_defs/*.js']

In cucumberOpts object

Upvotes: 0

Related Questions