zoukankan      html  css  js  c++  java
  • 如何重写LoadRunner的函数?

    参考:

    http://ptfrontline.wordpress.com/2010/06/22/overriding-lr-functions-with-custom-code/

    Most people do not know that LR supports overriding existing functions with custom ones in a very easy way.

    I had a situation where I had a pre-made script that had fixed think-time values for the lr_think_time() calls, and they of course were completely wrong. So my problem was that I had a lot of lr_think_time() places and I didn’t want to go through them all myself. 

    In most cases a search-and-replace would do the trick, but I stumbled upon the overriding of functions and implemented it that way instead, making my changes to the script stay in one place only instead of manipulating all the actions in the script.

    Remember: DO NOT CALL THE OVERRIDDEN FUNCTION INSIDE THE NEW CODE!!! – You’ll just end up with an endless loop, and terminate in stack-errors or similar…

    Here’s an empty script where I’ve overridden the lr_think_time() function with a custom one:

    01 #define lr_think_time my_think_time  // This define overrides lr_think_time() with my_think_time()
    02   
    03 double my_think_time(double sec)
    04 // This simulates the 50% to 150% think-time randomness ...
    05 {
    06     double x;
    07   
    08     x = ((50.0+rand()%100)/100)*sec; // 50% to 150% randomness
    09   
    10     lr_force_think_time( x ); // force the think time (this is undocumented command)
    11   
    12     return x; // return how many seconds we waited
    13 }
    14   
    15 ///////////////////////////////////////////////////////////////////////////////
    16   
    17 Action()
    18 {
    19     lr_think_time(10); // This will use the my_think_time() function !!
    20   
    21     return 0;
    22 }

    One could get creative and start overriding all sorts of functions with this. An example would be to set specific headers for specific web_url() calls depending on the params. You could override the web_url() call, examine the parameters and add any needed HTTP headers before doing a web_custom_request() instead ..

    Enjoy!

  • 相关阅读:
    ADERA3 省选模拟赛 SPOJ LMCONST
    TYVJ 1730 二逼平衡树 线段树套平衡树
    BZOJ 1059 [ZJOI2007]矩阵游戏 二分图匹配
    BZOJ 1056 [HAOI2008]排名系统 Splay+Hash
    OI教会我的
    BZOJ 1055 [HAOI2008]玩具取名 DP
    BZOJ 1058 [ZJOI2007]报表统计 Splay
    为自己而奋斗
    [总结]高斯消元&XOR方程
    我 的 2013
  • 原文地址:https://www.cnblogs.com/preftest/p/2053890.html
Copyright © 2011-2022 走看看