【问题标题】:Tests hang when running against firefox but the same tests complitly work with chrome测试在针对 firefox 运行时挂起,但相同的测试可以与 chrome 一起使用
【发布时间】:2016-08-08 07:00:49
【问题描述】:
  • 节点版本:5.10.1
  • 量角器版本:3.2.2
  • 浏览器:firefox v. 45.0.2
  • 操作系统Windows 8.1 x64
  • Web 应用程序“1.5.0”上的 Angular
  • Selenium 服务器“selenium-server-standalone-2.53.0”

我是量角器新手,我的英语很差。 情况: 我有一个测试(实际上是一套测试),它通过了 chrome,但几乎立即挂起对 firefox,它在点击链接后挂起,在它应该完成之后。

测试示例:

var homePageAddress = 'http://localhost';

var someLink = element(by.css('.navigationpanel-element[translate="SomeText.SomeText"]'));
var someTitle = element(by.css('.titlepanel-title-first[translate="omeText.SomeText"]'));
var someOtherLink = element(by.css('[translate="SomeText.SomeText"]'));
var someSearchBox = element(by.css('input.search-box'));
var listOfItems = element(by.css('li.list-item'));

browser.get(homePageAddress);

someLink.click();
//It hangs here in firefox
expect(someTitle.isDisplayed()).toEqual(true, 'Some result text');
expect(someOtherLink.isDisplayed()).toEqual(true, 'Some result text');
expect(someSearchBox.isDisplayed()).toEqual(true, 'Some result text');
expect(listOfItems.isPresent()).toEqual(true, 'Some result text');

conf.js:

exports.config = {
  directConnect: true,

    capabilities: {
        'browserName': 'firefox'
    },
    framework: 'jasmine2',

    specs: ['chromeOrganizationCreation.js'],

    jasmineNodeOpts: {
        defaultTimeoutInterval: 30000
    },  

   onPrepare: function() {  
        require('./waitReady.js');
   }
};

因此,正如我对 chrome 所说,它运行良好,但是当它针对 firefox 运行时,它在第一次单击后挂起,甚至浏览器窗口也没有关闭。

量角器日志说:

A Jasmine spec timed out. Resetting the WebDriver Control Flow.
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.

增加超时不会产生结果,行为相同。

