Forum Discussion

Scripter's avatar
Scripter
Occasional Contributor
9 years ago

Passing value from external XML file to project/testsuite property and executing groovy script

I have an external XML config file which looks like below.  I have to pass this value of "oracle" [from property name="ConnectedDB"] to soapui project properties or test suite properties

  •  <property name="mail">	
           <entry key="server" value="outlook"/>
      </property>
    <property name="housekeep">
    		<entry key="files.days" value="60"/>
    		<entry key="logs.days" value="30"/>
    </property>
    <property name="ConnectedDB">
    		<entry key="name" value="oracle" />
    		<entry key="table1" value="tableA" />
    		<entry key="table2" value="tableB"/> 
    </property>

    Once I know which database my software is connected to, I can run groovy script depending on database.

    I have 5 databases to choose from

Currently, I am running all 5 scripts at once. (which is a bad idea considering the software is connected to one database at one time)

I don't know if its possible or not. May be an idea or something... if its not possible, I would appreciate another alternative idea which could be implemented by me.

1 Reply

  • nmrao's avatar
    nmrao
    Champion Level 3
    Is it that you the sql query is different for different data base type which is why you kept different groovy script step for each?

    First, I would suggest to use single groovy to handle all.

    Use map to get different details such class name / connection string / query etc for each db type.

    Coming to your main question, you can read xml in the groovy to get the respective value using XmlSlurper which is very easy. Please see an example below
    http://mrhaki.blogspot.in/2009/10/groovy-goodness-reading-xml.html