Subhash
Subhash

Reputation: 588

Protractor: initialise Global variable in one js and use the same var in other js

I am using protractor to test angularJS apps. I have declared a variable 'logDir' in my test js and want to use it as global variable in other js.

//test.js

var regex = /(.*automation)/;
var result = regex.exec(__dirname);
var baseDir = result[0]; 
var libDir = baseDir + '/lib';

I want to use libDir variable globally in other js.

I am new to protractor and need help. If more clarification needed, let me know.

Thanks in advance.

Upvotes: 1

Views: 1516

Answers (1)

AdityaReddy
AdityaReddy

Reputation: 3645

You can dump the variable you need globally onto Protractor browser object and use it anywhere in the Protractor run Environment

browser.libDir = baseDir + '/lib';

And then if you need it in any other test case you can directly use it as browser.libDir

A more professional way to handle this would be declaring global variables in onPrepare().

  onPrepare: function() {
       browser.libDir = baseDir + '/lib'
  },

Upvotes: 2

Related Questions