0

I created a function which return the new Browser object from the JS function browser.forkNewDriverInstance() and i created a global variable in my config file and i'm calling a function from that file by using this global variable. but here when i'm calling that function it is throwing error like utility.openNewBrowser is not a function error.

Config File:

onPrepare: function () {
     
     global.utility=require("../src/test/resources/com.learnFramework.utility/timeOutConfig.js");
  }

Cucumber Opts functions

cucumberOpts: {

//i'm using the same file for setting up the timeout.. is this creating the issue??

    require:['../src/test/resources/com.learnFramework.utility/timeOutConfig.js'],
    tags: false,
    profile: false,
    format:'json:../Reports/jsonResult/results.json',
    'no-source': true
}

Function

var configure = function () {
      this.setDefaultTimeout(100 * 1000);
        
        this.openNewBrowser=function(){
            return browser.forkNewDriverInstance(true);
        }
    };

    module.exports = configure;

Error Log

TypeError: utility.openNewBrowser is not a function

When i called the forkNewBrowserInstance method directly i'm getting the below error.

both angularJS testability and angular testability are undefined. This could be either because this is a non-angular page or because your test involves client-side navigation, which can interfere with Protractor's bootstrapping. See http://git.io/v4gXM for details

can some help me to resolve this issue.. i got this error because the first browser ignoring synchronization but second browser how can i ignore the synchronization?

Community
  • 1
  • 1
Satish Rongala
  • 209
  • 6
  • 19

2 Answers2

0

What you did above is the correct way of defining a global variable. But I think the global variable name should be configure instead of utility that is why it is throwing the TypeError.

And wherever you want to call it, use that variable name as is. This is actually how protractor, browser and other built-in global variables were made available globally. The following posting was helpful and also the protractor doc where it's explaining the property: params?: any;

Hope this helps, please let me know.

Himanil Gupta
  • 91
  • 1
  • 12
  • it's not working.. i changed the global variable name but still the same issue – Satish Rongala Nov 15 '19 at 17:23
  • @SatishRongala Import timeoutConfig.js file only once and call the methods `openBrowser` and 'setDefaultTimeout` Under OnPrepare and CucumberOpts. Also in the last lines of the post have you checked whether the page is Angular or NonAngular. Refer this post https://stackoverflow.com/a/37747440/1976848 . – Himanil Gupta Nov 18 '19 at 15:06
  • i got a solution for this but i got stuck with another issue.. https://stackoverflow.com/questions/58888844 .. please check it if you able to solve this one.. – Satish Rongala Nov 18 '19 at 16:06
0

I faced the same issue but with jasmine. so i had done the following workaround and issue was resolved.

class abc{
      constructor() {
         var configure = function () {
         this.setDefaultTimeout(100 * 1000);    
         this.openNewBrowser=function(){
         return browser.forkNewDriverInstance(true);
        }
    };

}
}
module.exports = new abc();
Meenakshi
  • 1
  • 1