Performance Test --Jmeter example of wordpress

Jmeter example of wordpress

WordPress is using PHP language development blog platform, users can set up their own Web site on the server that supports PHP and MySQL database. Can also WordPress as a content management system (CMS) to use, Wordress installation .

First, the user login, multi-user login

1, step details

Single-user login:
1, opened with a text editor bin / user.properties jmeter installation file path, coupled with his CookieManager.check.cookies = false at the most end of the file (the cookie jmeter checking mechanism to the closed off, this is because wordpress non-compliant jmeter when a cookie is set to log, jmeter discards the cookie when logged in, leading to the results recorded can not log in playback)
2, open the <a href="http://www.cnblogs.com/Keep-Ambition/p/8381441.html" target="_blank"> jmeter recording function </a>, browser and enter your_ip_port / wp- login.php landing operation
3, delete recorded script redundant nodes, the GET /wordpress/wp-login.php request was renamed as the login form, will be renamed POST /wordpress/wp-login.php request submit login form in order to
4, click Run
 
Multi-user login:
1, the script on the basis of the above, increasing the user-defined variable configuration element, an increase in the four variables element: (user1 = admin, password1 = amdin, user2 = test24, password2 = tes124)
2, the transaction controller to modify the name of login user $ {__ threadNum}, GET /wordpress/wp-login.php modification request name login form user $ {__ threadNum}
3, change the name request is POST /wordpress/wp-login.php submit login form user $ {__ threadNum}, modify the value of the log request parameters: $ {__ V (user $ {__ threadNum})}, pwd is $ {__V (password $ {__ threadNum})}
4, modify the thread group, modify the number of threads 2, Ramp-up Period 2 was modified
5, click Run

2, landing renderings:

3, increase assertion (in a real load test, it will disable the swap assertion, because the assertion will take up cpu and memory, thus affecting the efficiency of concurrent jmeter of)

The above example can be judged by the response data in the search for a user name to log the user's way if the user logs in successfully, the time when much of virtual users, this is possible. But if there are hundreds or thousands of virtual users, we need to assert a judge

Step details:

    1 on the right point, the POST /wordpress/wp-login.php request, i.e. name submit login form user $ {__ threadNum} requests, select Add -> postprocessor -> CSS / JQuery Extractor.

    • Reference name to: user_name (variable name, followed by the need to get the value of this variable name) 
    • CSS / JQuery expression: # wp-admin-bar-my-account .ab-item (for HTML element is positioned with CSS selectors)
    • Match numbers: 1 (if there are multiple matching elements, the first element only take values)

    2, POST /wordpress/wp-login.php request, i.e. name submit login form user $ {__ threadNum} right point on the request, select Add -> assertions -> JSR223 Assertion. Language selection javascript, enter the following code in the Script:

welcomeMessage = vars.get ( "user_name"); // fetch values ​​defined immediately post-processor
username = welcomeMessage.split ( ",") [1] .trim (); // The comma slices, remove spaces, acquiring user name
vars.put ( "username", username); // user name re-assignment, then add the vars jmeter's                 
threadNum = ctx.getThreadNum () + 1; // Returns the current thread num
 
