How can I call the xpath from another file? - robotframework

There are 2 files
Testcase/feature1.robot
POM/feature2.robot
feature1.robot
*** Settings ***
Library SeleniumLibrary
Resource ../POM/feature2.robot
*** Variables ***
${username} xxxxxxxx
${password} xxxxxxxx
*** Keywords ***
Login in DataRPM
#[Arguments] ${username} ${password}
Input Text ${email_id} ${username}
feature2.robot
*** Settings ***
Documentation This contains all the locaters of Login Page
*** Variables ***
${email_id} xxxxxxxx
But here I don't want to use the email_id locator to be mentioned in the variable section. If I am mentioning the ${email_id} in this feature file I am able to go ahead without any error. I want to use the locator in the feature2.robot file which is under my POM directory. Then I want to call the variable from feature2.robot.
I have mentioned the path in the feature1.robot but still I am getting error.
[ ERROR ] Error in file feature1.robot': Resource file 'path' contains
a test case table which is not allowed.

The error is pretty descreptive, while you not showing use you probably have test cases implemented in feature2.robot and in that case it is a suite file.
But you are trying to use feature2.robot as a resource file, and as the error message states, resource files are not allowed to have test case table.
You should create a third file like POM/locators.robot:
*** Settings ***
Documentation This contains all the locaters of Login Page
*** Variables ***
${email_id} xxxxxxxx
and use this in both feature1.robot and feature2.robot like:
Resource ../POM/locators.robot
Resource locators.robot
From Robot Framework 3.1 *.resource file extension is supported, so if you have version 3.1, you should use locators.resource to be more explicit about that this file is a resource file and not a test suite.

your question is not clear, However , i would try to show an error free example using your code only, with slight modification.
feature1.robot
*** Settings ***
Resource ../Data/Feature2.robot
*** Variables ***
${username} pankaj
${password} xxxxxxxx
*** Test Cases ***
Login
Login in DataRPM
*** Keywords ***
Login in DataRPM
#[Arguments] ${username} ${password}
log to console ${email_id}
log to console ${username}
Feature2.robot
*** Settings ***
Documentation This contains all the locaters of Login Page
*** Variables ***
${email_id} pankajigec26#gmail.com
if you run feature1.robot you will not get into any error .
In your case , please check if you are running the same code which you have pasted here.

Related

Robot Framework Test Template Setup argument problems

I've got several working Robot Framework tests that I'm trying to consolidate into one test suite and run through a template. The tests are functionally the same, just being executed from a different URL. So that's the one parameter that's different. I'm trying to pass the URL into each test case, but I am getting an error: "Keyword 'Setup' expected 0 arguments, got 2."
*** Settings ***
Documentation Login tests
Library Zoomba.GUILibrary
Suite Setup Setup
Test Template Template 1
*** Variables ***
${browser} chrome
${url1} https://<test.url1>
${url2} https://<test.url2>
${url3} https://<test.url3>
*** Keywords ***
Setup
Open Browser ${url} browser=${browser} options=add_argument("<argument>")
Maximize Browser Window
Set Selenium Speed 0.2s
Log To Console Setup complete. Logging in...
Template 1
[Arguments] ${url} ${browser}=${browser}
Setup ${url} ${browser}
<Login tests>
*** Test Cases ***
Site 1 Login
${url1}
Site 2 Login
${url2}
Site 3 Login
${url3}
Anybody have any ideas? Please let me know, thanks!
You are calling Setup with two arguments, like the error says:
Template 1
[Arguments] ${url} ${browser}=${browser}
Setup ${url} ${browser}
<Login tests>

Robot framework SSHLibrary 0 arguments expected two

