Soapui supports groovy scripts, so we can customize groovy scripts to get databases from the database and modify the values of the XML nodes in the request before sending them, in order to obtain random data for stress testing, this can make the test results more realistic.
Soapui itself does not have a jar package with database-related drivers. According to its requirements, we put the database-related drivers under the $ soapui_home/bin/EXT directory and in LoadRunner. in bat, set classpath adds the ext directory to the row, and the modification looks like this:
set CLASSPATH=%SOAPUI_HOME%soapui-3.6.1.jar;%SOAPUI_HOME%..\lib\*;%SOAPUI_HOME%..\bin\ext\*;
The driver is ready. Now we can write a groovy script for getting data and open your loadtest (you cannot upload images in the company, and I can't help you if I don't know ), write your own data acquisition script in "setup script", which is roughly as follows:
import groovy.sql.SqlProperties properties = new Properties();properties.load(new FileInputStream("somedirecotry/home/dataSource.properties"));config = new ConfigSlurper().parse(properties);Sql sql=Sql.newInstance(config.url,config.username,config.password,config.driverClassName);List<String> someDataList = new ArrayList<String>();sql.eachRow("select somecolumn from sometable"){row ->someDataList.add(row.somecolumn);}context.setProperty("someDataList",someDataList);println "****************************************setup end**********************************************";
The reason why data is written in load test is that before each stress test is executed, this will be executed once and only once, similar to the beforeclass method of unit test, we can use the data obtained here directly in the test step. If we put this script for getting data in every test step, this means that each test needs to obtain data from the database. Similar to the before method of unit test, each test will be executed once, which will greatly affect the test result.
If the data has been obtained, you can use it in test step. Remember to get the data in loadtestcontext, and add "groovy Script test step" at the beginning of test step ", here we use the data obtained from load test:
// Remember that the data must be obtained from loadtestcontext list <string> somedatalist = context. getproperty ("loadtestcontext "). getproperty ("somedatalist"); random r = new random (); string somedata = ""; // obtain if (ptflnos! = NULL &&! Ptflnos. isempty () {int Index = R. nextint (somedatalist. size ()-1); somedata = somedatalist. get (INDEX) ;}println somedata; def policyutils = new COM. eviware. soapui. support. policyutils (context); def holder = policyutils. getxmlholder ("request1 # request"); // write the value to holder in the request XML. setnodevalue ("// soapenv: body/SAES: somedatarequest/SAES: some_field", somedata); groovyutils. setpropertyvalue ("request1", "request", Holder. prettyxml );
Of course, do not forget to add the test step to the test step. Otherwise, test what.