Problem: We perform an interface stress test first to generate a test URL, test the URL part of the field to be MD5 encrypted, how to generate such a test URL?
There are two scenarios for such testing:
1. Use Java script to generate a batch of encrypted test URLs, then put this batch of data into the LR parameter library, write C script to call
2. Encapsulate MD5 encryption class, and package the build test URL class into Lr-classpath so that you can write Java script in LR to call the jar package to generate the test URL automatically.
Note: LR11 in the Controller run C script support 10000 users, run Java Script Support 1000 users; LR12 only supports 50 users, if you want to use LR12 run pressure test, can write thread pool to improve the number of virtual users;
We use the second method, first to create a new Java project in Eclipse, and then to add the classes we need, the main method parameters of the interface (Filmnew.java/plans.java) class that encapsulate the interface, and then the underlying class (Md5.java /getenc.java/timesimple.java) generates the encrypted data, and the external calling class (Vug.java) is used to generate the test URL, as shown in the following structure:
1. In Filmnews.java and Plans.java, mainly through the HashMap storage interface parameters are as follows:
Hall interface Public hashmap<string, string> hallsbycinemaid (String cinemaid) {hashmap<string, string> params = new Hashmap<string, string> ();p arams.put ("Method", "Gethallsbycinemaid");p arams.put ("UID", uid);p arams.put (" Cinemaid ", Cinemaid); Movie ID to generate the return params dynamically;}
2.md5.java algorithm can go to Baidu, the following list Timesimple.java to get a day date method is as follows:
@SuppressWarnings ("static-access") public static String nextdatasimple (int index) {date date=new date ();//calendar Calendar = new GregorianCalendar (); Calendar.settime (date); Calendar.add (Calendar. DATE,INDEX);//The date obtained by index date=calendar.gettime (); Get a day date simpledateformat SDF = new SimpleDateFormat ("Yyyy-mm-dd"); return Sdf.format (date);}
3.vug.java is primarily an incoming host with (Filmnews.java returned) HashMap the method of generating the test URL as follows:
public string GetURL (string host, hashmap<string, string> params) {StringBuilder url = new StringBuilder (); Url.append (host + "?"); Params.put ("Time_stamp", String.valueof (New Date (). GetTime ())); String enc = Getenc.getenc (params, Md5key), for (Entry<string, string> e:params.entryset ()) {Url.append (E.getkey ( ) + "=" + e.getvalue () + "&");} Url.append ("enc=" + enc); return url.tostring ();}
4. When these scripts are ready to be completed, we need to export the jar package, through the above can see that I am using JDK1.7, and LR11 does not support JDK1.7 exported jar package, we need to change to JDK1.6 export jar;
Right-click the project-properties-java compiler-to change the JDK compliance to 1.6 and then in the Export-jar file
5. Export the jar package, and then import the jar package into Lr11-java vuser-run-time Settings-classpath as shown:
Once the configuration is complete, you can then invoke the methods in the jar with the actions interface
LoadRunner + Java Script chapter II