Forum Discussion
caz88
Occasional Contributor
HimanshuTayal I'm trying to get the logic from the groovy script I've written working at the project level. Currently the functionality requires me to include a groovy script within each testcase. I was wanting to be able to use the same logic in a setup script to reduce the amount of code needed to be inserted into the project. Can we use Java libraries in setup scripts? I'm not sure it is even possible to transfer this approach to a setup script at project level.
class SelectedMarkets{ def static selectMarketsToRunTests(testRunner, context, log){ def dataPath def dataFile def headers def rowLine //get the specifcic global property def objGlobalProperties = com.eviware.soapui.SoapUI.globalProperties; def regionToRun = objGlobalProperties.getPropertyValue("region") def regionArray = regionToRun.tokenize(); log.info regionArray //get original dataPath dataPath = context.expand( '${#TestCase#DataPath}' ) //get original dataFile dataFile = context.expand( '${#TestCase#DataFile}' ) //read current file FileInputStream fstream = new FileInputStream(dataPath +"/"+dataFile); DataInputStream data = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(data)); //find relevant lines and then write to another file while ((rowLine = br.readLine()) != null){ if(rowLine.contains("locale")){ headers = "$rowLine" log.info headers; } regionArray.each{ //if finds global property write to new file if(rowLine.contains(it) && !rowLine.contains("locale")){ //create temporary file def tempFile = File.createTempFile("temp" + dataFile, ".csv") //write revalent locales to temp file headers += "\n$rowLine" tempFile.write headers log.info headers //set the datasource to the temp file def dataSourceStep = testRunner.testCase.getTestStepByName("DataSource") dataSourceStep.getDataSource().setFileName(tempFile.absolutePath) } } } data.close(); } }
nmrao
5 years agoChampion Level 3
To re-use the code, please read below article:
http://rupertanderson.com/blog/1-how-to-develop-add-and-use-a-custom-groovy-library-in-soapui/
http://rupertanderson.com/blog/1-how-to-develop-add-and-use-a-custom-groovy-library-in-soapui/
Related Content
- 5 years ago678
Recent Discussions
- 22 hours agodipsthorat
- 2 days agoisbiat
- 2 days agoarmygrad