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

**URL:** <https://forum.robotframework.org/t/setting-test-setup-is-not-allowed-in-resource-file-error-message-in-console/5926>\
**Category:** Robot Framework\
**Created:** [10 July 2023 16:37 UTC](https://forum.robotframework.org/t/setting-test-setup-is-not-allowed-in-resource-file-error-message-in-console/5926 "2023-07-10T16:37:14Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pari](https://avatars.discourse-cdn.com/v4/letter/p/d78d45/32.png) [@Pari](https://forum.robotframework.org/u/Pari)\
**Post date:** [10 July 2023 16:37 UTC](https://forum.robotframework.org/t/setting-test-setup-is-not-allowed-in-resource-file-error-message-in-console/5926/1 "2023-07-10T16:37:14Z")

</div>

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.

```python
    ***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

```

---

<div class="post-metadata">

**Author:** ![HelioGuilherme66](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/helioguilherme66/32/34_2.png) [@HelioGuilherme66](https://forum.robotframework.org/u/HelioGuilherme66)\
**Post date:** [10 July 2023 21:13 UTC](https://forum.robotframework.org/t/setting-test-setup-is-not-allowed-in-resource-file-error-message-in-console/5926/2 "2023-07-10T21:13:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Pari](https://avatars.discourse-cdn.com/v4/letter/p/d78d45/32.png) [@Pari](https://forum.robotframework.org/u/Pari)\
**Post date:** [11 July 2023 14:09 UTC](https://forum.robotframework.org/t/setting-test-setup-is-not-allowed-in-resource-file-error-message-in-console/5926/3 "2023-07-11T14:09:07Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Pari](https://avatars.discourse-cdn.com/v4/letter/p/d78d45/32.png) [@Pari](https://forum.robotframework.org/u/Pari)\
**Post date:** [11 July 2023 14:13 UTC](https://forum.robotframework.org/t/setting-test-setup-is-not-allowed-in-resource-file-error-message-in-console/5926/4 "2023-07-11T14:13:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![HelioGuilherme66](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/helioguilherme66/32/34_2.png) [@HelioGuilherme66](https://forum.robotframework.org/u/HelioGuilherme66)\
**Post date:** [11 July 2023 14:40 UTC](https://forum.robotframework.org/t/setting-test-setup-is-not-allowed-in-resource-file-error-message-in-console/5926/5 "2023-07-11T14:40:04Z")

</div>

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:

```python
***Test Cases***

```

or

```python
***Tasks***

```

---

<div class="post-metadata">

**Author:** ![Pari](https://avatars.discourse-cdn.com/v4/letter/p/d78d45/32.png) [@Pari](https://forum.robotframework.org/u/Pari)\
**Post date:** [11 July 2023 17:41 UTC](https://forum.robotframework.org/t/setting-test-setup-is-not-allowed-in-resource-file-error-message-in-console/5926/6 "2023-07-11T17:41:57Z")

</div>

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

`

---

<div class="post-metadata">

**Author:** ![HelioGuilherme66](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/helioguilherme66/32/34_2.png) [@HelioGuilherme66](https://forum.robotframework.org/u/HelioGuilherme66)\
**Post date:** [11 July 2023 23:26 UTC](https://forum.robotframework.org/t/setting-test-setup-is-not-allowed-in-resource-file-error-message-in-console/5926/7 "2023-07-11T23:26:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Pari](https://avatars.discourse-cdn.com/v4/letter/p/d78d45/32.png) [@Pari](https://forum.robotframework.org/u/Pari)\
**Post date:** [13 July 2023 21:36 UTC](https://forum.robotframework.org/t/setting-test-setup-is-not-allowed-in-resource-file-error-message-in-console/5926/8 "2023-07-13T21:36:47Z")

</div>

Thank you, Helio
