question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AngularJS Protractor - How Do You Test an AJAX Login Call?

See original GitHub issue

I have a button that once clicked sends out an AJAX call in Angular’s $promise format. When the login is successful, a $scope variable is changed and an element that looks like:

<section id="logged-in-section" ng-if="auth.user !== null"> // Section to display if logged in </section>

is displayed. I am currently testing the above with the following:

loginButton.click(); browser.sleep(2000); expect($("#logged-in-section").isDisplayed()).toBeTruthy();

browser.sleep(2000) idles the browser for two seconds before Protractor checks to see if logged-in-section has been displayed. If I take out browser.sleep(2000), the test fails since there is a lag between hitting the login button and the response returned from the server.

What’s the syntax to chain the login button to the expect statement so that Protractor is only checking for #logged-in-section after the $promise is resolved?

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
shankscriptcommented, Apr 26, 2016

I hope you all would have figured out by now 😃 If not try: browser.waitForAngular

This Instructs webdriver to wait until Angular has finished rendering and has no outstanding $http or $timeout calls before continuing. Note that Protractor automatically applies this command before every WebDriver action.

Ref: https://angular.github.io/protractor/#/api?view=Protractor.prototype.waitForAngular

0reactions
juliemrcommented, Jul 13, 2016

This is obsolete now, thanks @shankscript for the good docs!

Read more comments on GitHub >

github_iconTop Results From Across the Web

AngularJS Protractor - How Do You Test an AJAX Login Call?
You can do this: loginButton.click().then(function(){ browser.waitForAngular().then(function (){ //this should wait for the angular digest process to finish ...
Read more >
Protractor: The Secret Service - Amit Gharat - WordPress.com
In a nutshell, Protractor runs tests against your application running in a real browser, interacting with it as a user would. That means...
Read more >
$http - AngularJS: API
Overview. The $http service is a core AngularJS service that facilitates communication with the remote HTTP servers via the browser's XMLHttpRequest object ...
Read more >
How to use command line arguments in Angularjs Protractor
I 'm using Protractor to perform some end to end tests, and I'd like to pass in login credentials through the command line...
Read more >
18 Quick Tips for Improving AngularJS Performance - KeyCDN
If you try to manually activate the digest cycle while it's already running, you could get an error. To prevent this from happening,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found