run Test Setup in specific test cases

1,167 views
Skip to first unread message

anarc0der

unread,
Sep 14, 2016, 2:36:34 PM9/14/16
to robotframework-users
Hi all...

Is possible to run a Test Setup in just specifics tests of my file?

Ex:

Test Setup  |  Run My Keyword  |  Test 1 | Test 2 | Test 4
 
Test 1
Test 2
Test 3
Test 4



Tatu Aalto

unread,
Sep 15, 2016, 1:13:55 AM9/15/16
to dnl 31337, robotframework-users

Ugh

Yes it's, more details in the user guide http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#test-setup-and-teardown

-Tatu
Send from my mobile


--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-users+unsub...@googlegroups.com.
To post to this group, send email to robotframework-users@googlegroups.com.
Visit this group at https://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.

Tatu Aalto

unread,
Sep 20, 2016, 1:16:39 AM9/20/16
to dnl 31337, robotframework-users

Ugh

If you want the test setup to be run only in specific test cases, then define the test setup only for those tests cases. But if you want to the test setup to be defined dynamically and it might be different for test run, that is not possible by using command line parameters only.

But perhaps you could elaborate the problem l, which you are trying to solve. Perhaps there is a other ways to solve the problem you are having.

-Tatu
Send from my mobile


On 15 Sep 2016 12:43 p.m., "dnl31337" <dnl3...@gmail.com> wrote:

Hi..

I read it but i didn t understand how to configure to run a keyword in specific tests..

How to pass to Test Setup, as argument, wich test cases i want him to run? Because what i understand is Test Setup  recive as argument the keyword, and he will run this keuword before each test of the file.. but in my situation i only want this Test Setup to run in a few tests from my file..

Ex:

Test Setup  run keywords xyz only in Test Case 2

Test case 1
Test case 2
Test case 3


Em 15/09/2016 02:13, "Tatu Aalto" <aalto...@gmail.com> escreveu:

Ugh

Yes it's, more details in the user guide http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#test-setup-and-teardown

-Tatu
Send from my mobile

On 14 Sep 2016 9:36 p.m., "anarc0der" <dnl3...@gmail.com> wrote:
Hi all...

Is possible to run a Test Setup in just specifics tests of my file?

Ex:

Test Setup  |  Run My Keyword  |  Test 1 | Test 2 | Test 4
 
Test 1
Test 2
Test 3
Test 4



--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-users+unsubscrib...@googlegroups.com.

Pekka Klärck

unread,
Sep 20, 2016, 5:15:09 AM9/20/16
to anarc0der, robotframework-users
2016-09-14 21:36 GMT+03:00 anarc0der <dnl3...@gmail.com>:
> Hi all...
>
> Is possible to run a Test Setup in just specifics tests of my file?

Yes. The designed approach is this:

*** Settings ***
Test Setup My Setup # This is the default setup tests in this
file will use

*** Test Cases ***
Test 1
# Uses the default setup
No Operation
Test 2
# Uses the default setup too
No Operation
Test 3
[Setup] Custom Setup # Uses a custom setup overriding the default
No Operation
Test 4
[Setup] NONE # Has no setup at all
No Operation

*** Keywords ***
My Setup
No Operation
Custom Setup
No Operation

> Ex:
>
> Test Setup | Run My Keyword | Test 1 | Test 2 | Test 4
>
> Test 1
> Test 2
> Test 3
> Test 4

You could also accomplish this if you wanted to. I doubt it would
generally be a good idea, but I guess there could be special cases
where it would be useful.

*** Settings ***
Test Setup Run My Setup Test 1 Test 2 Test 4

*** Test Cases ***
Test 1
No Operation
Test 2
No Operation
Test 3
No Operation
Test 4
No Operation

*** Keywords ***
Run My Setup
[Arguments] @{executed}
Run Keyword If $TEST_NAME in $executed My Setup
My Setup
No Operation

See the User Guide [1] for more information about ${TEST_NAME}
built-in variable and BuiltIn library docs [2] about evaluating
expressions.

[1] http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#automatic-variables
[2] http://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Evaluating%20expressions

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

Pekka Klärck

unread,
Sep 20, 2016, 5:18:50 AM9/20/16
to Tatu Aalto, dnl 31337, robotframework-users
2016-09-20 8:16 GMT+03:00 Tatu Aalto <aalto...@gmail.com>:
>
> But if you want to the
> test setup to be defined dynamically and it might be different for test run,
> that is not possible by using command line parameters only.

This isn't exactly true. You can specify setups/teardowns as variables
and specify those variables from the command line.

Example data (e.g. in tests.robot file)

*** Settings ***
Test Setup ${TEST SETUP}

*** Variables ***
${TEST SETUP} Default Setup

*** Test Cases ***
# Some tests here

Example usages:

# Run with the default setup
robot tests.robot
# Run with some other setup
robot --variable "TEST SETUP:Some Other Setup" tests.robot
Reply all
Reply to author
Forward
0 new messages