Forum Discussion

mcp111's avatar
mcp111
Contributor
6 years ago

Login to the application only if not already logged in

I'm running multiple tests in a batch

So for each test at the beginning, I need to check if it is already logged on and only if not logged on then I should login

How to write such conditional login?

 

3 Replies

  • Is there an object on the signon screen / initial log in screen that you can check if the object exists?  If yes, you know you are logged in.  If no, you know you have to log on.  BTW.  It is a best practice to start and stop your
    scripts at the same application state - for example - logged off.  This ensures when a script starts the application state is in the correct spot.

    • mcp111's avatar
      mcp111
      Contributor

      But that unnecessarily increases the cycle time if you're running multiple tests in a batch.

      It's ok if you're only running one test at a time.

      How to check if a window exists or not?

       


      jab4743 wrote:

      Is there an object on the signon screen / initial log in screen that you can check if the object exists?  If yes, you know you are logged in.  If no, you know you have to log on.  BTW.  It is a best practice to start and stop your
      scripts at the same application state - for example - logged off.  This ensures when a script starts the application state is in the correct spot.


       

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        I agree with jab4743.  A best practice is to make each test case "atomic".  It should be able to run without dependancy on any others.  Why?

         

        Well, let's say you have 200 test cases in your project and each one is dependant upon the execution of the prior ones.  If test case 199 fails, if you want to re-run it to figure out why it failed, you need to run 198 test cases unnecessarily just to validate the 199th one.

         

        Additionally, if you want to control your test project in such a way so that, if test case 150 fails, you gracefully handle it and want to move on to test case 151.  If 151 is dependant upon 150, well, you can't do that because a failure in 150 prevents 151 from executing.  This is not a problem if the test cases are constructed and run in such a way that they are independant.

         

        Yes, as you point out, this does increase run time... but the trade off, I believe, is worth it....

        Now... As for checking if an object exists....  I believe others have pointed out that TestComplete contains a GREAT amount of useful information in the help files...  a search of the help will find the following:

         

        https://support.smartbear.com/testcomplete/docs/app-objects/common-tasks/checking-existence.html

         

        Sample code is included in the help topic.  So, in your case, at the start of each test case, first step would be to execute code that detects if the login screen is currently displayed.  If so, run a login routine.  If not, continue with the test case.