1

I'm new to Angular and Protractor.

I'm using protractor to test Angular pages. I'm trying to test log-in procedure.

part of the html is:

< li data-ng-show="isLoggedIn()" >

I want to make sure that the credentials are correct by calling the 'isLoggedIn()' function. the 'isLoggedIn()' function is in a controller named 'navControl'.

can I do it? How? are there other suggestions to test log-in?

2 Answers 2

2

You should be testing your log in page (if you are using protractor) like a user - enter some text in your login form, then click the 'Log In' button! After this, inspect the page for whatever elements you are expecting to be visible after a user has logged in. You shouldn't really be directly calling your application functions - testing those falls under unit testing, not e2e testing for which Protractor is designed for :)

Sign up to request clarification or add additional context in comments.

3 Comments

thanks for answering. the question is how to do it. the < li > element that I have posted is the element that changes when logged in. it turns to 'show'. how can I check it?
You need to read up on the two things you are using; ng-show will simply add the ng-hide css class to an element when it should be hidden, and will remove the ng-hide css class when the element should be shown. (Taken from the docs, here.) Next, in protractor, you want a test that checks to see if your <li> element is shown - to do this you can check to see if it has the css class I mentioned. Examples of how to do this can be found on the Protractor help, here.
(continued) - Your test might check for the existence of the class with a line similar to this: expect(hasClass(element(by.id('my_list_id')), 'ngHide')).toBe(true);
1

Thanks for helping. The exact phrase I was looking for is this:

expect($('[data-ng-show="isLoggedIn()"]').isDisplayed()).toBeTruthy();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.