22

I need to call two teardown keywords in test case but must not create new keyword for that. I am interesting if there is a such syntax for keywords as for documentation or loops for example:

[Documentation]  line1
...              line2
...              line3
Kirill
  • 1,530
  • 5
  • 24
  • 48

2 Answers2

44

Use the "Run Keywords" keyword.

From doc "This keyword is mainly useful in setups and teardowns when they need to take care of multiple actions and creating a new higher level user keyword would be an overkill"

Would look like that:

Test Case
  [Teardown]  Run Keywords  Teardown 1  Teardown 2

or also

Test Case
  [Teardown]  Run Keywords  Teardown 1  
  ...                       Teardown 2 

and with arguments

Test Case
  [Teardown]  Run Keywords  Teardown 1  arg1  arg2
  ...         AND           Teardown 2  arg1  
Slava Semushin
  • 14,904
  • 7
  • 53
  • 69
Laurent Bristiel
  • 6,819
  • 34
  • 52
  • In this case Teardown 2 is argument for Teardown 1 so it doesn't work. – Kirill Mar 27 '14 at 16:09
  • oh yes, try with "run keywords" then – Laurent Bristiel Mar 27 '14 at 16:10
  • Thanks. It almost helps me. There is one problem - it doesn't work if I have to provide argument for Teardown 1 or 2. – Kirill Mar 27 '14 at 16:21
  • from the keyword doc: "Starting from Robot Framework 2.7.6, keywords can also be run with arguments using upper case AND as a separator between keywords. The keywords are executed so that the first argument is the first keyword and proceeding arguments until the first AND are arguments to it. First argument after the first AND is the second keyword and proceeding arguments until the next AND are its arguments. And so on" – Laurent Bristiel Mar 27 '14 at 16:25
  • By the way there is a way to not pass Teardown in Settings if I have already another in Test Case? – Kirill Mar 27 '14 at 16:37
  • test case "teardown" is overriding test suite "test teardown" defined at the suite level. See in the User Guide: "The easiest way to specify a setup or a teardown for test cases in a test case file is using the Test Setup and Test Teardown settings in the Setting table. Individual test cases can also have their own setup or teardown. They are defined with the [Setup] or [Teardown] settings in the test case table and they override possible Test Setup and Test Teardown settings." http://robotframework.googlecode.com/hg/doc/userguide/RobotFrameworkUserGuide.html#test-setup-and-teardown – Laurent Bristiel Mar 27 '14 at 16:48
  • @SlavaSemushin the new link is http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#test-setup-and-teardown – Laurent Bristiel Dec 15 '16 at 11:18
4

For executing multiple keywords in Test Teardown method use the following trick:

Firstly, define a new keyword containing the set of keywords you want to execute.

E.g. here Failed Case Handle is a new definition of the other two keywords take screenshot and close application. Consider this is to take a screenshot and then close the running application.

*** Keywords ***
Failed Case Handle
    take screenshot
    close application

Basically, when you call the Failed Case Handle keyword, take screenshot and close application will be executed respectively.

Then, in the ***Settings*** section define the Test Teardown procedure by the following example.

*** Settings ***
Test Teardown  run keyword if test failed  Failed Case Handle

or,

*** Settings ***
Test Teardown  run keyword  Failed Case Handle

So, in the first case Failed Case Handle keyword will be called if any test case fails. On the other-hand in the second case Failed Case Handle keyword will be called after each test cases.

Zubair
  • 103
  • 6