Selenium-cucumber.js test failed to run while adding a BeforeScenario in hooks.js file
Framework using: selenium-cucumber-js.
I am trying to run the below selenium-cucumber-js test. I would like to run the loginApp()
function as BeforeScenario
written in hooks.js file. But while running the test, its throwing below error at the moment. Could someone please advise on how to resolve the problem.
`C:Testscucumbernode_modulescucumberlibcucumberruntimeevent_broadcaster.js:30 process.nextTick(function(){ throw error; }); // prevent swallow by unhandled rejection
TypeError: node_modulescucumberlibcucumbersupport_codelibrary.js:17 scenario.loginApp is not a function
at C:Testscucumberstep-definitionshooks.js:4:51
at _combinedTickCallback (internal/process/next_tick.js:73:7)
at process._tickCallback (internal/process/next_tick.js:104:9)
at Module.runMain (module.js:606:11)
at run (bootstrap_node.js:390:7)
at startup (bootstrap_node.js:150:9)`
/**/Feature:**
//cucumber/features
Feature: Login and look for the Register tab
Scenario: Check the register tab in application
When After login look for "Register" in navbar
//**lookfortab.js**
//cucumber/step-definitions
const expect = require('chai').expect;
module.exports = function() {
this.When(/^After login look for "([^"]*)" in navbar$/, function (registerText) {
let navText = By.css('div#nav>div>ul>li>a');
driver.wait(until.elementLocated(navText, 10000));
return driver.findElement(navText).getText().then(el => {
console.log("print text here:"+el);
const displayTxt = el;
expect(displayTxt).to.be.eql(registerText);
});
})
}
//login.js
//cucumber/page-objects
module.exports = {
loginApp(){
this.driver.helpers.loadPage('https://testingsite.com')
this.driver.findElement(by.id('HomeLogin_Username')).sendKeys("Tester");
this.driver.findElement(by.id('HomeLogin_Password')).sendKeys("SomePassword123");
let lgBtn = By.css('div#login-fields>div>button');
this.driver.findElement(lgBtn).click();
}
};
//hooks.js
//cucumber/step-definitions
module.exports = function () {
this.BeforeScenario(function(scenario, done) {
console.log('BeforeScenario: ' + scenario.loginApp());
done();
});
};
javascript node.js selenium-webdriver cucumberjs
add a comment |
Framework using: selenium-cucumber-js.
I am trying to run the below selenium-cucumber-js test. I would like to run the loginApp()
function as BeforeScenario
written in hooks.js file. But while running the test, its throwing below error at the moment. Could someone please advise on how to resolve the problem.
`C:Testscucumbernode_modulescucumberlibcucumberruntimeevent_broadcaster.js:30 process.nextTick(function(){ throw error; }); // prevent swallow by unhandled rejection
TypeError: node_modulescucumberlibcucumbersupport_codelibrary.js:17 scenario.loginApp is not a function
at C:Testscucumberstep-definitionshooks.js:4:51
at _combinedTickCallback (internal/process/next_tick.js:73:7)
at process._tickCallback (internal/process/next_tick.js:104:9)
at Module.runMain (module.js:606:11)
at run (bootstrap_node.js:390:7)
at startup (bootstrap_node.js:150:9)`
/**/Feature:**
//cucumber/features
Feature: Login and look for the Register tab
Scenario: Check the register tab in application
When After login look for "Register" in navbar
//**lookfortab.js**
//cucumber/step-definitions
const expect = require('chai').expect;
module.exports = function() {
this.When(/^After login look for "([^"]*)" in navbar$/, function (registerText) {
let navText = By.css('div#nav>div>ul>li>a');
driver.wait(until.elementLocated(navText, 10000));
return driver.findElement(navText).getText().then(el => {
console.log("print text here:"+el);
const displayTxt = el;
expect(displayTxt).to.be.eql(registerText);
});
})
}
//login.js
//cucumber/page-objects
module.exports = {
loginApp(){
this.driver.helpers.loadPage('https://testingsite.com')
this.driver.findElement(by.id('HomeLogin_Username')).sendKeys("Tester");
this.driver.findElement(by.id('HomeLogin_Password')).sendKeys("SomePassword123");
let lgBtn = By.css('div#login-fields>div>button');
this.driver.findElement(lgBtn).click();
}
};
//hooks.js
//cucumber/step-definitions
module.exports = function () {
this.BeforeScenario(function(scenario, done) {
console.log('BeforeScenario: ' + scenario.loginApp());
done();
});
};
javascript node.js selenium-webdriver cucumberjs
add a comment |
Framework using: selenium-cucumber-js.
I am trying to run the below selenium-cucumber-js test. I would like to run the loginApp()
function as BeforeScenario
written in hooks.js file. But while running the test, its throwing below error at the moment. Could someone please advise on how to resolve the problem.
`C:Testscucumbernode_modulescucumberlibcucumberruntimeevent_broadcaster.js:30 process.nextTick(function(){ throw error; }); // prevent swallow by unhandled rejection
TypeError: node_modulescucumberlibcucumbersupport_codelibrary.js:17 scenario.loginApp is not a function
at C:Testscucumberstep-definitionshooks.js:4:51
at _combinedTickCallback (internal/process/next_tick.js:73:7)
at process._tickCallback (internal/process/next_tick.js:104:9)
at Module.runMain (module.js:606:11)
at run (bootstrap_node.js:390:7)
at startup (bootstrap_node.js:150:9)`
/**/Feature:**
//cucumber/features
Feature: Login and look for the Register tab
Scenario: Check the register tab in application
When After login look for "Register" in navbar
//**lookfortab.js**
//cucumber/step-definitions
const expect = require('chai').expect;
module.exports = function() {
this.When(/^After login look for "([^"]*)" in navbar$/, function (registerText) {
let navText = By.css('div#nav>div>ul>li>a');
driver.wait(until.elementLocated(navText, 10000));
return driver.findElement(navText).getText().then(el => {
console.log("print text here:"+el);
const displayTxt = el;
expect(displayTxt).to.be.eql(registerText);
});
})
}
//login.js
//cucumber/page-objects
module.exports = {
loginApp(){
this.driver.helpers.loadPage('https://testingsite.com')
this.driver.findElement(by.id('HomeLogin_Username')).sendKeys("Tester");
this.driver.findElement(by.id('HomeLogin_Password')).sendKeys("SomePassword123");
let lgBtn = By.css('div#login-fields>div>button');
this.driver.findElement(lgBtn).click();
}
};
//hooks.js
//cucumber/step-definitions
module.exports = function () {
this.BeforeScenario(function(scenario, done) {
console.log('BeforeScenario: ' + scenario.loginApp());
done();
});
};
javascript node.js selenium-webdriver cucumberjs
Framework using: selenium-cucumber-js.
I am trying to run the below selenium-cucumber-js test. I would like to run the loginApp()
function as BeforeScenario
written in hooks.js file. But while running the test, its throwing below error at the moment. Could someone please advise on how to resolve the problem.
`C:Testscucumbernode_modulescucumberlibcucumberruntimeevent_broadcaster.js:30 process.nextTick(function(){ throw error; }); // prevent swallow by unhandled rejection
TypeError: node_modulescucumberlibcucumbersupport_codelibrary.js:17 scenario.loginApp is not a function
at C:Testscucumberstep-definitionshooks.js:4:51
at _combinedTickCallback (internal/process/next_tick.js:73:7)
at process._tickCallback (internal/process/next_tick.js:104:9)
at Module.runMain (module.js:606:11)
at run (bootstrap_node.js:390:7)
at startup (bootstrap_node.js:150:9)`
/**/Feature:**
//cucumber/features
Feature: Login and look for the Register tab
Scenario: Check the register tab in application
When After login look for "Register" in navbar
//**lookfortab.js**
//cucumber/step-definitions
const expect = require('chai').expect;
module.exports = function() {
this.When(/^After login look for "([^"]*)" in navbar$/, function (registerText) {
let navText = By.css('div#nav>div>ul>li>a');
driver.wait(until.elementLocated(navText, 10000));
return driver.findElement(navText).getText().then(el => {
console.log("print text here:"+el);
const displayTxt = el;
expect(displayTxt).to.be.eql(registerText);
});
})
}
//login.js
//cucumber/page-objects
module.exports = {
loginApp(){
this.driver.helpers.loadPage('https://testingsite.com')
this.driver.findElement(by.id('HomeLogin_Username')).sendKeys("Tester");
this.driver.findElement(by.id('HomeLogin_Password')).sendKeys("SomePassword123");
let lgBtn = By.css('div#login-fields>div>button');
this.driver.findElement(lgBtn).click();
}
};
//hooks.js
//cucumber/step-definitions
module.exports = function () {
this.BeforeScenario(function(scenario, done) {
console.log('BeforeScenario: ' + scenario.loginApp());
done();
});
};
javascript node.js selenium-webdriver cucumberjs
javascript node.js selenium-webdriver cucumberjs
edited Nov 20 at 2:33
asked Nov 20 at 0:23
soccerway
417314
417314
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
First of all, note that selenium-cucumber-js
is using a rather old version of cucumber-js
(1.3.3 vs 5.0.2 at the moment of writing this). Keep that in mind when you're consulting cucumber-js
docs or looking for examples. Below, I'll be posting links to the cucumber-js@1.3.3
docs.
As for what's not working in your set up:
scenario
object that is passed into your hooks doesn't have page objects attached to it. It only contains some meta info about the scenario and methods to get it. Here's a list of them: cucumber-js docs
- If you want to reference the page objects from your hooks, you can use the global
page
as described here: Page objects - selenium-cucumber-js
- Your
loginApp()
function probably still won't work because you're accessing webdriver asthis.driver
and helpers asthis.driver.helpers
. They're also globally defined byselenium-cucumber-js
: Helpers
So, your hooks.js
should look like this:
module.exports = function () {
this.BeforeScenario(function(scenario, done) {
console.log('BeforeScenario: ' + page.login.loginApp());
done();
});
};
And your login.js
:
module.exports = {
loginApp(){
helpers.loadPage('https://example.com')
driver.findElement(by.id('HomeLogin_Username')).sendKeys("Tester");
driver.findElement(by.id('HomeLogin_Password')).sendKeys("SomePassword123");
let lgBtn = By.css('div#login-fields>div>button');
driver.findElement(lgBtn).click();
}
};
Thank you very much..now the test is passing..but at this stepconsole.log('BeforeScenario: ' + page.login.loginApp());
is throwing undefined ..do you why this is throwing undefined at this step in hooks.js?
– soccerway
Nov 25 at 21:40
@soccerway what's the error message and call stack?
– shkaper
Nov 26 at 18:11
1
@soccerway Ok, I see.loginApp()
printsundefined
because it doesn't return anything. If a function doesn't return anything explicitly, it returnsundefined
.
– shkaper
Nov 26 at 21:46
1
@soccerway so leavingpage.login.loginApp()
should do the trick then - in case it works
– shkaper
Nov 26 at 22:10
1
@soccerway yep, that's how it works
– shkaper
Nov 26 at 23:15
|
show 5 more comments
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53384522%2fselenium-cucumber-js-test-failed-to-run-while-adding-a-beforescenario-in-hooks-j%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
First of all, note that selenium-cucumber-js
is using a rather old version of cucumber-js
(1.3.3 vs 5.0.2 at the moment of writing this). Keep that in mind when you're consulting cucumber-js
docs or looking for examples. Below, I'll be posting links to the cucumber-js@1.3.3
docs.
As for what's not working in your set up:
scenario
object that is passed into your hooks doesn't have page objects attached to it. It only contains some meta info about the scenario and methods to get it. Here's a list of them: cucumber-js docs
- If you want to reference the page objects from your hooks, you can use the global
page
as described here: Page objects - selenium-cucumber-js
- Your
loginApp()
function probably still won't work because you're accessing webdriver asthis.driver
and helpers asthis.driver.helpers
. They're also globally defined byselenium-cucumber-js
: Helpers
So, your hooks.js
should look like this:
module.exports = function () {
this.BeforeScenario(function(scenario, done) {
console.log('BeforeScenario: ' + page.login.loginApp());
done();
});
};
And your login.js
:
module.exports = {
loginApp(){
helpers.loadPage('https://example.com')
driver.findElement(by.id('HomeLogin_Username')).sendKeys("Tester");
driver.findElement(by.id('HomeLogin_Password')).sendKeys("SomePassword123");
let lgBtn = By.css('div#login-fields>div>button');
driver.findElement(lgBtn).click();
}
};
Thank you very much..now the test is passing..but at this stepconsole.log('BeforeScenario: ' + page.login.loginApp());
is throwing undefined ..do you why this is throwing undefined at this step in hooks.js?
– soccerway
Nov 25 at 21:40
@soccerway what's the error message and call stack?
– shkaper
Nov 26 at 18:11
1
@soccerway Ok, I see.loginApp()
printsundefined
because it doesn't return anything. If a function doesn't return anything explicitly, it returnsundefined
.
– shkaper
Nov 26 at 21:46
1
@soccerway so leavingpage.login.loginApp()
should do the trick then - in case it works
– shkaper
Nov 26 at 22:10
1
@soccerway yep, that's how it works
– shkaper
Nov 26 at 23:15
|
show 5 more comments
First of all, note that selenium-cucumber-js
is using a rather old version of cucumber-js
(1.3.3 vs 5.0.2 at the moment of writing this). Keep that in mind when you're consulting cucumber-js
docs or looking for examples. Below, I'll be posting links to the cucumber-js@1.3.3
docs.
As for what's not working in your set up:
scenario
object that is passed into your hooks doesn't have page objects attached to it. It only contains some meta info about the scenario and methods to get it. Here's a list of them: cucumber-js docs
- If you want to reference the page objects from your hooks, you can use the global
page
as described here: Page objects - selenium-cucumber-js
- Your
loginApp()
function probably still won't work because you're accessing webdriver asthis.driver
and helpers asthis.driver.helpers
. They're also globally defined byselenium-cucumber-js
: Helpers
So, your hooks.js
should look like this:
module.exports = function () {
this.BeforeScenario(function(scenario, done) {
console.log('BeforeScenario: ' + page.login.loginApp());
done();
});
};
And your login.js
:
module.exports = {
loginApp(){
helpers.loadPage('https://example.com')
driver.findElement(by.id('HomeLogin_Username')).sendKeys("Tester");
driver.findElement(by.id('HomeLogin_Password')).sendKeys("SomePassword123");
let lgBtn = By.css('div#login-fields>div>button');
driver.findElement(lgBtn).click();
}
};
Thank you very much..now the test is passing..but at this stepconsole.log('BeforeScenario: ' + page.login.loginApp());
is throwing undefined ..do you why this is throwing undefined at this step in hooks.js?
– soccerway
Nov 25 at 21:40
@soccerway what's the error message and call stack?
– shkaper
Nov 26 at 18:11
1
@soccerway Ok, I see.loginApp()
printsundefined
because it doesn't return anything. If a function doesn't return anything explicitly, it returnsundefined
.
– shkaper
Nov 26 at 21:46
1
@soccerway so leavingpage.login.loginApp()
should do the trick then - in case it works
– shkaper
Nov 26 at 22:10
1
@soccerway yep, that's how it works
– shkaper
Nov 26 at 23:15
|
show 5 more comments
First of all, note that selenium-cucumber-js
is using a rather old version of cucumber-js
(1.3.3 vs 5.0.2 at the moment of writing this). Keep that in mind when you're consulting cucumber-js
docs or looking for examples. Below, I'll be posting links to the cucumber-js@1.3.3
docs.
As for what's not working in your set up:
scenario
object that is passed into your hooks doesn't have page objects attached to it. It only contains some meta info about the scenario and methods to get it. Here's a list of them: cucumber-js docs
- If you want to reference the page objects from your hooks, you can use the global
page
as described here: Page objects - selenium-cucumber-js
- Your
loginApp()
function probably still won't work because you're accessing webdriver asthis.driver
and helpers asthis.driver.helpers
. They're also globally defined byselenium-cucumber-js
: Helpers
So, your hooks.js
should look like this:
module.exports = function () {
this.BeforeScenario(function(scenario, done) {
console.log('BeforeScenario: ' + page.login.loginApp());
done();
});
};
And your login.js
:
module.exports = {
loginApp(){
helpers.loadPage('https://example.com')
driver.findElement(by.id('HomeLogin_Username')).sendKeys("Tester");
driver.findElement(by.id('HomeLogin_Password')).sendKeys("SomePassword123");
let lgBtn = By.css('div#login-fields>div>button');
driver.findElement(lgBtn).click();
}
};
First of all, note that selenium-cucumber-js
is using a rather old version of cucumber-js
(1.3.3 vs 5.0.2 at the moment of writing this). Keep that in mind when you're consulting cucumber-js
docs or looking for examples. Below, I'll be posting links to the cucumber-js@1.3.3
docs.
As for what's not working in your set up:
scenario
object that is passed into your hooks doesn't have page objects attached to it. It only contains some meta info about the scenario and methods to get it. Here's a list of them: cucumber-js docs
- If you want to reference the page objects from your hooks, you can use the global
page
as described here: Page objects - selenium-cucumber-js
- Your
loginApp()
function probably still won't work because you're accessing webdriver asthis.driver
and helpers asthis.driver.helpers
. They're also globally defined byselenium-cucumber-js
: Helpers
So, your hooks.js
should look like this:
module.exports = function () {
this.BeforeScenario(function(scenario, done) {
console.log('BeforeScenario: ' + page.login.loginApp());
done();
});
};
And your login.js
:
module.exports = {
loginApp(){
helpers.loadPage('https://example.com')
driver.findElement(by.id('HomeLogin_Username')).sendKeys("Tester");
driver.findElement(by.id('HomeLogin_Password')).sendKeys("SomePassword123");
let lgBtn = By.css('div#login-fields>div>button');
driver.findElement(lgBtn).click();
}
};
answered Nov 21 at 22:28
shkaper
1,032514
1,032514
Thank you very much..now the test is passing..but at this stepconsole.log('BeforeScenario: ' + page.login.loginApp());
is throwing undefined ..do you why this is throwing undefined at this step in hooks.js?
– soccerway
Nov 25 at 21:40
@soccerway what's the error message and call stack?
– shkaper
Nov 26 at 18:11
1
@soccerway Ok, I see.loginApp()
printsundefined
because it doesn't return anything. If a function doesn't return anything explicitly, it returnsundefined
.
– shkaper
Nov 26 at 21:46
1
@soccerway so leavingpage.login.loginApp()
should do the trick then - in case it works
– shkaper
Nov 26 at 22:10
1
@soccerway yep, that's how it works
– shkaper
Nov 26 at 23:15
|
show 5 more comments
Thank you very much..now the test is passing..but at this stepconsole.log('BeforeScenario: ' + page.login.loginApp());
is throwing undefined ..do you why this is throwing undefined at this step in hooks.js?
– soccerway
Nov 25 at 21:40
@soccerway what's the error message and call stack?
– shkaper
Nov 26 at 18:11
1
@soccerway Ok, I see.loginApp()
printsundefined
because it doesn't return anything. If a function doesn't return anything explicitly, it returnsundefined
.
– shkaper
Nov 26 at 21:46
1
@soccerway so leavingpage.login.loginApp()
should do the trick then - in case it works
– shkaper
Nov 26 at 22:10
1
@soccerway yep, that's how it works
– shkaper
Nov 26 at 23:15
Thank you very much..now the test is passing..but at this step
console.log('BeforeScenario: ' + page.login.loginApp());
is throwing undefined ..do you why this is throwing undefined at this step in hooks.js?– soccerway
Nov 25 at 21:40
Thank you very much..now the test is passing..but at this step
console.log('BeforeScenario: ' + page.login.loginApp());
is throwing undefined ..do you why this is throwing undefined at this step in hooks.js?– soccerway
Nov 25 at 21:40
@soccerway what's the error message and call stack?
– shkaper
Nov 26 at 18:11
@soccerway what's the error message and call stack?
– shkaper
Nov 26 at 18:11
1
1
@soccerway Ok, I see.
loginApp()
prints undefined
because it doesn't return anything. If a function doesn't return anything explicitly, it returns undefined
.– shkaper
Nov 26 at 21:46
@soccerway Ok, I see.
loginApp()
prints undefined
because it doesn't return anything. If a function doesn't return anything explicitly, it returns undefined
.– shkaper
Nov 26 at 21:46
1
1
@soccerway so leaving
page.login.loginApp()
should do the trick then - in case it works– shkaper
Nov 26 at 22:10
@soccerway so leaving
page.login.loginApp()
should do the trick then - in case it works– shkaper
Nov 26 at 22:10
1
1
@soccerway yep, that's how it works
– shkaper
Nov 26 at 23:15
@soccerway yep, that's how it works
– shkaper
Nov 26 at 23:15
|
show 5 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53384522%2fselenium-cucumber-js-test-failed-to-run-while-adding-a-beforescenario-in-hooks-j%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown