I have scenario like I need to load specific test data based on the environment I'm passing in cmd line like prod, qa and stag

Hi,

I have scenario like I need to load specific test data based on the environment I’m passing in command line like prod, qa and stag. Please help.

Ex: If I pass ENV:PROD script should take test data from PROD test data file

Hi @sudheer1987 ,

This was answered just recently in this thread

when you read the test data from your datafile just use ${ENV} in the file name/path

Dave.

@damies13 Can you please share with example if possible.

here is an example, you can use yaml instead of python variable files if you like it’s basically the same. refer to Variable files for details of the various variable files

Starting with a variable file for the dev env:

envexample_dev.py

myurl = "http://mydev.site/path"

envexample_uat.py

def geturl():
	# add some code to determine the value
	return "http://myuat.site/path/UAT"

myurl = geturl()

envexample_uat.py

*** Variable ***
${ENV}	dev

*** Settings ***
Variables    envexample_${ENV}.py


*** Test Cases ***
Environment Example
	Log    ${myurl}

Then to call them from the command line

% robot -v ENV:dev envexample.robot
% robot -v ENV:uat envexample.robot

Dave.

@damies13 Thanks for example. My scenario is like I have to load both test data (ex… User login or postal code) and url as well based on the environment I’m passing in command line. i. e., if I pass ENV:QA then it should take both url and specific data to the environment we are passing in cmd. If possible please share this case with example.

@sudheer1987,

The example I gave was for a single variable, if you refer to the documentation I linked you can see that you can have as many variables as you want.

This example was just to get you started and to let you understand the possibilities.

This is why I had the variable returned from a function in the uat example, you can do things like querying the data base in a function and return the result to RF as a variable if thats what you need to do.

If you just need static predefined variables then my dev example is all you need.

Dave.