Load Properties from ini file
The Example code below explains how do we get the ini file located in the system. Which get the properties and saves as global properties.def loadProperties(path){//Loads the file settings.inidef properties = new java.util.Properties();properties.load( new java.io.FileInputStream( “c:/settings.ini” ))return properties}Place the above code in a test.groovy file and call using the below codedef test=new test();prop=test.loadProperties();ProjProps = context.getTestCase().getTestSuite().getProject();//gets the host property and its valuedef host = prop.getProperty(“URL”,”localhost”);//settings the host property and value to global project properties.context.getTestCase().getTestSuite().getProject().setPropertyValue(“host”,host);//displays the host URL information in log filelog.info(host);ProjProps.setPropertyValue(“databaseurl”, props.getProperty(“databaseurl”))Example://Importing package SQLimport groovy.sql.Sql//defining objects of type java util propertiesdef properties = new java.util.Properties();//reading the settings.ini filedef file = new File(“c:/settings.ini”);//verifying the file exists and can read the file.if (file.canRead()){FileInputStream fis = new FileInputStream(file);properties.load(fis);fis.close();}//Establishing the DB connectiondef sql = Sql.newInstance(“jdbc:oracle:thin:@” + properties.getProperty( “dburl” ) + “:” +properties.getProperty( “dbport” ) + “:” + properties.getProperty( “db” ) , properties.getProperty(“dbuser”) ,properties.getProperty( “dbpassword” ), “oracle.jdbc.OracleDriver”)//defining groovy util objectdef groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )//defining groovey holders for response xmldef holder = groovyUtils.getXmlHolder( “Admin#Response” )//gettings node valuesdef items = holder.getNodeValues( “//ns2:Admin/orgUIDs”)// To find the count/# of nodes (log.info( “Found ” + items.length + ” items..” ))//Get the value of response into a variabledef Value=items[0]log.info(Value)//Gets the db value from DB into variable.def Dbvalue=sql.firstRow(“Select UNIT_UID from Org where ORG_UID=’$Value'”)log.info(Dbvalue.UNIT_UID)//compares the value of response is in DB.if (Value==Dbvalue.UNIT_UID){log.info(“the value of response “+Value+ ” = “+Dbvalue.UNIT_UID)}else{log.warn(“the value of response “+Value+ ” != “+Dbvalue.UNIT_UID)throw new Exception(“Test Failed as the value from response xml and DB are miss matching”)}
Categories: SoapUI
Comments (0)
Trackbacks (0)
Leave a comment
Trackback