Angular $http.delete has no callback when succeding - angularjs

I'm running some integration tests with Jasmine and a custom angular-mocks module (to allow real HTTP calls).
When doing a $http.delete (HTTP DELETE) on a URL, the call is successful (backend received it) but on PhantomJS's side I don't get any callback (the promise aint resolved).
I'm not having this problem with Chrome nor firefox therefore I'm suspecting PhantomJS to be buggy somehow.
Any idea if there is something I could do ?
PS: I already filed an issue on PhantomJSs GitHub.

Well actually it wasn't no callback at all. After increasing jasmine's timeout and karma's captureTimeout to 60s and waiting for 20sec I finally got my callback.
But It's kinda weird it take so much time with Phantom.

Related

Timed out waiting for Protractor to synchronize with the page after 50001ms

I am testing AngularJS app and very new to protractor. Every time I open the browser, it gets opened and then waits for the timeout before throwing the following error on cmd.
Timed out waiting for Protractor to synchronize with the page after 50001ms
I have tried increasing the timeout limit, but always get this error.
I have also tried using all of these:
browser.ignoreSynchronization = true;
browser.driver.sleep(5000);
browser.debugger();
browser.waitForAngular();
The page loads properly and if I use Eclipse and Selenium to interact with button objects, it just works fine.
Only protractor is having Sync issues. Please Help.
Possible reasons why Protractor would time out:
Your web page doesn't implement Angular in an expected way (i.e. with an ng-app on the body tag). More often, the error you will get in this case is Angular not found on page, but a timeout isn't out of the question. Using ignoreSynchronization would fix this if it were the issue, so this one isn't you.
An HTTP request is pending or fails. Open up your dev console and check the "Network" tab when the page loads with Protractor (it may happen with Protractor and not in a manual test). If you find something failing, make sure you are issuing the request correctly. For example, if you're trying to access an HTTP endpoint through HTTPS, it's definitely possible that the request would fail and Protractor would time out.
Your page is polling $timeout or $http repeatedly. Protractor won't do anything until Angular has reached a "resting" state (all elements and data bindings are loaded and all requests have returned).
The official list of timeout reasons is here: https://github.com/angular/protractor/blob/master/docs/timeouts.md.
But if you check the Javascript console and Network requests as the page loads, you should be able to figure out what's wrong. Good luck!

Error Timed out waiting for Protractor to synchronize with the page after 11 seconds

I have a problem with my Protractor tests. My angular app uses $timeout to continuously poll something from a server. Unfortunately this lead to the following error message when I'm running my tests:
There was a webdriver error: Error Timed out waiting for Protractor to synchronize with the page after 11 seconds. Please see https://github.com/angular/protrac
tor/blob/master/docs/faq.md
How can I handle such continuously polling timeouts? Setting the browser.ignoreSynchronization to false is not a good solution in my case (when I do that I have to insert a lot of browser.sleep())
Switching from $timeout to $interval as suggested here is currently not possible in my application. Increasing the timeout is also not possible (as I said the service is continuously polling something from the server)
Is there a possibility to change the waitForAngular routine so that my test won't timeout?
Any help will be highly appreciated.
From protractor's documentation:
Before performing any action, Protractor asks Angular to wait until
the page is synchronized. This means that all timeouts and http
requests are finished. If your application continuously polls $timeout
or $http, it will never be registered as completely loaded. You should
use the $interval service (interval.js) for anything that polls
continuously (introduced in Angular 1.2rc3).
Same boat with you.
We've seen a lot of posts discussing sleep(), waitForAngular()and browser.ignoreSynchronization.
I agree with you that it is not a good idea to set: ignoreSynchronization = true, since it forces us to wait on each async process manually.
Some suggested using sleep() and then waitForAngular() together like this:
browser.sleep(10000);
browser.waitForAngular();
I do not really understand why sometimes waitForAngular() fails to wait for the page synchronization to complete, and this "double waiting" code did work.
Please see if it works in your case.
add allScriptsTimeout: 50000 in protractor configuration file
exports.config = {
...
allScriptsTimeout: 50000,
...
};
or at least this solved my issue
Changing allScriptsTimeout to a greater value than 11000 thousand fixed my problem
Timed out waiting for Protractor ...
In node_modules/protractor/lib/configParser.js, changed:
allScriptsTimeout: 25000

protractor is not waiting for ui-router to change state

I'm using protractor for system tasting my ui-router SPA application.
As I understands the documentation, protractor should wait for things to happen before/while angular is playing.
for instance, when the user click a button, I'm changing the state. So I'm like -
$('#addProductButton button').click();
and then -
expect(browser.getLocationAbsUrl()).toContain('#/products/new');
but it fails.
To work around that I'm using browser.wait until the location is good. but this is stink.
does someone knows why protractor is not waiting.
p.s
try to use browser.waitForAngular() doesn't work.
Found the problem.
I was using $provide.decorator to provide $httpbackend with some values, while using setTimeout instead of $timeout.
setTimeout got me out of angular world and protractor is not waiting for that.
njoy!

