Robot framework "resource file not found" error - automation

I have designed this architecture where all the test cases will be in Amazon.robot file and all low level keywords for robot framework will be in two separate files(AmazonGui.robot and Commons.robot)
Amazon.robot file that has all the test cases:
*** Settings ***
Documentation This is some basic infor the whole suite
Resource Resources/AmazonGui.robot
Resource Resources/Common.robot
*** Variables ***
*** Test Cases ***
User must sign in to check out
[Documentation] This is some basic info about test
[Tags] Smoke
Common.Begin Web Test
AmazonGui.Search for Products
AmazonGui.Select Product from Search Results
AmazonGui.Add Product to Cart
AmazonGui.Begin Checkout
Common.End Web Test
I have two other resources files that has the low keywords, so basically the test case(Amazon.robot) is calling the low level Keywords files(Common.robot and AmazonGui.robot). I have imported the Resources files to the test case file.
AmazonGui.robot file that has low level keywords for test cases
*** Settings ***
Library Selenium2Library
*** Keywords ***
Search for Products
go to http://www.amazon.com
wait until page contains Your Amazon.com
input text id=twotabsearchtextbox Ferrari 458
click button xpath=//*[#id='nav-search']/form/div[2]/div/input
wait until page contains results for "Ferrari 458"
Select Product from Search Results
click link css=#result_0 a.s-access-detail-page
wait until page contains Back to search results
Add Product to Cart
click button id=add-to-cart-button
wait until page contains Added to Cart
Begin Checkout
click link id=hlb-ptc-btn-native
page should contain element id=signInSubmit
Common.robot file that has common features just opening and closing browser
*** Settings ***
Library Selenium2Library
*** Keywords ***
Begin Web Test
open browser about:blank ff
End Web Test
close browser
When I am trying to run the script from terminal using :
C:\development\robot-scripts\amazon>pybot -d results tests/amazon.robot
I get the below error:
[ ERROR ] Error in file 'C:\development\robot-scripts\amazon\tests\amazon.robot': Resource file 'Resources\AmazonGui.robot' does not exist.
[ ERROR ] Error in file 'C:\development\robot-scripts\amazon\tests\amazon.robot': Resource file 'Resources\Common.robot' does not exist.
==============================================================================
Amazon :: This is some basic infor the whole suite
==============================================================================
User must sign in to check out :: This is some basic info about test | FAIL |
No keyword with name 'Common.Begin Web Test' found.
--------------------------------------------------------
Amazon :: This is some basic infor the whole suite | FAIL |
1 critical test, 0 passed, 1 failed
1 test total, 0 passed, 1 failed
Not really sure, where I should look to find out the issue.

You have your test cases inside a folder called tests. The Resource files are present in a different folder called Resources.
When you give
Resources/AmazonGui.robot
It will check for a directory named Resources in the directory tests, but actually the directory is present outside the tests directory.
../Resources/AmazonGui.robot
Here you are asking the framework to come outside of the tests directory and check for the directory named Resources.

This issue is do not set the right path for resource files. Try this codes replace old:
Resource ../Resources/AmazonGui.robot
Resource ../Resources/Common.robot

Related

DataDriver not reading csv file

Not sure why its not finding my csv header variables
Im using this Library I installed it
https://github.com/Snooz82/robotframework-datadriver
However, I keep getting error
Variable '${username}' not found.
Below is my robot file
*** Setting ***
Resource ../../../Resources/Common.robot
Library DataDriver ../../../DataFiles/LoginMultipleTimes2.csv
Suite Setup Open Browser and navigate
Suite Teardown Close All Browsers
Test Template CSVList
*** Variables ***
${URL} = https://myapplogin.com
*** Test Cases ***
Login Successfully ${username} ${password}
*** Keywords ***
Open Browser and navigate
I open a browser and nagivate to MyApp Login page
CSVList
[Arguments] ${username} ${password}
Input Text id=username ${username}
Input Text id=password ${password}
Click Button xpath=//*[#id="signin-button"]/input
My csv file looks like this
${username},${password}
jack2,T3sT123
jack3,T3sT123
Any suggestions?
I have tried putting double and single quotes around the variables.
If I type in the wrong name in the Library section it gives an error so I know the file path is correct.
Solved the issue by adding
Library DataDriver ../../../DataFiles/AddClients_002.csv reader_class=csv_reader encoding=utf_8
and making sure I saved the file as MS DOS Comma Seperated (im using a mac).

