How to make multi-lines test setup or teardown in RobotFramework without creating new keyword?

三世轮回 提交于 2019-12-02 23:22:19
Laurent Bristiel

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  

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!