Using test case with Given in BDD style with robot framework

3,283 views
Skip to first unread message

Jürgen Müller

unread,
Dec 16, 2013, 11:06:50 AM12/16/13
to robotframe...@googlegroups.com
Hello,

I'm new to robotframework and hopefully I'm not posting a question already asked lots of times.

So here it is:

I want to use the BDD style with robotframework (and selenium library, which is not so interesting in the context of my question). 
Now I've already defined a test case:

Valid Login
    Given browser is opened to login page
    When user "h.wach" logs in with password "Anfang5!"
    Then xyz page should be open 

I've defined all the keywords and it works fine (should so, since it's just leaned on the example project).

Now I want to create the next test case which in Fact depends on the Valid Login already defined as test case.
So I (quite naturally to my opinion) want to define:

Search Contract
Given Valid Login
When Keyword "ThisIsTheKeyword" is searched
Then Auftraggeber "Mary" should be found

But this is failing with "No keyword with name 'Given Valid Login' found".
So what am I missing? Or is this construct simply impossible?

greetings
Jürgen

Mukesh T

unread,
Dec 16, 2013, 1:38:31 PM12/16/13
to robotframe...@googlegroups.com
This isn't working because the framework tries to search for keyword named 'Valid Login' or "Given Valid Login", when you write 'Given Valid Login' in your above case.

Recalling the test case from another test case is somehow not implemented in RF I guess, although it would be better to have this :)

One such issue is in 'won't fix' status: https://code.google.com/p/robotframework/issues/detail?id=319

However, I let the experts in this group comment as I'm a beginner on robot framework.

regards,
Mukesh

Tatu Aalto

unread,
Dec 16, 2013, 2:59:50 PM12/16/13
to robotframe...@googlegroups.com
Ugh

What you want it not possible, directly. But first some basic concepts, because it seems that you mixing test case [1] and keyword [2]. A copy/paste from user guide:

Keywords: Keyword tables are used to create new higher-level keywords by combining existing keywords together. These keywords are called user keywords to differentiate them from lowest level library keywords that are implemented in test libraries.

Test case: Test cases are constructed in test case tables from the available keywords. Keywords can be imported from test libraries or resource files, or created in the keyword table of the test case file itself.

Reading the documentation, will hopefully clear the issue for you. Once the difference is clear, read on. If the difference is not clear, ask more questions about the difference.

But back to your problem and solving it. One can not use test case as keyword, Robot Framework does not work in that way. There are several solutions for your problem. Here are two solutions:

Easy but very bad example: Make invisible dependency between tests
Make two tests: 1) with login 2) search contract. The second test case does not contain the Given Valid Login keyword and browser is not closed between test cases. Then run them in sequence and it should work. The bad thing is that now you have invisible dependency between tests. Example, when the first test fails, the second one will also fail, but the reason for failure is not clear for the second test. Unless someone remember the invisible dependency and someone (also including you) will not remember it after a very short period. Also it is impossible just to run the second test without the first one.

Better example: Make individual tests
Make two test 1) with login 2) search contract. The differences for fists example are:
A) create a keyword where you clear to the SUT [3] to the initial state. I do not know how it is done in your application, each application is different. But you will needed a lot, trust me on this. Lets say this keyword is called: Clear SUT To Initial State
B) Use the Clear SUT To Initial State keyword as a test tear down [4] for both tests. Or use it test suite tear down [5]
C) Create new keywordcalled: Valid Login. It contains keywords: browser is opened to login page, user "h.wach" logs in with password "Anfang5!" and xyz page should be open
D) Use Valid Login keyword as first keyword in  the second test case. Or use it in the test setup [4].

I short your test suite should look like this (also in attachment):
*** Test Cases ***

Valid Login
    Given browser is opened to login page
    When user "h.wach" logs in with password "Anfang5!"
    Then xyz page should be open
    [Teardown]    Clear SUT To Initial State


Search Contract
    Given Valid Login
    When Keyword "ThisIsTheKeyword" is searched
    Then Auftraggeber "Mary" should be found
    [Teardown]    Clear SUT To Initial State

*** Keywords ***
Clear SUT To Initial State
    Pass Execution    pass

Valid Login

    browser is opened to login page
    user "h.wach" logs in with password "Anfang5!"
    xyz page should be open

browser is opened to login page
    Pass Execution    pass


user "h.wach" logs in with password "Anfang5!"
    Pass Execution    pass


xyz page should be open
    Pass Execution    pass

Keyword "ThisIsTheKeyword" is searched
    Pass Execution    pass


Auftraggeber "Mary" should be found
--
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-u...@googlegroups.com.
To post to this group, send email to robotframe...@googlegroups.com.
Visit this group at http://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/groups/opt_out.

test_setup_and_tear_down.txt

Jürgen Müller

unread,
Dec 17, 2013, 5:10:06 AM12/17/13
to robotframe...@googlegroups.com
Hello Tatu,

thanx for the explanation. I already tested the construct of kinda copying the testcase as a keyword. And it worked (BTW without deleting the BDD style words!) fine.
I simply thought that it is not so splendid if you cannot call a test case from another. So if I for example have 10 testcases, each on top of all the previous cases, I've to define all of them as test case AND as keyword. This is really redundant and error-prone.

But so I will copy my test cases as keywords (and hopefully not forget to make changes on both places).

greetings
Jürgen

suraj....@synerzip.com

unread,
Sep 6, 2018, 5:16:01 AM9/6/18
to robotframework-users

I want to use the BDD style with robotframework (and selenium library, which is not so interesting in the context of my question). 
Now I've already defined a test case:

Valid Login
    Given browser is opened to login page
    When user "h.wach" logs in with password "Anfang5!"
    Then xyz page should be open 

I've defined all the keywords and it works fine (should so, since it's just leaned on the example project).

Hi , Can u please send code for that Valid login scenraio i am facing problem  

This e-mail, including any attached files, may contain confidential and privileged information for the sole use of the intended recipient. Any review, use, distribution, or disclosure by others is strictly prohibited. If you are not the intended recipient (or authorized to receive information for the intended recipient), please contact the sender by reply e-mail and delete all copies of this message.

suraj....@synerzip.com

unread,
Sep 11, 2018, 3:23:13 AM9/11/18
to robotframework-users
hi,
Jürgen Müller
Can u send the code for login scenario in BDD style I am new to robot framework i am facing problem
Reply all
Reply to author
Forward
0 new messages