Setting 'Test Setup' is not allowed in resource file. - error message in console

Hello,
Thanks for taking your time to read this post.
I am running into below error message each time I run my robot framework in debug mode. Instead of adding the test setup and test teardown at the test case level, I added them to the setting and declared them in the common.robot file I seem to not able to figure out what did I do run here? When I run the test case without debug mode test runs but will throw the exact same error in the console.

    *** Settings ***


# Selenium Library is defined in the Resource

Resource …/Common/M_Dot_Com_Common.robot
Resource …/Resource/Log_In_UserDefinedKeywords.robot

Test Setup Test Case Setup
Test Teardown Test Case Teardown

The error message is clear. You can only use Test Setup and Test Teardown in Test Cases, which are not allowed in Resource files.

1 Like

Hi Helio,
Thanks for taking your time to look at this. If I understand this correctly. If the code is in resource file then it should be ending with .resource, however, I have setup and teardown in the .robot file.

I had them in the resource folder though if that is something Robot consider as resource file automatically instead of looking for .resource as file extension

You can use resource files with extension robot.
But the problem is that you do not have test cases in that .robot file.

You must have:

*** Test Cases ***

or

*** Tasks ***
1 Like

ahhh, that make sense.

The reason I put the Test setup and Test Case Teardown under setting was I didn’t want to have them in each of the test case as they use the same url and browser.
In this case (see the code below), if I want to achieve reusability of Test setup and teardown, what would you recommend?

`*** Settings ***
Resource …/Common/M_Dot_Com_Common.robot
Resource …/Resource/Contact_Us_UserDefinedKeywords.robot

Test Setup Test Case Setup
Test Teardown Close All Browsers

*** Variable ***
${SERVER_ENV}= qa

${DEFAULT_PAGE}= Contact
more variables that is declared here

*** Test Cases ***
Fill out Contact Us form Sucessfully
#[Setup] Test Case Setup
Given User navigate to the ContactUs link
When User fill out the form with required field
And Click Contact Us button
Then It will display success message
#[Teardown] Close All Browsers

Fill out Contact Us form Validation Failure
#[Setup] Test Case Setup
Given User navigate to the ContactUs link
When User fill out the form with non-required field
And Click Contact Us button
Then It will display fill out the required field message
#[Teardown] Close All Browsers

`

That is the correct use.
I don’t know other solution.

1 Like

Thank you, Helio

1 Like