0

I have a certian number of scripts that i run in a batch runner. I want that if a test fails, it should run again once.

i want to programatically re run the test incase it fails or enters a recovery scenario.

Thanking you in advance.

0

Rerun failed test from launching vbscript

You can check test run status in VBScript and start the script from command line:

cscript.exe run-test.vbs [some params]

run-test.vbs would contain something like:

Dim qtApp
Dim qtTest
Set qtApp = CreateObject("QuickTest.Application")
qtApp.Launch
qtApp.Visible = True
qtApp.Open testPath, False
Set qtTest = qtApp.Test
Set qtResultsOpt = CreateObject("QuickTest.RunResultsOptions")
qtTest.Run qtResultsOpt, True
...

Here is a the line of code you need to check after Run command:

...Not (qtTest.LastRunResults.Status = "Passed")

And rerun test in loop with two conditions test passed or number of runs is over

Here is a link to full run-test.vbs on git (sure you need to add your rerun part)

Rerun from Recovery scenario

And another possibility to restart test on fail with Recovery Scenario:

restart test on fail in recovery scenario

But test will run in a loop untill it passes or forever if it always fails. After rerun all variables in test would be lost so you need to save runCount in an external file.

The sequence of steps in this case:

  1. On test start read external file and save value in global variable runCount
  2. Check the variable runCount is less then maxRunCount. If more - reset runCount to 0 in external file and exit test.
  3. Then goes execution of test body.
  4. Here comes an error.
  5. Recovery scenario is configured to call Recovery Function:

enter image description here

  1. In Recovery Function runCount is incremented and saved to external file.
  2. If test executes successfully reset runCount in external file to 0

So I think it's better to control run count from external VBScript test executor.

  • thanks, this is helpful is there also some way i can handle the restart in my test script and not a separate vbscript since i run them in a batch runner? I mean if any error comes up, a recovery scenario will be invoked in which i call an action. can i put a block of code for the restart there ? if yes what would it look like? – Sohaib Jamal Jun 10 '16 at 7:27
  • @SohaibJamal I edited my post and explained why it is better not to rerun test with recovery scenario. BTW you bath runner can run vbscript file run-test.vbs. Is there any problem? – Ivan Gerasimenko Jun 10 '16 at 8:16
  • yes this issue did cross my mind. youve been very helpful. thanks alot :) – Sohaib Jamal Jun 10 '16 at 8:25
  • and is there some way i can code a line which restarts the script and call that action in my recovery scenario? if that can be done i can keep an external file which i already as using for my scrpts – Sohaib Jamal Jun 10 '16 at 9:35
  • @SohaibJamal, check the last edit, it shows basic steps. – Ivan Gerasimenko Jun 10 '16 at 11:32
0

If you use ALM you can define in the Execution Setting of the test what to do if the test fail.

enter image description here

In there "On failure" field you can choose "Do Nothing" or "Rerun the test".

If you choose "Rerun the test" the other two field are enabled.
In those fields you can define how many times the test should be rerun and a script to run to cleanup the environment between the reruns.

  • my re run technique or logic works fine when executing independently, but it gives me an error when in batch runner. it says Object reference not set to an instance of an object. source: HP.QTP.Backend.Entities – Sohaib Jamal Jun 28 '16 at 7:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.