IE8 freeze caused by long synchronous xmlhttprequest from silverlight

I'm having an issue where a long synchronous request will freeze Internet Explorer.
Let me explain the context : this is a web application which only supports IE8 and which can only use Synchronous*.
We have a Silverlight component with a save button. When the user presses the button, some information is sent to the server using a synchronous XMLHttpRequest, then some other actions are done client-side in the Silverlight component.
The server-side part includes calculations that will sometime take a while (several minutes).
In short, here is the code (c# silverlight part)
ScriptObject _XMLHttpRequest;
_XMLHttpRequest.Invoke("open", "POST", url, false);
_XMLHttpRequest.Invoke("send", data);
checkResponse(XMLHttpRequest);
doOtherThings();
I know that the server does its work properly because I can see in the verbose logs, the end of the page rendering for the "url" called from Silverlight.
However, in debug mode I can see that I never reach the "checkresponse" line. After calling the "send" line, IE will freeze forever, not unfreezing once the server log shows that "url" has been processed.
Also, I tried to add "_XMLHttpRequest.SetParameter("timeout", 5000)" between the "open" and the "send" lines. IE freezes for 5 seconds, then "checkresponse" and "dootherthings" are executed. Then IE freezes again while server-side calculations are processed and doesn't unfreeze once the server is done with its work.
IE timeout is supposed to be 3 hours (registry key ReceiveTimeout set to 10800000), and I also got rid of IE 2-connexions limit (MaxConnectionsPer1_0Server and MaxConnectionsPerServer set to 20).
Last important information : there is no issue when the server-side part only takes a few seconds instead of several minutes.
Do you know where the freeze could come from (IE bug, XMLHttpRequest bug, something I have done wrong) and how I can avoid this ?
Thank you !
Kévin B
*(while trying to solve my issue with the help of Google I found an incredible amount of "use asynch" and "synch is bad" posts; but I can't do this change in my app. Switching the application, ajax loads, and all server side calculations to asynchronous is a huge work which has been quoted for our client and is a long-term objective. I need a short-term fix for now)
Silverlight virtually requires that everything be done asynchronously. Any long running synchronous process will hang the browser if run on the UI thread. If you never reach the 'checkResponse' line of code it is possible that an unhandled exception was thrown on the previous line, and it is being swallowed. You can check in the dev tools of your browser to see if there are any javascript errors. I am surprised that calling XMLHttpRequest synchronously works at all since I would expect it to lock up the UI thread. But, the solution depends on your definition of async.
You can try:
calling the sync XHR request on a background thread and then marshalling to the UI thread (eg with Dispatcher.BeginInvoke) when you are ready
setting up an XMLHttpRequest wrapper that makes the call in async mode and raises a callback in Silverlight on completion
using HttpClient or WebClient
While these options are async, they don't require your server code to be written any differently (it can stay synchronous). I have seen a web server process a call for over an hour before finally returning a response, at which time the Silverlight app raised a callback. You could even use tools like the TPL await/async, or co-routines available in many mvvm frameworks to make the code appear very procedural/synchronous while still performing its actions asynchronously.
I hope you already solved your issue, but maybe this will be helpful to whomever may come across this post.

AngularJS $http not sending GET request

In an Angular JS app I'm working on, I am using a service to periodically (in a $timeout) make a GET request to a URL in my API (both the Angular app and the API are being served from port 5000 on localhost).
For some reason, it appears that $http is not actually sending the GET. For each $http.get(), the .error() is called with empty data and a status of 0. When I check in my server log (I'm running a Ruby on Rails backend with the Unicorn gem for my server), it appears that the server never receives the request from Angular.
Here's the function in my service:
updateUserStatus = () ->
$http.get('/api/v1/status').success (statusData) ->
# update the variable and notify the observers
this.userStatus = statusData
notifyObservers()
startStatusTimeout()
.error (error, status) ->
# if there's an error, log it
console.log 'error:'
console.log error
console.log status
startStatusTimeout()
What's really odd is that it only happens sometimes. When it stops working, I can change the URL in the $http.get() to '/api/v1/status.json', and it works. For a while. Then I switch it back and it works again, for a while... obviously there is some greater issue at play.
I've been racking my brain for a few days now, and I've seen a bunch of similar issues on SO, but they all seem to be solved with implementing CORS in Angular, which I don't think is applicable to my situation because it's all coming from localhost:5000. Am I wrong? What's going on?
For reference, I'm using Angular version 1.0.7.
I had the same problem.
Check your code to see whether this happens after events that are fired from the DOM and are unknown to Angular.
If so, you need to add $scope.$apply(); after the get request in order to make it happen.
I'm fairly new to Angular so I'm not sure this is the best practice for using Angular, but it did work in my case.
See this similar question for a better explanation.

Resources