lib/cucumber/pickles/helpers/waiter.rb in pickles-0.1.7 vs lib/cucumber/pickles/helpers/waiter.rb in pickles-0.1.8

- old
+ new

@@ -48,20 +48,23 @@ # end # # end # end +# +# XMLHttpRequest.prototype.open broken in Angular2 + zone.js => have to redefine XMLHttpRequest.prototype.send +# def stub_xml_http_request(page) page.evaluate_script <<-JAVASCRIPT (function() { if (window.ajaxRequestIsSet) { return; }; window.ajaxRequestIsSet = true; - var oldOpen = XMLHttpRequest.prototype.open; + var oldSend = XMLHttpRequest.prototype.send; window.activeRequests = 0; - XMLHttpRequest.prototype.open = function(method, url, async, user, pass) { + XMLHttpRequest.prototype.send = function(method, url, async, user, pass) { window.activeRequests++; this.addEventListener("readystatechange", function() { if (this.readyState == 4) { window.activeRequests--; @@ -77,14 +80,13 @@ end } } }, false); - oldOpen.call(this, method, url, async, user, pass); + oldSend.call(this, method, url, async, user, pass); }; - var style = document.createElement('style'); style.type = 'text/css'; style.innerHTML = '* {' + '/*CSS transitions*/' + ' -o-transition-property: none !important;' + @@ -144,9 +146,13 @@ pending_ajax_requests_num.zero? || raise(Capybara::ElementNotFound) end end def pending_ajax_requests_num + req_num = page.evaluate_script("window.activeRequests") + return req_num if req_num + + stub_xml_http_request(page) page.evaluate_script("window.activeRequests") end end