Failed to Login to the site and any way to login again?

4 posts, 0 answers
  1. dabby
    dabby avatar
    3 posts
    Member since:
    Mar 2011

    Posted 30 Mar 2011 Link to this post

    Hi I have one question about the login . 

    Our Silverlight Application needs to validate the user credential, so sometimes it takes a long time to login, but sometimes login very fast.

    In WebUI test Studio, is there any way to do something as follows:

    1. Launch browser and try to login (don't know how much time it takes.)

    2. Login fail and try to login again  ( can check login sucessfully)

    3. When login sucessfully, 
    the test will be still running for the remaining task.

    Could you please tell me how I can put additional code in the following code?

                 Manager.Settings.EnableSilverlight = true;
                Manager.LaunchNewBrowser();
                ActiveBrowser.NavigateTo(URL);

                Thread.Sleep(5000);

     
    Thanks,

    Dabby

  2. Stoich
    Admin
    Stoich avatar
    1 posts

    Posted 01 Apr 2011 Link to this post

    Hello Dabby,
        I'm not 100% sure I understand what you're trying to do. Basically you want your test to keep attempting to Login until it manages to do it successfully?

    First off: you can to that without writing any code at all. Test Studio is designed so that coding is only a last resort.
    In your case you it seems like you can take advantage of Test Studio's While loop feature. Check out this article:
    http://blogs.telerik.com/blogs/posts/10-11-09/q3_2010_-_creating_loops_with_webui_test_studio.aspx
    As you can tell the While loop works identically to a While loop seen in programming languages based on the C syntax.

    Here's the general idea: you need to create a Verification that will verify that you're not logged in. For instance if your Login page might have a button labeled "Login". You know that if the button is present on the page - you haven't logged in yet. So we record a "WaitForExists" verification on this button.

    Next we add the While loop. We put this Verification in the the While loop in order to use it as a condition. What happens now is this loop will execute ad infinitum while the Login button is there (i.e. we haven't logged successfully).

    Create a separate test that executes all your Login steps. Let's say it's called LoginSubTest.
    Now put this test as a TestAsStep in your While loop. If you're not familiar with "Test As Step", look it up in the guide:
    http://www.telerik.com/documents/automated-testing-tools/WebUITestStudioDeveloperEditionQuickStartGuide.pdf

    Also, it's a good idea to put a fixed delay in the loop after the Logic TestAsStep. This delay should be enough for the Login to work otherwise you might get stuck in an endless loop. Check out the manual if you don't know what Delay Steps are.

    This is a basic solution for your automation task. I realize that this is probably not a very good explanation if you're just getting into the product: try to get it to work and don't hesitate to contact us again if you require additional assistance.

    Hope to hear from you soon!

    Regards,
    Stoich
    the Telerik team
  3. dabby
    dabby avatar
    3 posts
    Member since:
    Mar 2011

    Posted 01 Apr 2011 Link to this post

    Yes , you are right. Basically I want my test to keep attempting to Login until it manages to do it successfully.

    Thanks for your instruction. I tried it, but the test failed .  I can’t login to the site using while loop because this error shows up immediately.

     System.TimeoutException: Wait for condition has timed out.

     Because I am new to Web UI Test studio, I can’t see the code when doing right click. Besides, customize step in code is disabled.

     
    Do you mean something like

    While (true)

    {

    Manager.Settings.EnableSilverlight = true;

    Manager.LaunchNewBrowser();           

    ActiveBrowser.NavigateTo(URL);- this line will fail if the time is not enough
     

    }

    Or

    For (int i=0; i<5 ; -++)

    {

     Manager.Settings.EnableSilverlight = true;

     Manager.LaunchNewBrowser();      

         

     ActiveBrowser.NavigateTo(URL);---this line will fail and will not do the 5 times attempt

     

    }

    I tried your recording tool and use loop count (5);  ActiveBrowser.NavigateTo(URL) will always fail.
    Is there any way to do the mutltiple attemps?

    Thanks,

    Dabby

  4. Stoich
    Admin
    Stoich avatar
    1 posts

    Posted 06 Apr 2011 Link to this post

    Hello Dabby,

          loops in code are different from Loops added from the GUI (screenshot 1). GUI loops can't be converted to code. I believe you won't need any code for what you're trying to do.

    I will put together a little example and explain it step by step:

    Let's say I want a test that will try to login to my Telerik account until it succeed.
    First thing I do is go to the Telerik page and login. I record all the necessary actions for this and save it as a separate test called Login (screenshot 2). 
    When you create your login portion - make sure you set ample WaitOnElementsTimeout times to assure that the elements do actually appear.

    Now I create a new test "main" and I pick up where I left off. The recorder is already on the Telerik page and I'm logged in. Since I'm logged in I can see a button labeled "Log out". Because this button is there I can tell that I'm logged in. I record a step "Wait Doesnt Element Exists" on this button (screenshot 3). 
    Now I add a While loop and put the Wait steps as a condition. So now our loop will execute until it finds that button (i.e. until we're logged in). Now we add Login as a TestAsStep and put it inside the loop (screenshot 4).

    That's it - this will execute until it has managed to login. You should apply the same approach to your own automation task. I've attached the whole TestProject, you can explore it and run it. It will execute indefinitely since I change my user/pass to random things (for obvious reasons).

    The only drawback to this is that it really will execute indefinitely. There are many waits to work around that but they all involve code. You can try using a FOR loop in order to try to login a set number of times but the problem there is that it will run all the iterations no matter whether it logs in. 

    I hope this helps, let me know how it goes! 

    Greetings,
    Stoich
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top
  Cast Your Vote at DevPro Connections! Cast Your Vote at  Win IT Pro Connections!