Groovy - setPropertyValue for a value in a file and using it in the same script
Hi folks, I've been trying to read values from a CSV via a script and use them within the same script to login to a db. I've got the db login and SQL query running when hard coded the DB login details and not using this CSV file, however lots of different people will be using this script who all have different properties etc so i would like to make it dynamic rather than having to manually change it every time. Each person will have a csv file with 5 values in which this script will refer to. I'm quite new to this and here is what i have so far but i'm getting "groovy.lang.MissingPropertyException: No Such property: DBServer for class" The fileReader code i have is taken from another script i have which does work when referencing in a soap request, however i want to try do a similar thing but refer in the same groovy script import groovy.sql.Sql import java.sql.* com.eviware.soapui.support.GroovyUtils.registerJdbcDriver("com.microsoft.sqlserver.jdbc.SQLServerDriver") context.fileReader = new BufferedReader(new FileReader("C:\\tmp\\GroovySQL.csv")) firstLine = context.fileReader.readLine() String[] propData = firstLine.split(",") testRunner.testCase.testSuite.project.setPropertyValue("DBServer",propData[0]) testRunner.testCase.testSuite.project.setPropertyValue("DBDatabase",propData[1]) testRunner.testCase.testSuite.project.setPropertyValue("DBPort",propData[2]) testRunner.testCase.testSuite.project.setPropertyValue("DBUser",propData[3]) testRunner.testCase.testSuite.project.setPropertyValue("Password",propData[4]) //Connect to the DB String db_server = "{$DBServer}" String db_database = "{$DBDatabase}" String db_port = "{$DBPort}" String db_user = "{$DBUser}" String db_password = "{$DBPassword}" String connectionUrl = "jdbc:sqlserver://" + db_server + ":" + db_port + ";database=" + db_database + ";user=" + db_user + ";password=" + db_password; sql = Sql.newInstance( connectionUrl, "com.microsoft.sqlserver.jdbc.SQLServerDriver") //Read data sql.eachRow('select USER_ID from SP085_USERS') { p -> log.info "First Name = ${p.USER_ID}" } sql.close() Any help would be appreciated!Solved3KViews0likes2CommentsCalculate within the request before sending - Property Expansion, Dynamic Properties, Request
Hey, i would like to calculate a value within the request based on another property. The current issue i have is that he calculates the value but the soap request isnt correct or he dont calculate and the value is correct. Counter=01,02,03-20 <---always needs an leading 0, till 10 is reached. But with an leading 0 the code dosent work. ${=def bla=${#TestSuite#Counter};bla.plus(1); } What i want to archive, if "count" is less than 10, add an leading 0, if its bigger than 9, do nothing. But at both situations i need to increase it by 1. Best Regards Sten FladeSolved1.9KViews0likes4Comments