How to pass multiple arguments to a test case in CumulusCI test automation framework?

Problem statement:
Unable to pass multiple variable values to my test case using CumulusCI command:
`cci task run robot...
I am referring this section for building my command: https://cumulusci.readthedocs.io/en/latest/tasks.html#id49
If I have to pass just one variable in the same way as above, say for eg. just LocalOrRemote, then the code works perfectly fine, so it appears that this has to do something with the way I am passing multiple variables.
My test automation tech stack is Robot Framework, CumulusCI, Selenium
Sample Code:
*** Settings ***
Resource C:/Dev/myproject/robotframework/EnvironmentSetupFile.robot
Suite Setup Run Keywords Suite Setup KW1 AND Suite Setup OS And Browser ${LocalOrRemote} ${Browser}
*** Test Cases ***
Verify whether I am able to set environment and browser
[Tags] LocalEdge
[Documentation] This test should run on the local edge browser
Keyword X
Keyword Y
*** Keywords ***
Suite Setup KW1
do something
Suite Setup OS And Browser
[Arguments] ${LocalOrRemote} ${Browser}
Log Many ${LocalOrRemote} ${Browser}
run keyword if '${LocalOrRemote}'=='Local' Setup Local Browser ${Browser}
... ELSE IF '${LocalOrRemote}'=='Remote' Setup Remote Browser ${Browser}
... ELSE FAIL "Incorrect environment value passed! Please refer the instructions in README for running the test suite"
Command I am using to invoke my test:
cci task run robot -o suites mypath/MyTestFile.robot -o include LocalEdge -o vars LocalOrRemote:Local,Browser:edge
Issue I am facing:
The value of ${Browser} is not received as edge but defaulted to chrome, which means the command is not able to pass on my desired value to the TC.
KEYWORD BuiltIn . Log Many ${LocalOrRemote}, ${Browser}
Documentation:
Logs the given messages as separate entries using the INFO level.
Start / End / Elapsed: 20190522 16:36:53.877 / 20190522 16:36:53.878 / 00:00:00.001
16:36:53.877 INFO Local
16:36:53.877 INFO chrome
How to pass multiple arguments to a test case in CumulusCI test automation framework?
The way you are doing it is the correct way: -o vars var1:value1,var2:value2
Here's a really simple example:
*** Test cases ***
Example
Should be equal ${LocalOrRemote} Local
Should be equal ${Browser} edge
Save that to a file and then run it with the robot task like this:
cci task run robot -o vars LocalOrRemote:Local,Browser:edge -o suites example.robot
You will see that the variables are initialized properly. If the wrong browser is opening up, one of your libraries must be changing the value of the ${Browser} variable without you realizing it.
Thanks a ton #Bryan for the direction. It was that moment when you get so awestruck by your own creation and forget to try out basic debugging in your framework.
Anyway, the issue here was the placement of resources as you rightly pointed out. Observe the before and after code pieces below. The issue (well at this point I cannot comment that its an issue or shortcoming) revolves around the placement of Salesforce.robot resource. For the Cci command to pass the right value of the 2nd variable, I had to place this resource in the test case itself. The Cci command did not pass the right value of the 2nd variable when I had this resource loaded via an environment file; weird.
*** Settings ***
Documentation ###My setup before:
Resource C:/Dev/myproject/robotframework/EnvironmentSetupFile.robot
Suite Setup Run Keywords Suite Setup KW1 AND Suite Setup OS And Browser ${LocalOrRemote} ${Browser}
Documentation ###My setup after:
Resource C:/Dev/myproject/robotframework/EnvironmentSetupFile.robot
Resource cumulusci/robotframework/Salesforce.robot #had to place this resource here
Suite Setup Run Keywords Suite Setup KW1 AND Suite Setup OS And Browser ${LocalOrRemote} ${Browser}
*** Test Cases ***
Verify whether I am able to set environment and browser
[Tags] LocalEdge
[Documentation] This test should run on the local edge browser
Log "TC passed"
My setup before:
C:/Dev/myproject/robotframework/EnvironmentSetupFile.robot
*** Keywords ***
Suite Setup KW1
Import Resource cumulusci/robotframework/Salesforce.robot #the resource that was causing the issue
Import Resource C:/Dev/myproject/robotframework/BrowserSetupKeywords.robot
import resource C:/Dev/myproject/robotframework/ValidationKeywords.robot
Import Library cumulusci.robotframework.CumulusCI ${ORG}
import library SeleniumLibrary timeout=7 seconds implicit_wait=5 seconds
import library OperatingSystem
import library BuiltIn
C:/Dev/myproject/robotframework/BrowserSetupKeywords.robot
*** Keywords ***
Suite Setup OS And Browser
[Arguments] ${LocalOrRemote} ${Browser}
Log Many ${LocalOrRemote} ${Browser} #used to default Browser value passed to chrome
`
My setup after:
C:/Dev/myproject/robotframework/EnvironmentSetupFile.robot
*** Keywords ***
Suite Setup KW1
#Import Resource cumulusci/robotframework/Salesforce.robot # had to comment this resource here and place it before the Suite Setup
Import Resource C:/Dev/myproject/robotframework/BrowserSetupKeywords.robot
import resource C:/Dev/myproject/robotframework/ValidationKeywords.robot
Import Library cumulusci.robotframework.CumulusCI ${ORG}
import library SeleniumLibrary timeout=7 seconds implicit_wait=5 seconds
import library OperatingSystem
import library BuiltIn
C:/Dev/myproject/robotframework/BrowserSetupKeywords.robot
*** Keywords ***
Suite Setup OS And Browser
[Arguments] ${LocalOrRemote} ${Browser}
Log Many ${LocalOrRemote} ${Browser} #now returns the correct Browser value

