cancel
Showing results for 
Search instead for 
Did you mean: 

Login to the application only if not already logged in

Contributor

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?

 

Regards

Partha Mandayam
Software Consultant
3 REPLIES 3
Contributor

Re: Login to the application only if not already logged in

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.

Contributor

Re: Login to the application only if not already logged in

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.


 

Regards

Partha Mandayam
Software Consultant
Community Hero

Re: Login to the application only if not already logged in

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.


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Extensions available