protractor is not waiting for ui-router to change state - angularjs

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!

Related

Protractor browser.driver.getCurrentUrl vs browser.getCurrentUrl

I'm running an Angular app and I'm trying to get the current URL when testing on protractor. Which one to use?
browser.driver.getCurrentUrl() or browser.getCurrentUrl() ?
If this is an Angular application under test - use browser, otherwise - browser.driver.
To quote #jmr from a relevant github issue:
If you need to interact with a non-Angular page, you may access the wrapped webdriver instance directly with browser.driver.
Though, note that both are gonna work if this is Angular application under test. Some people even said that found browser.driver more reliable if it the sync time is longer than usual:
Just to add to this - I find that browser.driver works better on AngularJS apps that take time to sync. I have tried both and for some reason browser.driver is more reliable.
Though, I've personally used browser.getCurrentUrl() and cannot recall any problems.

Protractor: Polyfill Function.prototype.bind in PhantomJS. Can't make it work, is it even possible?

I've spent the afternoon on this and am making no progress, I'm really starting to wonder if it's even possible.
I'm using Angular with Headroom to handle a menu disappearing when scrolling down. My testing is done with Protractor, using PhantomJS, and this is where the fun begins.
PhantomJS does not support .bind() and Headroom uses it all over the place, which means I need to polyfill it. It should be no problem, but I can't make it work.
I think my problem is that no matter where I run the polyfill function, PhantomJS and the tested page are already loaded, so it's already too late, Headroom will have failed to load due to .bind() not being available.
Is there any way to run those methods before the page is loaded? I know I could add them to my application via a script tag in the head, but I'd rather not add something to the whole app that will only be used by the testing framework.
I think I have a workaround for that. (at least give it a shot and we'll see if it's working or not) The best u can do is to patch your phantomJS browser to have this method supported. Basically u should run a script before every specs, so that it can apply to the global scope and will be available to your specs.
Just try to extend your specs configurations. Here is an example:
...
specs: ['my_phantomjs_bind_patch.js', 'webtests/**/*.js']
...
You cant run scripts before the actual page load as they are a part of the dom tree .What you can do is : `
window.onload = function() {
//do something
};
but even when the onload event is fired the tag must be rendered. So you should try your idea and add one script tag before all other elements to your html and run the code there, if it's just for a test run.
`
`

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!

Angular $http.delete has no callback when succeding

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.

Get the ExtJS Active Ajax call count

I am working in selenium to test the ExtJs application. My problem is, I need to ensure the page is completely rendered. I cant use selenium.waitForPageLoad. In normal Ajax application i can use "Ajax.activeRequestCount", which will give the Ajax call count. If it is '0' We can ensure the page is completly loaded. Is there any similar function available in ExtJs? Can any one pls help me on this
There is no such method in ExtJs. You can however create handlers for global Ext.Ajax events beforerequest and requestcomplete http://docs.sencha.com/ext-js/4-0/#!/api/Ext.Ajax-event-beforerequest and count active connections yourself.
Or, if the Selenium tests are to be run in modern browsers, you could try Progress Listeners (with these).
For Firefox, you could create a simple addon that would wait for async requests to complete, and ship that addon with your Selenium tests.

Resources