Use soapui to randomly retrieve data from the database for ws stress testing

Source: Internet
Author: User
Tags soapui groovy script

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.