Hey there! I'm facing an issue with Cucumber-Protractor where I can't seem to console log the webpage title in the "Given" tag, even though all my tests are passing. I've checked my Protractor.conf.js file and it looks fine to me. Here's how it looks: Protractor.conf.js-
exports.config = {
//seleniumAddress: 'http://127.0.0.1:4444/wd/hub',
getPageTimeout: 60000,
allScriptsTimeout: 500000,
framework: 'custom',
frameworkPath: require.resolve('protractor-cucumber-framework'),
capabilities: {
'browserName': 'chrome'
},
specs: [
'features/Login.feature'
],
cucumberOpts: {
require: 'features/steps/logic.js',
format: [require.resolve('cucumber-pretty')]
}};
The logic.js file has been causing some trouble:
I am having trouble console logging the "webpagetitle" using the disp() function.
const assert = require('assert')
const {Before,Given,When,Then} = require('cucumber');
var webdriver = require('selenium-webdriver'),
By = webdriver.By,
until = webdriver.until;
var firefox = require('selenium-webdriver/firefox');
var options = new firefox.Options();
options.addArguments("-headless");
var driver = new webdriver.Builder()
.forBrowser('firefox')
.setFirefoxOptions(options)
.build();
Given('Go to Title', function () {
function navigate(callback) {
console.log("This line gets printed - Getting to Google");
driver.get("https://www.google.com/");
callback();
}
function disp() {
console.log("This line gets printed - Getting title");
driver.getTitle().then(function (webpagetitle) {
console.log(webpagetitle);
console.log("This line does not get printed - This section seems to have an issue.");
});
}
navigate(disp);
});
When('do nothing', function () {});
Then('do nothing here also', function () {});
Your help would be highly appreciated.
Error with @yong changes: Do I need to call that done callback anywhere (as you have already called)?
1) Scenario: Add two number # features\Login.feature:5
× Given Go to Title # practice\example6\node_modules\cucumber\lib\support_code_library_builder\build_helpers.js:173
Error: function timed out, ensure the callback is executed within 5000 milliseconds
at Timeout._time.default.setTimeout [as _onTimeout] (C:\Users\Mohit.Garg\Desktop\Cucumber practice\example6\node_modules\cucumber\lib\user_code_runner.js:81:20)
at ontimeout (timers.js:436:11)
at tryOnTimeout (timers.js:300:5)
at listOnTimeout (timers.js:263:5)
at Timer.processTimers (timers.js:223:10)
- When do nothing # practice\example6\node_modules\cucumber\lib\support_code_library_builder\build_helpers.js:173
- Then do nothing here also # practice\example6\node_modules\cucumber\lib\support_code_library_builder\build_helpers.js:173
√ After # practice\example6\node_modules\cucumber\lib\support_code_library_builder\build_helpers.js:173
1 scenario (1 failed)
3 steps (1 failed, 2 skipped)
0m05.006s
[16:00:07] Bye selenium standalone server.
[16:00:07] Chrome #01 had 1 test failure(s)
[16:00:07] Total failed spec(s): 1
[16:00:07] Process exited with error code 1
C:\Users\Mohit.Garg\Desktop\Cucumber practice\example6>