Devleena
Devleena

Reputation: 463

' ReferenceError: browser is not defined ' while running cucumber-js in protractor-cucumber

I am using protractor 5.2.2. and cucumber 3.2.0.I am getting an error "browser is not defined" when i am run cucumber-js.

Feature: Login page test
Scenario: Verify whether the user is able to navigating to the login page

When I go to "https://in.linkedin.com/" 

and my step code is

var {defineSupportCode} = require('cucumber');
defineSupportCode(function ({ setDefaultTimeout, Given, When, Then }) {
setDefaultTimeout(60 * 1000);

When(/^I go to "(.*)"$/, function (url, callback) { 
browser.get(url).then(callback); 
});
)};

It looks like cucumber is not catching the global browser variable.

Upvotes: 0

Views: 2929

Answers (1)

yong
yong

Reputation: 13722

To run protractor script, you need to use command like protractor conf.js no matter which test framework(jasmine, cucumber) you used.

When use cmd protractor to start running, it will load browser into Nodejs runtime's global variable.

After protractor complete load browser into global, the package protractor-cucumber-framework will generate and execute another command line which will use cucumber-js to run cucumber feature files, but now in the Nodejs runtime, global variable has browser this property and its value is not null/undefined.

That's why we have to need more two packages: cucumber and protractor-cucumber-framework

Upvotes: 1

Related Questions