一段 selenium-server 的日志(结束):

    09:49:56.693 DEBUG [20] org.apache.http.wire - http-outgoing-11 << "{"name":"clickElement","sessionId":"c9f64f66-fc8c-4f3d-a0be-535b63370dd0","status":0,"value":"ok"}"
    09:49:56.693 DEBUG [20] org.apache.http.impl.conn.DefaultManagedHttpClientConnection - http-outgoing-11: Close connection
    09:49:56.693 DEBUG [20] org.apache.http.impl.execchain.MainClientExec - Connection discarded
    09:49:56.694 DEBUG [20] org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection released: [id: 11][route: {}->http://127.0.0.1:7055][total kept alive: 0; route allocated: 0 of 2000; total allocated: 0 of 2000]
    09:49:56.695 DEBUG [20] org.openqa.selenium.remote.RemoteWebDriver - Executed: [c9f64f66-fc8c-4f3d-a0be-535b63370dd0, clickElement {id={c0ac812d-747e-4bf9-9678-ae6025d656c1}}]
    09:49:56.695 INFO [14] org.openqa.selenium.remote.server.DriverServlet - Done: [click: 0 [[FirefoxDriver: firefox on WINDOWS (c9f64f66-fc8c-4f3d-a0be-535b63370dd0)] -> css selector: .navigationpanel-element[translate="SomeText.SomeText"]]]
    09:49:56.700 DEBUG [14] org.openqa.selenium.remote.server.DriverServlet - Finished: POST /session/e92fa9f1-8822-4f27-85a2-9f929d484e4a/element/0/click
    09:49:56.710 DEBUG [14] org.openqa.selenium.remote.server.DriverServlet - Handling: POST /session/e92fa9f1-8822-4f27-85a2-9f929d484e4a/execute_async
    09:49:56.712 INFO [14] org.openqa.selenium.remote.server.DriverServlet - Executing: [execute async script: try { return (function (rootSelector, callback) {
      var el = document.querySelector(rootSelector);

      try {
        if (window.getAngularTestability) {
          window.getAngularTestability(el).whenStable(callback);
          return;
        }
        if (!window.angular) {
          throw new Error('window.angular is 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');
        }
        if (angular.getTestability) {
          angular.getTestability(el).whenStable(callback);
        } else {
          if (!angular.element(el).injector()) {
            throw new Error('root element (' + rootSelector + ') has no injector.' +
               ' this may mean it is not inside ng-app.');
          }
          angular.element(el).injector().get('$browser').
              notifyWhenNoOutstandingRequests(callback);
        }
      } catch (err) {
        callback(err.message);
      }
    }).apply(this, arguments); }
    catch(e) { throw (e instanceof Error) ? e : new Error(e); }, [body.ng-scope]])
    09:49:56.713 DEBUG [20] org.openqa.selenium.remote.RemoteWebDriver - Executing: executeAsyncScript [c9f64f66-fc8c-4f3d-a0be-535b63370dd0, executeAsyncScript {script=try { return (function (rootSelector, callback) {
      var el = document.querySelector(rootSelector);

      try {
        if (window.getAngularTestability) {
          window.getAngularTestability(el).whenStable(callback);
          return;
        }
        if (!window.angular) {
          throw new Error('window.angular is 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');
        }
        if (angular.getTestability) {
          angular.getTestability(el).whenStable(callback);
        } else {
          if (!angular.element(el).injector()) {
            throw new Error('root element (' + rootSelector + ') has no injector.' +
               ' this may mean it is not inside ng-app.');
          }
          angular.element(el).injector().get('$browser').
              notifyWhenNoOutstandingRequests(callback);
        }
      } catch (err) {
        callback(err.message);
      }
    }).apply(this, arguments); }
    catch(e) { throw (e instanceof Error) ? e : new Error(e); }, args=[body.ng-scope]}]
    09:49:56.714 DEBUG [20] org.apache.http.client.protocol.RequestAddCookies - CookieSpec selected: default
    09:49:56.715 DEBUG [20] org.apache.http.client.protocol.RequestAuthCache - Auth cache not set in the context
    09:49:56.715 DEBUG [20] org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection request: [route: {}->http://127.0.0.1:7055][total kept alive: 0; route allocated: 0 of 2000; total allocated: 0 of 2000]
    09:49:56.715 DEBUG [20] org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection leased: [id: 12][route: {}->http://127.0.0.1:7055][total kept alive: 0; route allocated: 1 of 2000; total allocated: 1 of 2000]
    09:49:56.715 DEBUG [20] org.apache.http.impl.execchain.MainClientExec - Opening connection {}->http://127.0.0.1:7055
    09:49:56.716 DEBUG [20] org.apache.http.impl.conn.DefaultHttpClientConnectionOperator - Connecting to /127.0.0.1:7055
    09:49:56.716 DEBUG [20] org.apache.http.impl.conn.DefaultHttpClientConnectionOperator - Connection established 127.0.0.1:58730<->127.0.0.1:7055
    09:49:56.717 DEBUG [20] org.apache.http.impl.conn.DefaultManagedHttpClientConnection - http-outgoing-12: set socket timeout to 10800000
    09:49:56.717 DEBUG [20] org.apache.http.impl.execchain.MainClientExec - Executing request POST /hub/session/c9f64f66-fc8c-4f3d-a0be-535b63370dd0/execute_async HTTP/1.1
    09:49:56.717 DEBUG [20] org.apache.http.impl.execchain.MainClientExec - Target auth state: UNCHALLENGED
    09:49:56.717 DEBUG [20] org.apache.http.impl.execchain.MainClientExec - Proxy auth state: UNCHALLENGED
    09:49:56.717 DEBUG [20] org.apache.http.headers - http-outgoing-12 >> POST /hub/session/c9f64f66-fc8c-4f3d-a0be-535b63370dd0/execute_async HTTP/1.1
    09:49:56.717 DEBUG [20] org.apache.http.headers - http-outgoing-12 >> Content-Type: application/json; charset=utf-8
    09:49:56.718 DEBUG [20] org.apache.http.headers - http-outgoing-12 >> Content-Length: 1172
    09:49:56.718 DEBUG [20] org.apache.http.headers - http-outgoing-12 >> Host: 127.0.0.1:7055
    09:49:56.718 DEBUG [20] org.apache.http.headers - http-outgoing-12 >> Connection: Keep-Alive
    09:49:56.718 DEBUG [20] org.apache.http.headers - http-outgoing-12 >> User-Agent: Apache-HttpClient/4.5.1 (Java/1.8.0_77)
    09:49:56.718 DEBUG [20] org.apache.http.headers - http-outgoing-12 >> Accept-Encoding: gzip,deflate
    09:49:56.718 DEBUG [20] org.apache.http.wire - http-outgoing-12 >> "POST /hub/session/c9f64f66-fc8c-4f3d-a0be-535b63370dd0/execute_async HTTP/1.1[\r][\n]"
    09:49:56.718 DEBUG [20] org.apache.http.wire - http-outgoing-12 >> "Content-Type: application/json; charset=utf-8[\r][\n]"
    09:49:56.718 DEBUG [20] org.apache.http.wire - http-outgoing-12 >> "Content-Length: 1172[\r][\n]"
    09:49:56.719 DEBUG [20] org.apache.http.wire - http-outgoing-12 >> "Host: 127.0.0.1:7055[\r][\n]"
    09:49:56.719 DEBUG [20] org.apache.http.wire - http-outgoing-12 >> "Connection: Keep-Alive[\r][\n]"
    09:49:56.719 DEBUG [20] org.apache.http.wire - http-outgoing-12 >> "User-Agent: Apache-HttpClient/4.5.1 (Java/1.8.0_77)[\r][\n]"
    09:49:56.719 DEBUG [20] org.apache.http.wire - http-outgoing-12 >> "Accept-Encoding: gzip,deflate[\r][\n]"
    09:49:56.719 DEBUG [20] org.apache.http.wire - http-outgoing-12 >> "[\r][\n]"
    09:49:56.719 DEBUG [20] org.apache.http.wire - http-outgoing-12 >> "{"script":"try { return (function (rootSelector, callback) {\n  var el = document.querySelector(rootSelector);\n\n  try {\n    if (window.getAngularTestability) {\n      window.getAngularTestability(el).whenStable(callback);\n      return;\n    }\n    if (!window.angular) {\n      throw new Error('window.angular is undefined.  This could be either ' +\n          'because this is a non-angular page or because your test involves ' +\n          'client-side navigation, which can interfere with Protractor\\'s ' +\n          'bootstrapping.  See http://git.io/v4gXM for details');\n    }\n    if (angular.getTestability) {\n      angular.getTestability(el).whenStable(callback);\n    } else {\n      if (!angular.element(el).injector()) {\n        throw new Error('root element (' + rootSelector + ') has no injector.' +\n           ' this may mean it is not inside ng-app.');\n      }\n      angular.element(el).injector().get('$browser').\n          notifyWhenNoOutstandingRequests(callback);\n    }\n  } catch (err) {\n    callback(err.message);\n  }\n}).apply(this, arguments); }\ncatch(e) { throw (e instanceof Error) ? e : new Error(e); }","args":["body.ng-scope"]}"
    09:50:25.970 DEBUG [13] org.openqa.selenium.remote.server.DriverServlet - Handling: DELETE /session/e92fa9f1-8822-4f27-85a2-9f929d484e4a
    09:50:25.971 INFO [13] org.openqa.selenium.remote.server.DriverServlet - Executing: [delete session: e92fa9f1-8822-4f27-85a2-9f929d484e4a])

请帮忙,我花了很多时间试图解决它,我应该打开一些问题吗?但我不确定要定义某些步骤以在没有本地应用程序的情况下重现它。

更新

这里描述的问题: https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/4757

来自我的 Firefox 驱动程序的日志:

"level":"INFO","message":"[fxdriver.SyntheticMouse] Calling fireMouseEvent mousemove 397, 205, ","timestamp":1461003932367,"type":""} {"level":"INFO","message":"[fxdriver.SyntheticMouse] Calling fireMouseEvent mousedown 397, 205, ","timestamp":1461003932388,"type":""} {"level":"INFO","message":"[fxdriver.SyntheticMouse] Calling fireMouseEvent mouseup 397, 205, ","timestamp":1461003932408,"type":""} {"level":"INFO","message":"[fxdriver.SyntheticMouse] Calling fireMouseEvent click 397, 205, ","timestamp":1461003932454,"type":""} {"level":"INFO","message":"[fxdriver.Utils] Not loading document anymore.","timestamp":1461003932478,"type":""} {"level":"INFO","message":"[fxdriver.nsCommandProcessor] Received command: executeAsyncScript","timestamp":1461003932504,"type":""} {"level":"INFO","message":"[fxdriver.nsCommandProcessor] Received command: findElements","timestamp":1461003934754,"type":""} {"level":"INFO","message":"[fxdriver.DelayedCommand] Ignoring pending about:document-onload-blocker request","timestamp":1461003934917,"type":""} {"level":"INFO","message":"[fxdriver.DelayedCommand] Ignoring pending about:document-onload-blocker request","timestamp":1461003935029,"type":""} {"level":"INFO","message":"[fxdriver.DelayedCommand] Ignoring pending about:document-onload-blocker request","timestamp":1461003935156,"type":""} {"level":"INFO","message":"[fxdriver.DelayedCommand] Ignoring pending about:document-onload-blocker request","timestamp":1461003935279,"type":""} {"level":"INFO","message":"[fxdriver.DelayedCommand] Ignoring pending about:document-onload-blocker request","timestamp":1461003935395,"type":""} {"level":"INFO","message":"[fxdriver.DelayedCommand] Ignoring pending about:document-onload-blocker request","timestamp":1461003935518,"type":""} {"level":"INFO","message":"[fxdriver.DelayedCommand] Ignoring pending about:document-onload-blocker request","timestamp":1461003935640,"type":""} {"level":"INFO","message":"[fxdriver.DelayedCommand] Ignoring pending about:document-onload-blocker request","timestamp":1461003935757,"type":""} {"level":"INFO","message":"[fxdriver.DelayedCommand] Ignoring pending about:document-onload-blocker request","timestamp":1461003935889,"type":""} {"level":"INFO","message":"[fxdriver.DelayedCommand] Ignoring pending about:document-onload-blocker request","timestamp":1461003936015,"type":""} {"level":"INFO","message":"[fxdriver.DelayedCommand] Ignoring pending about:document-onload-blocker request","timestamp":1461003936145,"type":""} {"level":"INFO","message":"[fxdriver.DelayedCommand] Ignoring pending about:document-onload-blocker request","timestamp":1461003936273,"type":""}

但是我还是不知道怎么解决,your comet request是什么: To solve the problem I rebuild selenium using following guide: http://shengwangi.blogspot.com/2014/08/how-to-build-selenium-from-source.html This generated my custom version of jar file. Based on comment #28 I updated nsCommandProcessor.js and just added: (request.name.indexOf('<your comet request>') > -1) to hasOnLoadBlocker = hasOnLoadBlocker || (request.name == 'about:document-onload-blocker'); so it would ignore the comet call. nsCommandProcessor.js is under javascript\firefox-driver\js folder

【问题讨论】:

    标签: angularjs selenium firefox protractor


    【解决方案1】:

    发生这种情况的原因有几个。我的第一个建议是确保 webdriver 是最新的。在控制台中输入:

    webdriver-manager update
    

    其次,当您说增加超时会产生相同的行为时,您真的看到更长的超时吗?如果它暂停 5 秒(默认),那么 Jasmine 认为它是异步的。 http://jasmine.github.io/2.0/introduction.html#section-43

    我会尝试(也是一个很好的做法),将您的测试分成 it 块。

    it('gets the homepage', function() {
        var homePageAddress = 'http://localhost';
        browser.get(homePageAddress)
        expect(browser.getCurrentUrl()).toContain('localhost');
    });
    
    it('clicks the link', function() {
        var someLink = element(by.css('.navigationpanel-element[translate="SomeText.SomeText"]'));
        someLink.click();
        expect(something).toBe(true);
    });
    

    这种方式可能有助于 Protractor 更好地处理控制流。

    第三,如果这些都不起作用,也许可以尝试另一种定位元素的方法。我对translate 属性不太熟悉,但它似乎也是一种“实验性技术”,根据 MDN,任何浏览器都不支持。

    https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/translate

    【讨论】:

    • 感谢您的快速响应,我之前更新了 webdriver-manager,也尝试使用 selenium-server-standalone 的最新版本,但没有帮助。如果我增加它,我会看到更长的超时。现在我意识到两件事:1.如果“量角器”加载页面然后做一些期望,即使我使用translate属性它也能正常工作,但我只需要在链接或按钮上添加点击,它会立即挂起点击,点击后什么都不做。
    • 此案例有效:it('gets the homepage', function() { var homePageAddress = 'http://localhost'; browser.get(homePageAddress) expect(browser.getCurrentUrl()).toContain('localhost'); }; 此案例无效:it('clicks the link', function() { var someLink = element(by.css('.navigationpanel-element[translate="SomeText.SomeText"]')); someLink.click(); expect(something).toBe(true); }
    • 正如我所说,点击后它会挂起,但 click() 没有问题;在Firefox中,我什么都不懂。我尝试使用其他定位器并得到相同的结果。
    • 现在我也尝试在 C# 上编写简单的测试,点击两次,结果相同。我认为这是我们的 web 应用程序(angularjs)和 selenium webdriver 之间的东西。 chrome 以某种方式解决了这个问题。
    • @Niyarlatotep 是的,与 chrome 相比,我在 firefox 上运行的测试存在一些小问题。从来没有专门针对.click(),但希望你能弄清楚。我唯一的另一个想法是通过browser.driver.actions().mouseDown(someLink).mouseUp().perform()模拟点击事件;除此之外我不确定
    【解决方案2】:

    这里描述的问题:https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/4757

    有两种解决方法:首先在下面的链接中描述, 第二个是我们使用的:通过网络套接字打开工作信号R。 感谢支持!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-16
      • 2021-01-31
      • 2016-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-14
      • 2022-10-13
      相关资源
      最近更新 更多