I am trying to make a testcase in robotframework with SSHLibrary and running into an error trying to connect with the FTP server. The error I get is keyword login.login expects 0 arguments and gets two. I do not really understand why it does expect 0 arguments.
the resource file in which the keyword file exists has the following code:
*** Settings ***
Library SSHLibrary
*** Keywords ***
lOGIN
Set Default Configuration 30s
Open Connection ${HOST}
Login ${USERNAME} ${PASSWORD}
The test I like to run looks like:
*** Settings ***
Documentation Example of testing an accrual for TLOG
Resource ../Resources/login.robot
*** Variables ***
${HOST} sitenv
${USERNAME} crmapplication
${PASSWORD} Company11*
*** Test Cases ***
logintositenv
login.login
Any idea what is going wrong? I am especially surprised I cannot get it to work because I used the open connection and login keywords from SSHLibrary before when I was trying out a few things and it worked fine.
As you said login.login That tells me you have probably another library that has keyword login. In this case you have to specify that you want to use SSH library.
You can do this with
SSHLibrary.Login
Here you can have a look how to import library with custom name and use keywords

Not able to connect to Excel as a database using Robotframework-databaselibrary

I am trying to open a excel file as a database using the robot framework database library but i am not able to do that. Tried both the below keywords but getting several errors:
Connect To Database
Connect To Database Using Custom Params
Tried to google to find any example but couldn't find. Appreciate if someone can suggest if this is possible ? If yes, could you please suggest a correct way to call these keywords for excel file.
I have tried below:
1)
*** Settings ***
Library DatabaseLibrary
*** Test Cases ***
Test1
connect to database excel D:\TestFile.xlsx ${EMPTY} ${EMPTY} ${EMPTY} ${EMPTY} ${EMPTY} ${EMPTY}
I have below db.cfg file as well:
[default]
dbapiModuleName=excel
dbName=D:\\TestFile.xlsx
dbUsername=
dbPassword=
dbHost=
dbPort=
This is giving error: NoSectionError: No section: 'default'
2)
*** Settings ***
Library DatabaseLibrary
*** Test Cases ***
Test1
connect to database using custom params excel database='D:\TestFile.xlsx', user='${EMPTY}', password='${EMPTY}', host='${EMPTY}', port='${EMPTY}'
This is giving error: AttributeError: module 'excel' has no attribute 'connect'
3)
*** Settings ***
Library DatabaseLibrary
*** Test Cases ***
Test1
connect to database using custom params pyodbc database='D:\TestFile.xlsx', user='${EMPTY}', password='${EMPTY}', host='${EMPTY}', port='${EMPTY}'
This is giving below error:
InterfaceError: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')

How to create _init_.robot and use it for all robot files in the directory in robot framework?

I am trying to include_init_.robot file in the test suite. I have added a test implementation to check the method it would work, however I am unable to figure out it's execution. Code is as follows:
init.robot
*** Settings ***
Documentation Suite description
Suite Setup Initialization In Progress
*** Keywords ***
Initialization In Progress
log many THE CODE WORKS NOW
test#1.robot
*** Settings ***
Documentation Suite description
*** Test Cases ***
Test Case Execution
log many TC EXECUTED
Code used to run the test: pybot folder_name
The name of the first file is incorrect. You have
_init_.robot
while it should be
__init__.robot
When you do that the log will show this:

No keyword with name 'Create Session' found robot framework

I'm new to Robot Framework. When I run ride.py, I'm getting this error.
here is my code:
Create Session chat ${URL1} headers=${MyHeaders1}
Thank you very mych in advance for your help.
Looks like you're trying to use the requests library but haven't imported it. I recommend that you read the user guide, especially the part on importing libraries.
Basically you want to add this in your *** Settings *** section:
*** Settings ***
Library RequestsLibrary
You may also want to check out the library's Github README, there's a few usage examples in there that will likely help you.
I have explain the issue and also the solution.
Problem :
*** Variables ***
${Base_URL} http://www.thetestingworldapi.com/
*** Test Cases ***
TC001_GetRequest
create session thetestingworldapi ${Base_URL}
${response} = get request thetestingworldapi api/studentsDetails
Error in console: No keyword with name '${response}= get request ggg' found.
To resolve this kind of error just do one change in the code part, am attching silution as well below.
Solution :
*** Variables ***
${Base_URL} http://www.thetestingworldapi.com/
*** Test Cases ***
TC001_GetRequest
create session thetestingworldapi http://www.thetestingworldapi.com/ --- Use the main base url instead of the variable and this will work.
${response} = get request thetestingworldapi api/studentsDetails

Resources