简体   繁体   中英

How to use multiple returned value from a python function in a robot file?

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}')}

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM