How to structure a suite setup with multiple .robot-files?

Hello,

I am somewhat new with Robot Framework and I’ve run into something I can’t figure out, I’ve looked around the docs as well but honestly haven’t found what I’m looking for.

Current situation:
I have several .robot-files that’s part of a suite, I have tried and can run the full suite by calling the “top folder” and having the suite setup present in the first .robot that runs and not the others.

However I can’t run the individual .robot-files because of this. The reason I don’t want every robot-file to run a suite setup in a full suite is because it is somewhat complicated, it starts some hardware and creates a couple of bindings and stuff and takes quite a bit of time.

I’m not even sure I’m making sense but in short:
When running the full suite containing several .robot-files, I would like the suite setup to run only once, but I also want the suite setup to run if I decide to run an individual .robot-file in the same suite. How can I achieve this?

Best regards,

Oh I forgot to mention something, an idea I had was to have a bool in the suite setup like “FirstRun” and set it to True when starting the test, and then the setup itself sets it to false. If it is false, the suite setup will skip the keywords that starts the hardware and such.

My idea what that this would make the suite setup run only once, and when running the full suite, the individual .robot files would run the suite setups but since this bool is false after the first run it will skip the suite setup. Does that make sense or is there a better way of doing this?

1 Like

To run a single suite setup (once) for multiple .robot files, you can use the __init__.robot file and define the Suite Setup and Suite Teardownin there.
They will be only executed before the first Test Suite and after the last Test Suite.
See example screenshot below.

You can see the Suite Setup and Suite Teardown are only executed before the first suite and after the last suite.
This will only work, when running the whole folder, e.g. via
robot .\tests\init_example\

Thanks for your reply, that’s a nice example. I’m looking for something like that, but it should also work for running individual .robot files in the same folder or a sub-folder for when you just want to execute part of the suite.

Best regards,
Mattias

That’s still possible by using the --suite and --test argument if you don’t mind using the command line

To e.g. only execute a specific suite:
robot --suite suiteA .\tests\init_example\

To run a specific test starting with “Login”:
robot --test Login* .\tests\init_example\

2 Likes

Anyway, here is the documentation of the init.robot files
https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#suite-initialization-files

2 Likes

I don’t mind that at all and will test it, thanks a lot!

1 Like

Apologies for the late reply, I finally had time to test your suggestion and it seems like your answer was exactly what I was looking for, it works great with the --include stuff as well. I’ve marked your reply as the solution, thanks again!

Should anyone else find this thread, if you’re planning to also use Test Setup specified in the init.robot, you still need to add them as a resource in the individual .robot-files otherwise they won’t be found. This is also stated in the documentation but I felt I should add it.

2 Likes

Hey,
I was facing similar issue and tried your solution.
So it launches 2 chrome windows but execution takes place in only one window for suiteA.robot and no execution takes places for suiteB.robot

I’m getting following error
Setup failed:
SessionNotCreatedException: Message: session not created: Chrome failed to start: exited normally.
(session not created: DevToolsActivePort file doesn’t exist)
(The process started from chrome location C:\Program Files\Google\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)