簡體   English   中英

Protractor 無法從 JS 文件中找到 function

[英]Protractor is not able to find a function from JS file

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. 但是在這里,當我調用 function 時,它會拋出類似實用程序的錯誤utility.openNewBrowser is not a function錯誤。

配置文件:

onPrepare: function () {

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

Cucumber 選配功能

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;

錯誤日志

TypeError: utility.openNewBrowser is not a function

當我直接調用 forkNewBrowserInstance 方法時,出現以下錯誤。

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

有人可以幫我解決這個問題。我收到這個錯誤是因為第一個瀏覽器忽略了同步,但是第二個瀏覽器我怎么能忽略同步?

您在上面所做的是定義全局變量的正確方法。 但我認為應該configure全局變量名而不是utility ,這就是它拋出 TypeError 的原因。

無論您想調用它,請按原樣使用該變量名稱。 這實際上是 protractor、瀏覽器和其他內置全局變量全局可用的方式 以下帖子很有幫助,還有protractor 文檔,其中解釋了屬性: params?: any;

希望這會有所幫助,請告訴我。

我遇到了同樣的問題,但使用的是 jasmine。 所以我做了以下解決方法,問題得到解決。

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

}
}
module.exports = new abc();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM