LoadRunner calls Java class

Source: Internet
Author: User

From: http://www.51testing.com/html/56/n-130456.html

Recent company needsTestAlthough I think this is alreadyWhite box testingBut if the leadership asks for this, I have to study the technology. the requirement is that you can pass parameters to the class, receive the parameters returned by the class, and judge whether the parameters are correct or not.

  Step 1: Overall Thinking.

I used to use LoadRunner for direct recording, but some protocols are difficult to understand how to record, such as VB, C ++, the simplest way to do things in Java is to directly call related class files, dynamically link libraries, and directly call them using code. In this way, I tried to write a program call in LoadRunner.JavaClass.

 Step 2: Perform Java classes that meet the requirements.

To tell the truth, it is too difficult for me to understand java. Fortunately, I know C ++, but I have never seen Java coding methods and compiling environments. Learn it slowly and ask a lot. It's hard to get it done at the very beginning. First, install j2sdk on the system disk ., Add % java_home % \ bin to the system environment variable. Then, you can use the CMD command to compile and run Java. The compiling and running commands are respectively run javac under the Java class directory you write.Test. Java and Java test parameters. For example, if your class is in the C: \ test directory, you should use CD \ test in cmd and go to this directory, use javac test. java and Java test parameters.

I found a simple ready-made Java class on the Internet and now put the source code below.

 

Code
Package main;

 

Import java. Io. printstream;

 

Public class birthday

 

{

 

Public String year;

 

Public String month;

 

Public String Day;

 

Public birthday ()

 

{

 

Year = "1900 ";

 

Month = "01 ";

 

Day = "01 ";

 

}

 

Public birthday (string y, string M, string D)

 

{

 

Year = y;

 

Month = m;

 

Day = D;

 

System. Out. println ("OK ");

 

}

 

Public String getbirthday ()

 

{

 

String fullbirthday = month + '/' + day + '/' + year;

 

Return fullbirthday;

 

}

 

}

 

Class is very simple. It is easy to compile with the above method.

  Step 3: Call this class in LoadRunner.

After thinking for a long time, I decided to use the Java vuser script to write Java code. This code must be written. After getting familiar with the Java language for a while, I decided to use import to introduce the class, so the problem came again ,*. where should the class file be stored? The intermediate test process is not shown yet. Just write the final result here. Now I get the result of storing the *. Class file in the classes \ main directory of the LoadRunner installation path. This step is easily completed by understanding Java, including the path and import statements.

The Java code in loadruner is as follows:

 

Code
Import lrapi. lr;

 

Import main. birthday;

 

Public class actions

 

{

 

Public int Init (){

 

Return 0;

 

} // End of init

 

Public int action (){

 

Birthday Bir = new birthday ("1981", "6", "1 ");

 

// Bir. getbirthday

 

System. Out. println (BIR. getbirthday ());

 

Return 0;

 

} // End of action

 

Public int end (){

 

Return 0;

 

} // End of end

 

}

 

Note: The class is called and initialized, and parameters are passed in. Finally, the class method is called, a value is returned, and the value is printed, it is easy to check whether the value is correct.

One day of accumulation!WorkOn my seat.

Finally, I found that LoadRunner has a detailed introduction. Ah, I feel like I am in English!

Finally, we found that the path of the LoadRunner import class can be set by ourselves, and we do not need to put all the classes under the classes directory, you can set the specific settings in the class path entry in runtime settings. Every script can be set like this. The laodrunner layout issues related to how to obtain scripts for specific concurrency.

Note:

Last night, I found that if the Java class interface is an array or another type of parameter, LoadRunner would be very difficult to process. It is necessary to convert the interface into a simple type for parameterized processing.

Imported a simple class file yesterday. If this class is called againOthersClass, other classes in the jar package, do not need to decompress the jar package, and then import the classes one by one, just add the relevant jar package path in classpath.

 

Related Article

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.