josephting
josephting

Reputation: 2665

Execution Level Setup & Teardown with Robot Framework

I understand there's Test Setup which will get executed before every test case and Suite Setup which will get executed before every suite (i.e. each .robot file).

However, I'm trying to do Setup and Teardown of the command level which is Setup once I run the robot command and when all test suites have ran, run Teardown.

Tried with having __init__.robot file in my scenario directory but they didn't get called at all.

*** Settings ***

Resource  ../_common/keywords.robot

Suite Setup  Prepare Browser
Suite Teardown  Close Browser

I want to be able to launch the browser before any test is started and then close browser only after all tests are completed.

For example, robot 1.robot 2.robot should:

  1. Open browser
  2. Run 1.robot test suite
  3. Run 2.robot test suite
  4. Close browser

Upvotes: 3

Views: 2562

Answers (1)

Todor Minakov
Todor Minakov

Reputation: 20047

You could do that by having "special" suites just for that, and call them first and last in a run. With the SeleniumLibrary having a global scope, the browser initialized in the first one should be accessible for all follow-up suites in the same run.

E.g. the suite "Startup.robot" will open the browser, and "Closing.robot" will close it, and any in between will use it:

robot Startup.robot 1.robot 2.robot Closing.robot

When you pass a directory for execution, the framework takes the .robot files in it in alphabetical order, so you can name those special suites "0000_Startup.robot" and "zzzz_Closing.robot" for them to be ran in the corresponding order (that's if you use only ascii/latin file names).


And yep, the initialization files are not used to run something before the other suites - they are there to set default values for those other suites, which can be overridden downstream. See their description in the documentation.

Upvotes: 3

Related Questions