Protractor: initialise Global variable in one js a

2019-08-11 08:05发布

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.

1条回答
走好不送
2楼-- · 2019-08-11 08:47

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'
  },
查看更多
登录 后发表回答