// If you remove the user name from the user-defined variable names follow the user landing page elements inside out is inconsistent, it is determined that there is no successful landing
AssertionResult.setFailure(!(vars.get("user" + threadNum) == username));
AssertionResult.setFailureMessage (username + "Login failed for user ');

An upgraded version of the assertion, can show a clear cause of login failure:

welcomeMessage = vars.get ( "user_name"); // Get defined immediately post-processor such as the variable value Hi, admin string
threadNum = ctx.getThreadNum () + 1; // Get the number of the current thread
expectLoginUser = vars.get ( "user" + threadNum); // get the user-defined variables user1
 
if (welcomeMessage === null) {// if did not get the login welcome message, so that the login fails
    AssertionResult.setFailure (true); // direct assertion failure
    AssertionResult.setFailureMessage (expectLoginUser + "user login fails, you may be a user name and password do not match"); // Set the assertion failure message
} Else {// If we can get to the welcome message, Minden card into the background
    username = welcomeMessage.split ( ",") [1] .trim (); // The comma slices, remove spaces, acquiring user name
    vars.put ( "username", username); // debugging
 
    AssertionResult.setFailure ((expectLoginUser == username)!); // if user is not our board into to fill in the form user, an assertion failure
    AssertionResult.setFailureMessage (username + "Login failed for user '); // set the failure message
}

Note: 

jmeter unique variable doubts:

  • vars: jmeter variables, including user-defined variables in the document here
  • ctx: jmeter context, can be (starting from 0, so the code should threadmun + 1) to get through this variable number of the current process, in particular document here
  • AssertionResult: Assertion result, AssertionResult.setFailure(true)will make an assertion failure, specific documentation poke here

4, the effect of assertion FIG containing:

 Note: Debug Sampler This sampler assembly, although variable name will print out the test plan provides debugging

 

Second, create an article

Use jmeter to achieve the creation of blog posts functions

1, step details:

1, open jmeter recording capabilities, the browser opens wordpress / wp-admin / post-new.php page, create a blog to record
2, after recording is finished, remove the extra node controller retention login transaction, a new transaction controller, the upper 2 onto the transaction request to the following controller, the controller changes the name of the transaction to create post user $ {__ threadNum }, the GET /wordpress/wp-admin/post-new.php name changed to create post form, the POST /wordpress/wp-admin/post.php name changed to submit create post form
Right click on the create post form node and select Add -> postprocessor -> CSS / JQuery Extractor
(The name changed to get user_id, reference name to post_id, CSS / JQuery Expression: # post_ID, Attribute: value, matching numbers: 1, the default value: NOT FOUND)
3, then create a CSS / JQuery Extractor, is still placed in the create post form
(Modify the name get user_id, reference name to user_id, CSS / JQuery Expression: # user-id, Attribute: value, matching digits: 1, Default: NOT FOUND)
4, POST /wordpress/wp-admin/post.php request modification request parameters (user_ID: $ {user_id}, post_author: $ {user_id}, post_title: $ {__ RandomString (10, abcdefghijklmnopqrstuvwxyz)}, content: $ {__ RandomString (10, abcdefghijklmnopqrstuvwxyz)}, post_ID: $ {post_id}, post_author_override: $ {user_id})
5. Save and run

2, FIG effect:

 Note: If you create an article, the server returned to the 403, this is because: wordpress checks an article called when processing a request to create a _noncerequest parameters, when we create an article open page in a browser _nonce's value will generation, that is to say if we pass jmeter playback request, then _noncethe value is no way server with the desired value for the number, which is wordpress prevent Cross-Site request Forgery (CSRF) way.

Solution:
find wordpress installation directory, locate the wp-includes/pluggable.phpfile, use a text editor to open in function wp_verify_nonce( $nonce, $action = -1 ) {the next function, add a new row return 1;, save.

function wp_verify_nonce( $nonce, $action = -1 ) {
  return 1;
    $ Nuncio = (string) $ nuncio;
    $user = wp_get_current_user();
    $uid = (int) $user->ID;
    if ( ! $uid ) {
    ....
    ....
    ....

 return 1, is to let wordpress in check _nonce when returns true forever, reached a temporary shut down to prevent CSRF role.

 

Third, the article visit

Visitors inside the analog read blog articles, the logic is implemented for visitors first visit blog home page, then randomly select an article to read on the home page

1, step details:

  • 1.1, a new build-web-test-plan test plan
  • 1.2, the number of times the thread loop into which the group: 1
  • 1.3, IP and port in home page http request is replaced in the blog home page address
  • 1.4, a new CSS / JQuery Extractor in home_page, the name changed tochoose a post
    • Reference name: rand_post_href
    • CSS/JQuery expressions: .entry-title>a
    • Attribute: href
    • Matching numbers: 0
    • Default value: NOT FOUND
  • 1.5, a new JSR223 PostProcessor at Home_Page, modify the nameget post id
    • Language: javascript
    • Script:
var href = vars.get('rand_post_href'); if(href) { var id = href.split('=')[1] vars.put("rand_id", id); }
  • 1.6 if a new controller, the name is modified if rand_id exists conditions: 
$ {Rand_id}! = Null // if the article id is not empty
  • 1.7 Create a http request in if the controller sampler, Name:view post ${rand_id},请求器中的IP和port换成博客首页地址 
    • Request parameters:p = ${rand_id}(如http://localhost/wordpress/?p=123)里抓取了123,这是随机访问文章的id里抓取了123,这是随机访问文章的id)
  • 1.8, save and run.

2, FIG effect:

Guess you like

Origin www.cnblogs.com/doumingyi/p/12457379.html