代码之家  ›  专栏  ›  技术社区  ›  jdstaerk

量角器/硒XHR保持“待定”状态

  •  2
  • jdstaerk  · 技术社区  · 7 年前

    我正在用硒量角器测试我的角页。

    在某些随机点上,它只是停止执行,因为XHR请求仍然“挂起”(在Chrome开发工具中)。

    当我复制请求URL(它是一个简单的GET请求)并在新的选项卡中打开它时,它会立即返回数据(JSON,大约200个字符长)。

    当执行E2E测试时,请求保持“挂起”,并且在所述GET-URL被调用的10次中,可能有1次失败。

    Selenium打印以下错误:“从呈现程序接收消息超时:298.388”。

    有什么想法吗?

    编辑:

    • Chrome版本71.0.3578.98
    • Chromedriver版本2.45
    • Selenium服务器版本3.141.59(独立)
    2 回复  |  直到 7 年前
        1
  •  1
  •   Moshe Slavin    7 年前

    不得已 ,你可以 execute JS

    waitForAngular(function(browser, timeOut){
        pendingReq = browser.executeScript("var injector = window.angular.element('body').injector(); var $http = injector.get('$http'); return ($http.pendingRequests.length === 0);"
        if (timeOut >= 0){
            timeOut -= 1;
            if ( pendingReq ){
                return
            };
            else {
                waitForAngular(browser, timeOut)
            };
        };
        else {
        console.log("did not load in time");
        };
    });
    

    这不是一个干净的编码方式,但我发现它可以帮助我处理Angular应用程序,其中的请求仍然悬而未决。。。

    编辑:

    上面的函数应该可以工作,它可能需要一些重构,我没有测试它。。。

        2
  •  1
  •   Saddam Pojee    7 年前

    你的测试没有按时执行。所以,你可以在 protractor.conf.js 文件。

    jasmineNodeOpts: {
      ...
     /**
     * Default time to wait in ms before a test fails.
     */
      defaultTimeoutInterval: 50000,
      ...
    },
    

    在下面的链接中,您可以找到可以在中配置的各种超时参数 : https://github.com/angular/protractor/blob/master/lib/config.ts


    如果这不能解决你的问题,那主要是因为一些插件或第三方广告。

    https://sqa.stackexchange.com/questions/9007/how-to-handle-time-out-receiving-message-from-the-renderer-in-chrome-driver/9140#9140