This is a migrated thread and some comments may be shown as answers.

Best way to handle a Login

1 Answer 90 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
sitefinitysteve asked on 18 Nov 2010, 03:33 AM
How do you recommend handling testing pages behind a login?

...should the first part of the test hit the logout, then login
...If statement for the Login (so if it sees it, it logs in)
...Seperate login .aii, then link it in with one of the above scenarios
...?

1 Answer, 1 is accepted

Sort by
0
Stoich
Telerik team
answered on 19 Nov 2010, 04:04 PM

Hello Steve,

    I'll explain what we consider to be Best Practices when it comes to handling Login:

In the context of Automated testing modularization is a good thing. You should try to break down your test into different modules each tasked with handling a specific component - long tests aren't best practice.
More specifically on the Login: you should put all the steps associated with the Login in one test and then add this test as a step where ever it is needed (i.e. in other tests that need to login to somewhere). This approach lets you reuse the Login module and also makes it easier to establish where and why a failure in your test occured. The only time you should consider not having a separate step for login is when you can handle the login in a single step: for instance a default Windows Security Login.

In your Login subtest: 
    Before we login, we need to be sure we're logged out first. So we have to check for signs showing we're logged in and log out if necessary . For example: you navigate to the page you need to log in to. If a link containing the text "Log out" is present on the page you know you must be logged in right now. 

Unfortunately you will need to write the code that checks this yourself. I've  

I've attached a small sample test. In it I log in to my Telerik account. This is how we check whether I'm logged in:

if (Find.ByExpression<HtmlInputSubmit>("Value=Log Out") != null) {
   // Pages.DeveloperProductivityTeam.YourAccountTmUsercontrolsPublicClientnetLoginnameandstatusAscx1BtnLogoutSubmit != null) {
    Pages.DeveloperProductivityTeam.YourAccountTmUsercontrolsPublicClientnetLoginnameandstatusAscx1BtnLogoutSubmit.Click(); 
if (Find.ByExpression<HtmlInputSubmit>("Value=Log Out") != null) {
 Pages.DeveloperProductivityTeam.YourAccountTmUsercontrolsPublicClientnetLoginnameandstatusAscx1BtnLogoutSubmit != null) {
   Pages.DeveloperProductivityTeam.YourAccountTmUsercontrolsPublicClientnetLoginnameandstatusAscx1BtnLogoutSubmit.Click(); 
  }

Basically, first we test whether an element labeled "Log out" is present on the page. In your case the element indicating you're logged in may be different but the basic idea is the same. We know the element exists if it's Find Logic (in our case Find.ByExpression<HtmlInputSubmit>("Value=Log Out")  ) returns something (as opposed to null). If it exists you have to hit the logout button. First check whether this button is present (Find expression !=null) and if it is - press it. You're now ready to login.

Having this custom coded logout step at the begining of your Login subtest will save you a lot of trouble because attempting to login to a page you're already logged into will result in a failure.

Please take a look at the attached test which handles login into a Telerik account. It consists of "MainTest" and "LoginBestPractices" which is the Login substep. It "LoginBestPractices" don't forget  to chage the e-mail and password used to your own (steps 6 and 8 respectively). 

I hope this answer you question - don't hesitate to contact us if there's anything else!

Kind regards,
Stoich
the Telerik team
See What’s New in WebUI Test Studio’s Q3 Release – Friday, November 19th, 2010 at 11am EST – Register Today!
Tags
General Discussions
Asked by
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
Answers by
Stoich
Telerik team
Share this question
or