I have to load some seed data for my tests. I'm having a really hard time making sure the seed data has loaded completely before the tests begin running.
In the beforeAll block I'm calling an adapter I wrote for my API that clears out any data, loads a specified file of seed data and then runs a callback passed in from the protractor test file.
I can't include the test cases in a callback (this seems like it would be a similar blocking issue to refactoring to promises) or protractor doesn't recognize them.
Can anyone suggest a way I can make sure my API has been successfully seeded before the tests begin?
Thanks!
If you are using Jasmine 2.1 or higher with Protractor you can make use of the done() function in your beforeAll.
So if you have a function called seedMyDataAsync() that takes a callback function as a parameter, you could do something as simple as this:
beforeAll( function(done) {
seedMyDataAsync(done);
});
The done() function was introduced with Jasmine 2.0, but wasn't available for beforeAll() until Jasmine 2.1.
From the documentation:
Calls to beforeAll, afterAll, beforeEach, afterEach, and it can take an optional single argument that should be called when the async work is complete.
By default jasmine will wait for 5 seconds for an asynchronous spec to finish before causing a timeout failure. If the timeout expires before done is called, the current spec will be marked as failed and suite execution will continue as if done was called.
Related
In our application we are calling every minute to our feature flags service using angular therefore browser.waitForAngular() always fail.
is there a way to use browser.waitForAngular() and make it ignore this specific feature flag call (API call that is being called every 60 secs) so we can still use the wait for angular and not implement waits on the code?
There is an option to enable/disable waitForAngular which may be used to disable for pages where polling is happening and enabled again later for other pages..Check the below link
browser.waitForAngularEnabled
All,
I'm a beginner to Angular framework and have been reading $http service. I thought I understood Promise object in Angular JS until the below questions popped up my mind. Can you please help me understand?
– When I make a REST call from Angular, Angular work not make the rest call before it executes the other steps in the js from where the REST API is invoked. This is because it’s single threaded. Okay I get this. So when does it execute the REST call? May be after all the instructions in the current JS are done? If yes,
Why do we even call it asynchronous?
Secondly, during the time it executes the REST API (let’s say the REST API results in an output not before 2 seconds), right after it calls REST API would Angular just wait for the 2 seconds without doing anything?
If $http service executes the REST API asynchronously as soon as it sees it,
Who spawns the second thread to execute the REST API? The framework? If so then are they making Javascript no longer be uni–threaded?
Secondly when the service returns while the main thread hasn’t even completed executing all the lines in my js, does Angular/jQuery goes and executes the instructions coded in the .then function, leaving the instructions in the main thread waiting?
Thanks much for your help!
Prem
When I make a REST call from Angular, Angular work not make the rest call before it executes the other steps in the js from where the REST API is invoked
No. That is incorrect. It sends the request immediately. But it doesn't block until the response comes back, because that could take a whole lot of time and completely freezes the application. So instead, it registers a callback, and this callback will be called, later, when the response is available. That's the principle of asynchronism.
Who spawns the second thread to execute the REST API
There is no second thread.
The easiest way to look at it is to consider that an HTTP response is an event, just like a click or a keypress. All the unique thread does is to wait for the next event and react to it, in a loop.
First of all, it wont block the execution, it sends the request immediately. Basically it follow the promise pattern which uses the concept of callback function. So whenever API returns the response it calls the callback function and resume the process.
There is no concept like second thread. When HTTP return the response the execution doesn't stop. it just call its callback method and after that excute the remaining line of code
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
I'm using protractor to run some end-2-end tests for an Angular application, and from what I can tell, all the specs I specify in my config file end up sharing the same instance of protractor's browser.
Normally this wouldn't be a problem, but I am also using http-backend-proxy to set up mock responses to my application's ajax calls. This module uses the browser instance, and it seems that setting up mock responses in one spec pollutes the browser instance for subsequent specs, causing all the specs to use the mock response strategy defined in the first spec.
Obviously this creates some problems for test isolation.
Has anyone dealt with something similar?
[edit]
I did not find a way to create multiple browser instances, but did find a way to deregister http-backend-proxy responses between tests, which accomplishes the test isolation I was looking for. For future reference to anyone that runs into this same problem, I was using:
proxy.onLoad.when()
setups to handle my mock responses. You can deregister these with:
proxy.onLoad.reset()
If you place these in beforeEach() and afterEach() blocks, respectively, you can accomplish isolation both between tests within a given spec, and between separate spec files.
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.