Ask a Question

file for different env

SOLVED
kadir
Occasional Contributor

file for different env

I have different excel files, but all these excel files are for different environments. When I run a test case or test suite, I want to make sure data source file path changes based on the env I chose. Any help please?

 

kadir_0-1636037290951.png

 

4 REPLIES 4
richie
Community Hero

Hey @kadir 

 

Im working on the wrong laptop at moment but I cant check - but does the file browse editable field support parameters? 

 

I cant remember - but if it does, you could create a custom project level property indicating the environment and then point to this.

 

so say you have 3 environments with different testdata in different folders, you could create a custom property called 'environment_path' and you could specify this before your execution by importing a properties file that contains the correct path

 

so 3 environments = DEV, QA & CLONE

 

create 3 properties files, 1 for each environment -

 

in each file you would have something like 

environment_path=C:\ReadyAPI\Project\QA

 

once the file's created, decide which environment to execute on and then prior to execution load in the file.

 

Then in your DataSource test step's file path editable field input the value as ${Project#environment_path}

 

I actually do this for every single possible environment specific parameter/variable so there's minimal hard coding.  Means I can lift and shift my project to different environments without having to change any data at all.  The only thing I change is the properties file I load in, immediately before I start an execution run.

 

ta

 

Rich

 

 

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta

Hi,

 

Taking nothing away form @richie 's solution but I have another approach.

 

I haven't tried dynamically changing the file based on environment, but I do do this for selecting a given sheet within my data spreadsheet environment.

 

Before the datasource and outside the loop, I have a Groovy script labelled 'Get Environment - Groovy Script'.

log.info("Checking the environment");

def activeEnvironment = testRunner.testCase.testSuite.project.activeEnvironment.getName();

def sheetToUse = "";

if (activeEnvironment.contains( "DEV")) {
	sheetToUse = "Development";
} else if (activeEnvironment.toUpperCase().contains("TEST") ){
	sheetToUse = "Test";
} else if (activeEnvironment.toUpperCase().contains("PRE") ){
	sheetToUse = "Pre-Production";
} else {
	// something went wrong.
	sheetToUse = "";
}

log.info("Currently Selected Environment :- ${activeEnvironment}.  Select sheet :- ${sheetToUse}.");

return sheetToUse;

 

My Datasource

ChrisAdams_0-1636101473569.png

 

@ChrisAdams 

 

 

I kinda like your answer - gonna steal your script if you dont mind! 😉

 

Cheers!

 

Rich

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta

@richie go for it.  Also, no reason it cannot be applied to selecting a spreadsheet instead of a sheet.

cancel
Showing results for 
Search instead for 
Did you mean: