How to jump to a particular test-step

Best practices, code snippets for common functionality, examples, and guidelines.
ankit26
Posts: 5
Joined: Thu Jun 16, 2016 11:35 am

How to jump to a particular test-step

Post by ankit26 » Thu Aug 25, 2016 6:38 am

I have a problem here I want to skip some particular steps if the Test Case Name is say X. Can we do it in ranorex, If yes how?

Martin
Posts: 152
Joined: Fri Aug 15, 2014 12:24 pm

Re: How to jump to a particular test-step

Post by Martin » Thu Aug 25, 2016 8:03 am

Hey

If you want to skip a test case by name then you actually know beforehand what test case you want to skip.

This can be achived by run configurations. You can learn all about these from here: http://www.ranorex.com/support/user-gui ... html#c3019

But if you actually want to skip a module inside a test case related to some previous test modules outcome then you can use some creativity. For example from the top of my head what you could do is set up some variables for both modules and bind them together through databinding. (http://www.ranorex.com/support/user-gui ... sting.html)

You could set the value for the 1st variable to whatever needed (eg. true/false) by what the outcome of the 1st module is. Then catch the value in the next module and with a simple if-statement just either skip everything in that module or continue with it's flow.
public void Flow()
{
    if (varValue == "true")
    {
        UserFunction();
        UserFunction2();
    } else {
        Report.Info("Skip this module");
    }
}

public void UserFunction()
{
    Report.Info("Working on this");
}

public void UserFunction2()
{
    Report.Info("Working on that");
}
Martin

ankit26
Posts: 5
Joined: Thu Jun 16, 2016 11:35 am

Re: How to jump to a particular test-step

Post by ankit26 » Thu Aug 25, 2016 1:34 pm

I wanted to skip test-steps in a single module not modules or test case

Martin
Posts: 152
Joined: Fri Aug 15, 2014 12:24 pm

Re: How to jump to a particular test-step

Post by Martin » Thu Aug 25, 2016 1:38 pm

Nevertheless this code example fits perfectly.

The key here is if-statements. Makes it even easier.
public void Flow()
{
    if (varValue == "1")
    {
        UserFunction();
        UserFunction2();
    } else if (varValue == "2") {
        UserFunction();
    } else if (varValue == "3") {
        UserFunction2();
    } else {
        Report.Info("Skip everything");
}

public void UserFunction()
{
    Report.Info("Working on this");
}

public void UserFunction2()
{
    Report.Info("Working on that");
}
If you are just getting into working with user code methods you can always convert your recorded test steps to user code (right click -> Convert to user code) and put them inside a custom method to be called upon.