Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protractor-Cucumber.js throwing undefined snippet error while running feature file #1070

Closed
dixitgargi opened this issue Apr 17, 2018 · 9 comments

Comments

@dixitgargi
Copy link

PFB Details:
"cucumber": "^4.2.1",
"protractor": "^5.3.1",
"chai": "^4.1.2",
"chai-as-promised": "^7.1.1",
"protractor-cucumber-framework": "^4.2.0",

Node 9.10.0
NPM 5.6.0

config.js file:
// conf.js
exports.config = {
framework: 'custom',
seleniumAddress: 'http://localhost:4444/wd/hub',
frameworkPath: require.resolve('protractor-cucumber-framework'),
ignoreUncaughtExceptions: true,
specs: [
'test/features/*.feature' // accepts a glob
],
cucumberOpts: {
timeout: '10000',
// require step definitions
require: [
'test/features/step_definitions/.*steps.js' // accepts a glob
],
tags:['@test5'],
strict: true, // fail if there are any undefined or pending steps
'dry-run': true, // invoke formatters without executing steps
compiler: []
},
// rootElement: 'div#nested_ngcontent',
useAllAngular2AppRoots: true,
capabilities: {
'browserName': 'chrome'
},
chromeOnly: true,
}

FeatureFile:
@test5
Feature: Login to WebApp
Scenario Outline: Login
Given I launch
Then I enter
Examples:
| myvar | textabc |
| https://www.google.com | google |

Page.js(where method is implimented):

'use strict'

const googleP = require('../../test/screens/googleScreen');

class googlename {
constructor() {

};
entertext(textabc) {
    var google = new googleP;
    google.txt_search.sendkeys(textabc);
}

}

module.exports = googlename;

Screen.js(where locators are defined):

'use strict'

// import { element, By } from "protractor";

class google {
constructor() {
this.txt_search = element(by.id('q'));
}
}

module.exports = google

step.js:
'use strict'
const { Before, Given, Then } = require('cucumber');
var {defineSupportCode} = require('cucumber');
var {setDefaultTimeout} = require('cucumber');
const chai = require('chai');
const {expect} = require('chai');
const assert = require('assert');
const googlePage = require('../../pages/googlePage');
browser.ignoreSynchronization=true;
Before({timeout: 60 * 1000}, function() {
setDefaultTimeout(60 * 1000);
});

Given(/^I launch .* $/, function(myvar) {
return browser.get(myvar);
});

Then(/^I enter (.*)$/, function(textabc) {
const google = new googlePage();
return google.entertext(textabc);
});

while executing feature file with above step definition I am getting below error:

protractor Conf.js

(node:2332) [DEP0022] DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
[13:14:42] I/launcher - Running 1 instances of WebDriver
[13:14:42] I/hosted - Using the selenium server at http://localhost:4444/wd/hub

  1. Scenario: Login # test\features\google.feature:8

    • Before # test\features\step_definitions\googlesteps.js:12
      ? Given I launch https://www.google.com
      Undefined. Implement with the following snippet:

      Given('I launch https://www.google.com', function () {
        // Write code here that turns the phrase above into concrete actions
        return 'pending';
      });
      

    ? Then I enter google
    Undefined. Implement with the following snippet:

      Then('I enter google', function () {
        // Write code here that turns the phrase above into concrete actions
        return 'pending';
      });
    

2/2 steps [=================================================================================================================================] 1 scenario (1 undefined)
2 steps (2 undefined)
0m00.000s
[13:14:46] I/launcher - 0 instance(s) of WebDriver still running
[13:14:46] I/launcher - chrome #1 failed 1 test(s)
[13:14:46] I/launcher - overall: 1 failed spec(s)
[13:14:46] E/launcher - Process exited with error code 1
npm ERR! Test failed. See above for more details.

b) step.js

'use strict'
const { Before, Given, Then } = require('cucumber');
var {defineSupportCode} = require('cucumber');
var {setDefaultTimeout} = require('cucumber');
const chai = require('chai');
const {expect} = require('chai');
const assert = require('assert');
const googlePage = require('../../pages/googlePage');
browser.ignoreSynchronization=true;