How to declare global base url on RIDE in robot framework

On RIDE editor there are 5-6 test suites. Each test suite opens the same URL after opening browser. I want to use a global variable (base URL )for those test suite. Could you please help me how to do it. Thanks in advance.
[]
You will need to delcare it as global by using
*** Variables ***
#{url} Set Global Variable www.google.com
*** Test Cases ***
test1
log to console ${url}
it's BuiltIn's Library.

Load code lines for a robot-file

I have huge robot-files. In all this files a section of the code is the same. Because of DRY I want to shorten the files and put the code to an other file. How to call this 100 robot-code lines from an other file then?
file1.robot
MyTest1
<Content of other file>
Some other keywords
file2.robot
MyTest2
<Content of other file>
Some other keywords
Other file
Log to console 1
Log to console 2
Log to console 3
Log to console .
Log to console .
Log to console 100
The way to do this is to use keywords in a resource file. You can't include raw lines of code.
For example:
other.robot
*** Keywords ***
Do something
log to console 1
log to console 2
...
file1.robot
*** Settings ***
Resource other.robot
*** Test Cases ***
MyTest1
do something
Some other keywords

Robot framework resource file not found

I want to use a resource file with the name clean_environment.robot on windows. It is in the same folder like my robot file (C:\Users\xxxxx\Desktop\git\src), which is callig the resource file.
Basic file 30.robot:
** Settings **
Resource clean_environment.robot
** Test Cases **
MyTestCase
Clean environment
I get the error:
[ ERROR ] Error in file
'C:\Users\xxxxx\Desktop\git\src\30.robot':
Resource file 'Clean environment' does not exist.
The resource file:
*** Settings ***
*** Test Cases ***
Clean environment
Log to console 111
Edit:
The computer said: Resource file 'Clean environment' does not exist! But 'Clean environment is not the resource file, it is the keyword right?
If the file has a test case in it, it is not considered to be a resource file by robot. Resource files can only have keywords, variables and settings.
If you expect Clean environment to be a keyword, put it in a keyword table:
*** Keywords ***
Clean environment
Log to console 1111