Reputation: 81
I have written a python function for fetching database credentials for different environments
def database_creds(env):
if env == 'staging' or env == 'qa':
hostname = 'host1'
username = 'user1'
password = 'pass11'
database = 'TestDb'
elif env == 'production':
hostname = 'host2'
username = 'user2'
password = 'pass22'
database = 'ProdDb'
return hostname, username, password, database
My doubt is how we can use each returned values in robot file?
If we are returning only one value from a python function
def getApiFullUrl(env):
if env== 'production':
url = 'production url'
else:
url = 'other environment url'
return url
we can use like this in robot file:
${url} ${getApiFullUrl('${env}')}
Upvotes: 2
Views: 1176
Reputation: 20067
Either assign them to the same number of variables (that's "automatic unpacking"):
${hostname} ${username} ${password} ${database} database_creds production
, or assign it to a single variable and treat it as a list:
${data} database_creds qa
Log This is the hostname - ${data}[0], and this the database - ${data}[3]
Upvotes: 4