Before({timeout: 60 * 1000}, function() {
setDefaultTimeout(60 * 1000);
});
Given('I launch {string}', function(myvar) {
browser.get(myvar);
return true;
});
Then('I enter {string}', function(textabc) {
const google = new googlePage();
return google.entertext(textabc);
});

while running above step.js I am facing below error:

protractor Conf.js

(node:14528) [DEP0022] DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
[12:53:01] I/launcher - Running 1 instances of WebDriver
[12:53:01] I/hosted - Using the selenium server at http://localhost:4444/wd/hub
1 scenario (1 skipped)
2 steps (2 skipped)
0m00.000s
[12:53:04] I/launcher - 0 instance(s) of WebDriver still running
[12:53:04] I/launcher - chrome #1 passed

Please help me to understand what exactly is going wrong in my code and help me to solve it

@charlierudolph
Copy link
Member

In the future, please post on the protractor-cucumber-framework repo first and only post here once determined it is a cucumber issue. Also please use syntax highlighting with code blocks (I added some to the original post) and ensure your pasted code is formatted nicely so it is easy to read.

For the first steps.js, the regexp for I launch has a space at the end so I wouldn't expect that to match but the I enter one looks correct. Your glob in the protractor config looks wrong to me as I think:
test/features/step_definitions/.*steps.js should be test/features/step_definitions/*steps.js.

I'm not sure whats going on with the second steps.js.

@dixitgargi
Copy link
Author

I will make sure of your suggestions.
however I have updated file as:
step.js:

Given(/^I launch "(.*)"$/, function (myvar) {
browser.get(myvar);
});

Then(/^I enter "(.*)"$/, function(textabc) {
const google = new googlePage();
return google.entertext(textabc);
});

and updated glob in protractor config.js file as per your suggestions but I am still getting below issue:

protractor Conf.js

(node:1860) [DEP0022] DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
[21:01:45] I/launcher - Running 1 instances of WebDriver
[21:01:45] I/hosted - Using the selenium server at http://localhost:4444/wd/hub

  1. Scenario: Login # test\features\google.feature:8

    • Before # test\features\step_definitions\googlesteps.js:10
      ? Given I launch https://www.google.com
      Undefined. Implement with the following snippet:

      Given('I launch https://www.google.com', function () {
        // Write code here that turns the phrase above into concrete actions
        return 'pending';
      });
      

    ? Then I enter google
    Undefined. Implement with the following snippet:

      Then('I enter google', function () {
        // Write code here that turns the phrase above into concrete actions
        return 'pending';
      });
    

2/2 steps [=================================================================================================================================] 1 scenario (1 undefined)
2 steps (2 undefined)
0m00.000s
[21:01:50] I/launcher - 0 instance(s) of WebDriver still running
[21:01:50] I/launcher - chrome #1 failed 1 test(s)
[21:01:50] I/launcher - overall: 1 failed spec(s)
[21:01:50] E/launcher - Process exited with error code 1
npm ERR! Test failed. See above for more details.

@charlierudolph
Copy link
Member

Those steps won't match as the step definition has quotes around the url and search query while the text in the feature file does not have text

@dixitgargi
Copy link
Author

ok!!
I have tried
Given(/^I launch .*$/, function (myvar) {
browser.get(myvar);
});

Then(/^I enter .*$/, function(textabc) {
const google = new googlePage();
return google.entertext(textabc);
});

and

Given(/^I launch (.*)$/, function (myvar) {
browser.get(myvar);
});

Then(/^I enter (.*)$/, function(textabc) {
const google = new googlePage();
return google.entertext(textabc);
});

with these implementation I am getting below:

protractor Conf.js

(node:12464) [DEP0022] DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
[21:40:08] I/launcher - Running 1 instances of WebDriver
[21:40:08] I/hosted - Using the selenium server at http://localhost:4444/wd/hub
1 scenario (1 skipped)
2 steps (2 skipped)
0m00.000s
[21:40:12] I/launcher - 0 instance(s) of WebDriver still running
[21:40:12] I/launcher - chrome #1 passed

My concern is, in which scenario cucumber directly skip steps.
or is it something related to data table I have provided in example under feature file.
I really need to fix it soon, please help me with this.

@charlierudolph
Copy link
Member

Just noticed that you have 'dry-run': true in your protractor config. I'm not familiar with that file as I'm only involved wth cucumber and not the protractor cucumber integration. When cucumber is executed with dry-run, it skips all the steps.

@dixitgargi
Copy link
Author

ok!! I have made it to false.
at least it is now going into step.
now I am getting different error

protractor Conf.js

(node:6512) [DEP0022] DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
[22:10:39] I/launcher - Running 1 instances of WebDriver
[22:10:39] I/hosted - Using the selenium server at http://localhost:4444/wd/hub

  1. Scenario: Login # test\features\google.feature:8
    √ Before # test\features\step_definitions\googlesteps.js:9
    × Given I launch https://www.google.com # test\features\step_definitions\googlesteps.js:13
    TypeError [ERR_INVALID_ARG_TYPE]: The "url" argument must be of type string. Received type function
    at Url.parse (url.js:143:11)
    at urlParse (url.js:137:13)
    at Url.resolve (url.js:634:29)
    at Object.urlResolve [as resolve] (url.js:630:40)
    at ProtractorBrowser.get (D:\CDDFRAMEWORK\node_modules\protractor\built\browser.js:653:17)
    at World. (D:\CDDFRAMEWORK\test\features\step_definitions\googlesteps.js:14:20)
    • Then I enter google # test\features\step_definitions\googlesteps.js:17

2/2 steps [=================================================================================================================================] 1 scenario (1 failed)
2 steps (1 failed, 1 skipped)
0m00.000s
[22:10:43] I/launcher - 0 instance(s) of WebDriver still running
[22:10:43] I/launcher - chrome #1 failed 1 test(s)
[22:10:43] I/launcher - overall: 1 failed spec(s)
[22:10:43] E/launcher - Process exited with error code 1
npm ERR! Test failed. See above for more details.

@charlierudolph
Copy link
Member

What is your step definition now? I expect you aren't capturing the url with the regexp when you want to be.

// This won't work as your regexp isn't capturing anything 
// and thus the function will not receive the url as an argument
// It is receiving a callback instead as based on the number of parameters the 
// function accepts it assumes you are using the callback interface
Given(/^I launch .*$/, function (myvar) {
  browser.get(myvar);
});

// This should work
Given(/^I launch (.*)$/, function (myvar) {
  browser.get(myvar);
});

@dixitgargi
Copy link
Author

dixitgargi commented Apr 18, 2018

I was capturing url through regexp (.*), I have now modified my files as below:
Feature File
Feature: Login to WebApp
Scenario Outline: Login
Given I launch url
Then I enter
Examples:
| textabc |
| google |

Step.js
const { Before, Given, Then } = require('cucumber');
var {setDefaultTimeout} = require('cucumber');
const {expect} = require('chai');
const assert = require('assert');
const googlePage = require('../../pages/googlePage');
browser.ignoreSynchronization=true;
var myvar

Before({timeout: 60 * 1000}, function() {
setDefaultTimeout(60 * 1000);
});  

Given(/^I launch url$/, function () {
return browser.get("https://www.google.com");
});

Then(/^I enter (.*)$/, function(textabc) {
 const google = new googlePage();
 return google.entertext(textabc);
});

when I executed feature file It is working fine

protractor Conf.js

(node:9748) [DEP0022] DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
[09:59:17] I/launcher - Running 1 instances of WebDriver
[09:59:17] I/hosted - Using the selenium server at http://localhost:4444/wd/hub
1 scenario (1 passed)
2 steps (2 passed)
0m01.793s
[09:59:23] I/launcher - 0 instance(s) of WebDriver still running
[09:59:23] I/launcher - chrome #1 passed

Thank you so much for solving my issues.

@lock
Copy link

lock bot commented Apr 18, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Apr 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants