Reputation: 51
I have a method in python file that returns a value lilke URL. Which I want to call in robot framework to launch the test cases, by appending environment . Below is the code that I have used.
python and robot file code. please let me know where I am doing it wrong. Am trying calling method from python file which returns the url into robot framework class,
Environment.py
class TestUrl:
def getBaseUrl(self, env):
if env == 'int':
domain = 'example.com/'
return domain
def getFullUrlForEclaimsHome(self, env, partner):
x = self.getBaseUrl(env)
url = 'https://' + partner + x
print url
return 'https://' + partner + x
test.robot
*** Settings ***
Variables ../../CommonTestClass/Environments.py
*** Variables ***
${browser} chrome
${env} int
${partner} example
${example URL} = call method getFullUrlForEclaimsHome('${env}','${partner}')
*** Keywords ***
Launch the browser
sleep 2s
Open Browser ${example URL} ${browser}
Maximize Browser Window
Upvotes: 4
Views: 4228
Reputation: 1477
the name of the file and the name of the class (for my experience) should match, so if the file is called "Environments.py" your class should be called "Environments" this because once that you import it in robot framework you will call directly the method "getBaseUrl" or "getFullUrlForEclaimsHome".
Plus you are missing () on your class definition:
class TestUrl():
EXAMPLE:
My Python file called: Tree.py
from anytree import Node, RenderTree
class Tree ():
def generate_tree (self,db_server,db_table,db_username, db_password):
DO_SOMETHING
def retrieve_tree_info (self,db_server,db_table,db_username, db_password, tree_ID):
DO_SOMETHING
return (SOMETHING)
MY Robot Framework File:
*** Settings ***
Library YOUR_LIBRARY
Resource YOUR_RESOURCE
Library ../External Library/Tree.py #PATH TO YOUR Tree.py FILE
#NOTE: If you use some IDLE (I'm using RED) it give you suggestion about the method name, in my example the IDLE call it in a bit different way than it was called in the python file
*** Variables ***
YOUR_VARIABLE
*** Test Cases ***
Create tree
DO_SOMETHING
${tree}= Retrieve Tree Info ${db_server} ${db_name} ${db_user} ${db_password} ${tree_ID}
DO_SOMETHING
Verify Locations tree
DO_SOMETHING
${tree}= Retrieve Tree Info ${db_server} ${db_name} ${db_user} ${db_password}
DO_SOMETHING
Upvotes: 3