user2661518
user2661518

Reputation: 2745

Call python file from suite setup in robot framework

I am calling keyword for suite setup as below

Suite setup  setup keyword

But can I call python file from suite setup or keywords file? I have lot of keywords as setup so is there any way I can pass them all together? I can use run keywords to pass multiple keywords but can I pass file?

Upvotes: 1

Views: 1522

Answers (1)

Bryan Oakley
Bryan Oakley

Reputation: 385850

You can't give a filename as an argument to a suite setup, but you can certainly create a file that has a single keyword that does everything you want.

You could also use a variable file, which will get executed before any tests will run.

Using a library file with a setup keyword

To use a library file, put all the code you want to execute in a single function. For example:

# my_setup_file.py
def my_setup():
    do_something()
    do_something_else()

You could then use it like this:

# my_suite.robot
*** Settings ***
| Library | my_setup_file.py
| Suite setup | my_setup

Using a variable file

You can use a variable file, which in effect works like loading up a file in setup since the file is evaluated before the start of the first step (and before any other setup steps)

In this case your python file would not need a function, it could have any code. All variables defined in this file will be available to your test case.

# my_variables.py
foo = "this is foo"
bar = "this is bar"

You would then use it like this:

*** Settings ***
| Variables | my_variables.py

Upvotes: 1

Related Questions