Results 1 to 7 of 7
  1. #1

    How to Skip the lines of code during execution


    By any chance, can we ignore or skip number of lines of code and continue our execution?

    For Ex : I am executing a Script which has 30 lines of code, i got a error in 10th line which obviously paused the execution, i know that next five lines(11- 15) contains an error, at this stage can we directly continue our execution from 16th line by skipping those five lines.

  2. #2

    Re: How to Skip the lines of code during execution

    you can use On Error Resume Next

  3. #3

    Re: How to Skip the lines of code during execution

    On Error Resume Next goes to the immediate line and tries to execute it.

    If you have chunk of the code in for loop you can exit the loop by using

    On Error Resume Next
    exit for

    In the similar way you can use ExitAction or ExitIteration

    But i do no know of any methods which would skip execution of few lines of code.

    Its better you write that chunk of code into a seperate action and use the exitaction along with on error resume next as shown above.

    Hope this will be helpful


  4. #4

    Re: How to Skip the lines of code during execution

    Thanks for your info......

    The above examples will work only when we have that particular code before starting the execution but in my situation,only when i execute i found those lines cannot be executed and i wanted to skip at that time using any QTP commands...i am not very sure whether its possible or not??

  5. #5

    Re: How to Skip the lines of code during execution


    The lines which you want to skip, prefix your code with "OptionalStep" to make the step optional. It means, at Runtime, QTP will try to exeucte the line and if the step could not be executed due to some reason, that line will be skipped.

    Ex: OptionalStep.Browser("Google").Page("Google").WebB utton("Google Search").Click

    To make number of lines skipable, wrape them with "With" statement.

    Try it and let me know how it goes.


  6. #6
    Advanced Member
    Join Date
    Mar 2007
    Salt Lake City, UT, USA

    Re: How to Skip the lines of code during execution

    One way:

    Add On Error Resume Next right before line 10.

    Right after line 10 (before line 11 is executed) add:

    If err.number = 0 Then
    (put all the lines of code you might want to skip right here - they will execute if there was no error in line 10)
    (maybe add a reporter.reportevent to describe the error in the test results log)
    err.clear 'to clear the error
    End If
    On Error Goto 0 'reset error handling

    This will execute line and, if there is no error, those lines inside the If..End If block will be executed, but if there was an error, those lines will be skipped.

    Disclaimer: I haven't tried this for several years and my memory might be faulty, and at a glance the err object seems poorly described in QTP help, so I apologize if the syntax is wrong - hopefully it's either correct, or close enough you can fix it easily enough.
    "The last 10% of any software project will take 90% of the budgeted time. The first 90% will take the other 90%"

  7. #7

    Re: How to Skip the lines of code during execution

    Another way:

    Separate your lines,
    you want to skip in case of Error into Sub.

    Something like that:

    Sub MyOptionalSteps()
    End Sub

    Then in your code:

    If NOT (ConditionWhenErrorComes) Then
    End If

    QTP will execute your Sub only if condition will be TRUE -
    if not Error comes in RunTime.

    As for QTP Function "OptionalStep" - it will be good for one line, but will fail for multiple lines.




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
BetaSoft Inc.
All times are GMT -8. The time now is 07:27 PM.

Copyright BetaSoft Inc.