cancel
Showing results for 
Search instead for 
Did you mean: 

stopping execution of a keyword test in script

Occasional Contributor

stopping execution of a keyword test in script

Hello,

 

After calling KeywordTests.TestName.Run via a script, is there any way to stop execution of the keyword test and continue through the remainder of the script?

 

Calling Runner.Stop(True) just ends the entire process, I am hoping for a way to have the runner continue stepping through the remaining code

6 REPLIES 6
Community Hero

Re: stopping execution of a keyword test in script

Within the Keyword test, there is a "Stop Execution" operation that you can add in to halt the execution of the keyword test.  I'm assuming that you want to have a condition in the keyword test that, if the condition fails, that you halt the execution. I'd use that "Stop Execution" operation for that.


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
Occasional Contributor

Re: stopping execution of a keyword test in script

That gives the same functionality as if Runner.Stop were called in my error event script, which isn't what I'm needing.

 

I'm calling multiple keyword tests to run via a script, and I'm trying to think of a way to write it out so that if an error occurs during the execution of a keyword test, it stops trying to run the keyword test and then continues on to the next line of code in the script.

 

Being able to simply put in my code something like "KeywordTests.TestName.Stop" would be simplest way to go about it, but that isn't valid code. (At least not for VBscript)

Community Hero

Re: stopping execution of a keyword test in script

You are correct, I just tried it.  The "true" parameter for stopping a current test item stops because running the script is a "test item".

 

OK, there is something else to look at as well.

 

Go to Tools | Current Project Properties | Playback and check what the setting is for "On error" in the Error Handling section.

 

Additionally, something to try is to use exception handling in your keyword test to control the halting of the test.  Use "try/catch/finally" to control test control flow.  


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
Occasional Contributor

Re: stopping execution of a keyword test in script

Yeah that setting is set to False (most of those are). I'm currently in TestComplete 12.

 

Are Try/Catch/Finally valid operators in VBscript? I was under the impression that they were not. Although that would probably be the easiest option to catch the error if I could just do

 

Try

KeywordTests.TestName.Run

Catch

<error handling>

 

But I was under the impression that those were not valid operations for VBscript.

 

Or are you talking about enclosing the actions of the keyword test itself in a Try/Catch using the TestComplete Methods?

Community Hero

Re: stopping execution of a keyword test in script

Actually, what I meant was using try/catch/finally in the keyword tests themselves.  Build into the tests exception handling and such that they can cleanly exit out when desired so that your script code can continue.  


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
Highlighted
Community Leader

Re: stopping execution of a keyword test in script

@Ag3nt49 

 

I've recently been looking into doing something quite similar.  In some cases I find one KWT is a prerequisite for the next, but just because KWT 1 failed, doesn't mean I can't run KWT 3  - I just want to skip over KWT 2

 

The approach I'm using is to always have my KWTs themselves return a true/false

 

The entrie KWT is in a Try/Catch/Finally structure.

 

If it falls through to the catch, you will obviously return false

 

If it reaches finally you will have to figure out if you want to return a true or a false.  Sometimes I use a KWT level boolean variable and if, say halfway through my KWT an object recognition fails, the variable is set to false and I insert a Go To Label.  The Finally block can then return the value of the global variable.

 

When you call the KWT from a script, you should now be able to assign the output of the KWT.Run() to a variable.

 

e.g.

var kw1tpassed = KWT1.Run();

if(kwt1passed)

{

  KWT2.Run();

}

else

{

  Log.Warning("KWT1 failed.  Check your logs");

}

 

KWT3.Run();


-------------------------------------------------
Standard syntax disclaimers apply
Regards,