Test end event/trigger
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Test end event/trigger
Hi all,
I may be asking the wrong questions so I'll just explain what I'm trying to do:
When a TestComplete completes running, I am having it go to an url, which is basically a REST api to trigger the next run (we built an internal web app to queue tests).
So first, I tried putting this rest api trigger at the end of a script. But that's not good enough - because in the event the run gets some exceptions, I dont get to the api part.
So next, I tried to use a try-catch block to catch any exceptions. If exception, then trigger api. This is slightly better, but what if a run is not going as expected and someone ends the run manually.
I need a general way to say, if this test complete run finishes, do this.
Solved! Go to Solution.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
OnStopTest event (https://support.smartbear.com/testcomplete/docs/reference/events/onstoptest.html) seems to be what you are looking for...
/Alex [Community Champion]
____
[Community Champions] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Champions]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Champion] signature is assigned on quarterly basis and is used with permission by SmartBear Software.
https://community.smartbear.com/t5/Community-Champions/About-the-Community-Champions-Program/gpm-p/252662
================================
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks! That seems to do the trick.
Seems like the event code doesnt work unless I add in an actual event to the project. If only there's a code-only solution...
But thats okay! This will do for now.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
A code only solution would be try/catch/finally.... in the "Finally" block, trigger your code. Finally will run ALWAYS... if there's an exception, "catch" will run... then "finally" runs. If there is no exception, the "catch" block is ignored but "finally" still runs.
Robert Martin
[Hall of Fame]
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
Vegas Thrill Rider
Extensions available
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks!
I think try catch wasnt ideal because it doesn't guarantee that the test will end in the try block, so it can't reach catch/finally.
I can put the entire code inside a try block, but I feel that's a bigger sin. The event based solution seems perfect. Its just unfortunate it only works when you add "Events => GeneralEvents" onto the project itself.
On top of that I also had to add:
function GeneralEvents_OnStopTest(Sender) { Common.openUrl("http://localhost:1337/next") }
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Wrapping all the code in a test case in a "try" block is actually not a bad idea... what happens if something unexpected happens during the execution of your test code? The "try" will catch anything unexpected... So, that's really a pretty good practice there.
As to your "unfortunate"... that's the way events work.... you want code to execute to "handle" an event, you first need to tell the project what events to "handle"... that's what the "GeneralEvents" does...
Robert Martin
[Hall of Fame]
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
Vegas Thrill Rider
Extensions available
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yeah it'd be nice if they expose the event names so we can act upon it.
Can't I just tell it what events to handle inside the code ? It works like other frameworks out there where its like button.on('click') where click is just a built in event. So if I say onStopTest in the code, the code should just compile and add a listener for the stop event automatically...
I think the try block may be stylistic preference. Actually I'd be surprised if I manually stop the run manually if it will even run the 'finally' block at all, since the code executions just stops. But I can test that out for the curiosity.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I tested it. Finally does indeed run.
Now that I think more about it a try/catch/finally block may seem like better candidates than events since this is one of those 'if anything unexpected happen' situations.
Hrmmmm. Thanks everyone for the input! Ill ponder about it more.
