Execute Testcases in loop

4,663 views
Skip to first unread message

Maha Lakshmi

unread,
Feb 3, 2012, 8:06:13 AM2/3/12
to robotframework-users
Hi,

I m new for RobotFrameWork.

Is is possible to execute the testcase in multiple times in some
looping with different values.

I am having the following scenario :
1. Need to configure multiple boards with different parameters.
2. Single testcase exists to configure a board with the given
argument.


Need to execute that single testcase with different parameters in some
looping of that testcase.

Please provide me a solution how to handle it in Robot Framework.

I have seen the for loop used for keyword execution repetition. Will
it work for testcase looping?

Gaurav Arora

unread,
Feb 3, 2012, 9:03:18 AM2/3/12
to maha.v....@gmail.com, robotframework-users
Hi,

You can abstract away the contents of a test case into separate keywords and then call them repeatedly. So you do something like this in the for loop:
1. Call keyword to configure board
2. Call keyword to perform actual test


Gaurav


--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To post to this group, send email to robotframe...@googlegroups.com.
To unsubscribe from this group, send email to robotframework-u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/robotframework-users?hl=en.


Taylor, Martin

unread,
Feb 3, 2012, 9:04:40 AM2/3/12
to maha.v....@gmail.com, robotframework-users
Hi Maha,

I agree that this would be a very useful feature in Robot Framework and I asked for it a few years ago
http://code.google.com/p/robotframework/issues/detail?id=319
Unfortunately the RF developers said it was "too hard" to do and marked the issue WONTFIX.

You can fake this behavior by moving all your steps for a test into a user-defined keyword and then looping execution of the keyword with a :FOR, but that really defeats the purpose of test case reuse. It would mean that ALL test cases would have to be written as user-defined keywords and every test case would be a single line, calling the corresponding user-defined KW. That's a PAIN to maintain, so I've only ever done this for a few select tests and I end up with steps to maintain in the user-defined KW AND in the original test case.

Cheers,
Martin

Hi,

--

Mikko Korpela

unread,
Feb 3, 2012, 10:58:16 AM2/3/12
to robotframework-users
Hi,

I've implemented something that could help you achieve what you are
looking for: https://github.com/mkorpela/RoboMachine

The tool can be used for generating a number of Robot Framework test
cases from a set of input values.

@Martin: Why doesn't the Test Template setting work for you?

On Feb 3, 4:04 pm, "Taylor, Martin" <cmtay...@ti.com> wrote:
> Hi Maha,
>
> I agree that this would be a very useful feature in Robot Framework and I asked for it a few years agohttp://code.google.com/p/robotframework/issues/detail?id=319

Taylor, Martin

unread,
Feb 3, 2012, 12:00:51 PM2/3/12
to mikko....@gmail.com, robotframework-users
Hi Mikko,

I've never figured out the use of Test Template, so I don't understand why it would be useful in this context of being able to call a test case from inside another test case. Please explain.

Thanks,

Mikko Korpela

unread,
Feb 3, 2012, 1:44:03 PM2/3/12
to Taylor, Martin, robotframework-users
Hi Martin,

After reading comments on the issue you linked in your first post and some other related posts, I don't think that Test Template is the right tool for what you are trying to do.

RoboMachine might be :P

Also the Parallel library 1# has the ability to execute tests from inside of another tests. This is done in another pybot process - so that might be a problem.

1# http://code.google.com/p/robotframework/source/browse/proto#proto%2Fparallel

--
Mikko Korpela

Pekka Klärck

unread,
Feb 8, 2012, 5:52:00 PM2/8/12
to g.a...@iontrading.com, maha.v....@gmail.com, robotframework-users
2012/2/3 Gaurav Arora <g.a...@iontrading.com>:

>
> You can abstract away the contents of a test case into separate keywords and
> then call them repeatedly. So you do something like this in the for loop:
> 1. Call keyword to configure board
> 2. Call keyword to perform actual test
>
> See http://robotframework.googlecode.com/hg/doc/userguide/RobotFrameworkUserGuide.html?r=2.6.3#creating-user-keywords
> on how to create user-keywords.

This is a very good general approach. If you have a finite set of
values you want to go through, it might be easier to simply create
"normal" data-driven test cases [1]. These two approaches can also be
combined by using for loops with test templates [2].

[1] http://robotframework.googlecode.com/hg/doc/userguide/RobotFrameworkUserGuide.html#data-driven-style
[2] http://robotframework.googlecode.com/hg/doc/userguide/RobotFrameworkUserGuide.html#test-templates

If you are interested about model-based testing, then looking at
RoboMachine proposed by Mikko is probably a good idea.

Cheers,
.peke
--
Agile Tester/Developer/Consultant :: http://eliga.fi
Lead Developer of Robot Framework :: http://robotframework.org

Pekka Klärck

unread,
Feb 8, 2012, 6:01:11 PM2/8/12
to cmta...@ti.com, maha.v....@gmail.com, robotframework-users
2012/2/3 Taylor, Martin <cmta...@ti.com>:

>
> I agree that this would be a very useful feature in Robot Framework and I asked for it a few years ago
> http://code.google.com/p/robotframework/issues/detail?id=319
> Unfortunately the RF developers said it was "too hard" to do and marked the issue WONTFIX.

The main reasons we decided not to implement this issue were that a)
implementation is far from trivial, b) there are many open questions
regarding where keywords and variables used by the executed tests
should be searched from, and c) it is possible to use user keywords
for this purpose. Keywords are also more flexible and easier to reuse
as they can take arguments.

We don't, however, have anything against adding this feature if the
community considers this an important feature and someone is willing
to implement it.

aqeels...@gmail.com

unread,
Jan 12, 2018, 5:56:39 AM1/12/18
to robotframework-users
Hi, i have a code which consists of two for loops nested for loops. Now i am asked to calculate the test cases of that code. But i am facing some problems that how do i calculate the test cases. Here is the code.


void main()

            {

                        int number;

                        cout << "Enter number: ";

                        cin >> number;

 

                        for(int i = 2; i <= number; i++)

                        {

                                    int prime = 1;

                                    for(int j = 2; j <= i/2; j++)

                                    {

                                                if ((i%j) == 0)

                                                {

                                                            prime = 0;

                                                            break;

                                                }

                                    }

                                    if (prime == 1)

                                    {

                                                cout << setw(10) << i << endl;

                                    }

                        }

            }

Reply all
Reply to author
Forward
0 new messages