3

I have many tests that require certain preconditions to be met before continuing and thought I could write a simple function like:

Function FailIfNot(condition, error_message)
    If Not condition Then
        WriteToALM FAILURE, error_message 'convenience function
        ExitScript
    End If
End Function

I've searched online, but can't figure out which Exit* function I should use. Each test case consists of a single action which covers a particular interaction with the application and once developed is run in "batch mode" with all the other test cases by ALM (in development I execute it as a temporary run). Ideally the function should go in a library that is shared with other test scripts, which seems to further complicate it.

Hope I'm not reinventing the wheel here.

Pranav
  • 437
  • 3
  • 19
Samuele Pilleri
  • 734
  • 1
  • 7
  • 17
  • 1
    Look at the `ExitIteration` command – Dave May 20 '19 at 13:46
  • @Dave what's the difference between that and `ExitTest`? – Samuele Pilleri May 22 '19 at 10:05
  • 1
    `ExitTest` stops the test from running, while `ExitIteration` stops the current iteration of data and moves onto the next one – Dave May 22 '19 at 16:52
  • @Dave I guess it doesn't have to do with classic loops, what do you mean with iteration? – Samuele Pilleri May 22 '19 at 20:13
  • 1
    When you create a test, you can set it to run "on all iterations", "one iteration only" etc. If you set it for all iterations, you then write the code to process a single run of the test, and the test will execute the steps for each row of data inserted into the data table. If you set it to run one iteration only, then it executes a single time regardless of how many rows there are - although you can build your own loop to iterate through the datatable that way – Dave May 22 '19 at 21:57
  • @Dave For some reason using any kind of `Exit*` doesn't write the report to ALM, and when you try to launch the last run report it says "Run Results for this run session are not available in ALM". Any idea why? – Samuele Pilleri May 23 '19 at 12:17

1 Answers1

4

I think what you're looking for is 'ExitTest'. Built in function that will exit the running test.

For example I have a EndTest function, and will call it from an if statement. So:

If condition = true
    'do something
Else
    Call EndTest(micFail, "reason", "step")
End If

The EndTest function looks like this:

Function EndTest(strEvent, strReason, strDescription)
    reporter.ReportEvent strEvent, strReason, strDescription
    ExitTest
End Function
Zoette
  • 1,241
  • 2
  • 18
  • 49
Corey Snow
  • 225
  • 2
  • 15
  • I was looking for something exactly like that, can you confirm it works in recent (12.50+) versions of UFT and doesn't break ALM? – Samuele Pilleri May 22 '19 at 08:03
  • 1
    We have been using UFT version 14.03 with ALM version 12.50.32 for almost a year now and haven't had an issue with this. We've used it on previous versions as well. – Corey Snow May 22 '19 at 17:47
  • I've tried your solution, but for some reason using any kind of `Exit*` doesn't write the report to ALM, and when you try to launch the last run report it says "Run Results for this run session are not available in ALM". Any idea why? – Samuele Pilleri May 23 '19 at 12:19
  • Are you doing a reporter.ReportEvent before the exit command? I'm not sure the ExitTest command has built in reporting, that's why in the function we use it does the reporter.ReportEvent command to report back before it exits. Maybe you could share your exact code – Corey Snow May 23 '19 at 18:59
  • Yes, I was issuing that command. I've debugged it for a few hours, then cleaned Cookie/Cache/ActiveX/... in IE and it started working with `ExitAction`. Hope it doesn't break. Thank you for your help! – Samuele Pilleri May 24 '19 at 08:22