zoukankan      html  css  js  c++  java
  • loadrunner12.55:常用函数汇总说明之Transaction Functions参数函数

    根据使用手册内容可见,LR支持的关于Transaction Functions包括:

    lr_end_cross_vuser_transaction Marks the completion in this Vuser of a transaction started by a different Vuser.
    lr_end_sub_transaction Marks the end of a sub-transaction.
    lr_end_transaction Marks the end of a transaction.
    lr_end_transaction_instance Marks the end of a transaction instance.
    lr_fail_trans_with_error Sets the status of open transactions to LR_FAIL and sends an error message.
    lr_get_trans_instance_duration Returns the duration of a transaction instance specified by its handle.
    lr_get_trans_instance_status Returns the current status of a transaction instance.
    lr_get_trans_instance_think_time Gets the think time of a transaction instance specified by its handle.
    lr_get_trans_instance_wasted_time Gets the wasted time of a transaction instance by its handle.
    lr_get_transaction_duration Gets the duration of a transaction by its name.
    lr_get_transaction_status Gets the current status of a transaction.
    lr_get_transaction_think_time Gets the think time of a transaction by its name.
    lr_get_transaction_wasted_time Gets the wasted time of a transaction by its name.
    lr_resume_transaction Resumes collecting transaction data.
    lr_resume_transaction_instance Resumes collecting transaction instance data.
    lr_set_transaction Create a transaction manually.
    lr_set_transaction_instance_status Sets the status of a transaction instance.
    lr_set_transaction_status Sets the status of open transactions.
    lr_set_transaction_status_by_name Sets the status of a transaction.
    lr_start_cross_vuser_transaction Initiates a transaction that is closed in one or more Vusers other than the initiating Vuser.
    lr_start_sub_transaction Marks the beginning of a sub-transaction.
    lr_start_transaction Marks the beginning of a transaction.
    lr_start_transaction_instance Starts a nested transaction specified by its parent's handle.
    lr_stop_transaction Stops the collection of transaction data.
    lr_stop_transaction_instance Stops collecting data for a transaction specified by its handle.
    lr_wasted_time Sets the wasted time for all open transactions.

    1、lr_start_transaction  &  lr_end_transaction

     设定订票系统的登录事务login:

    lr_start_end_transaction_Func()
    {
    
    /*Correlation comment - Do not change!  Original value='131159.414823815zHtzfVcpttAtHQpAHtt' Name ='userSession' Type ='ResponseBased'*/
    	web_reg_save_param_ex(
    		"ParamName=userSession",
    		"LB=name="userSession" value="",
    		"RB="/>
    <table border",
    		SEARCH_FILTERS,
    		"Scope=Body",
    		"IgnoreRedirections=No",
    		"RequestUrl=*/nav.pl*",
    		LAST);
    
    	web_url("WebTours", 
    		"URL=http://127.0.0.1:1080/WebTours/", 
    		"Resource=0", 
    		"RecContentType=text/html", 
    		"Referer=", 
    		"Snapshot=t8.inf", 
    		"Mode=HTML", 
    		LAST);
    
    	lr_start_transaction("login");
    
    
    	web_submit_data("login.pl",
    		"Action=http://127.0.0.1:1080/cgi-bin/login.pl",
    		"Method=POST",
    		"RecContentType=text/html",
    		"Referer=http://127.0.0.1:1080/cgi-bin/nav.pl?in=home",
    		"Snapshot=t9.inf",
    		"Mode=HTML",
    		ITEMDATA,
    		"Name=userSession", "Value={userSession}", ENDITEM,
    		"Name=username", "Value=jojo", ENDITEM,
    		"Name=password", "Value=bean", ENDITEM,
    		"Name=JSFormSubmit", "Value=on", ENDITEM,
    		"Name=login.x", "Value=0", ENDITEM,
    		"Name=login.y", "Value=0", ENDITEM,
    		LAST);
    	
    	lr_end_transaction("login", LR_AUTO);
    
    	web_image("Search Flights Button", 
    		"Alt=Search Flights Button", 
    		"Snapshot=t10.inf", 
    		LAST);
    
    	web_submit_form("reservations.pl", 
    		"Snapshot=t11.inf", 
    		ITEMDATA, 
    		"Name=depart", "Value=Denver", ENDITEM, 
    		"Name=departDate", "Value=04/24/2021", ENDITEM, 
    		"Name=arrive", "Value=London", ENDITEM, 
    		"Name=returnDate", "Value=04/25/2021", ENDITEM, 
    		"Name=numPassengers", "Value=1", ENDITEM, 
    		"Name=roundtrip", "Value=<OFF>", ENDITEM, 
    		"Name=seatPref", "Value=None", ENDITEM, 
    		"Name=seatType", "Value=Coach", ENDITEM, 
    		"Name=findFlights.x", "Value=52", ENDITEM, 
    		"Name=findFlights.y", "Value=6", ENDITEM, 
    		LAST);
    
    	web_submit_form("reservations.pl_2", 
    		"Snapshot=t12.inf", 
    		ITEMDATA, 
    		"Name=outboundFlight", "Value=020;338;04/24/2021", ENDITEM, 
    		"Name=reserveFlights.x", "Value=36", ENDITEM, 
    		"Name=reserveFlights.y", "Value=5", ENDITEM, 
    		LAST);
    
    	web_submit_form("reservations.pl_3", 
    		"Snapshot=t13.inf", 
    		ITEMDATA, 
    		"Name=firstName", "Value=Jojo", ENDITEM, 
    		"Name=lastName", "Value=Bean", ENDITEM, 
    		"Name=address1", "Value=", ENDITEM, 
    		"Name=address2", "Value=", ENDITEM, 
    		"Name=pass1", "Value=Jojo Bean", ENDITEM, 
    		"Name=creditCard", "Value=", ENDITEM, 
    		"Name=expDate", "Value=", ENDITEM, 
    		"Name=saveCC", "Value=<OFF>", ENDITEM, 
    		"Name=buyFlights.x", "Value=47", ENDITEM, 
    		"Name=buyFlights.y", "Value=9", ENDITEM, 
    		LAST);
    
    
    	web_image("SignOff Button", 
    		"Alt=SignOff Button", 
    		"Ordinal=1", 
    		"Snapshot=t14.inf", 
    		LAST);
    
    	return 0;
    }
    

     显示事务完成响应时间时0.1504秒,执行函数web_submit_data本身消耗的时间是0.0083秒。

     2、lr_start_sub_transaction  &  lr_end_sub_transaction

    lr_start_end_sub_transaction()
    {
    	int i, baseIter = 10;
        char dude[1000];
    //Start Parent
        lr_start_transaction("Master");
    //Start first sub transaction
        lr_start_sub_transaction("FirstT", "Master");
    //Start nested child of first sub transaction
        lr_start_sub_transaction("FirstT_Child1", "FirstT");
     // Artificially create some elapsed time
            for (i=0; i<(20 * baseIter); ++i)
                sprintf(dude, 
                    "This is the way we kill time in a script = %d", i);
                
        lr_end_sub_transaction("FirstT_Child1",LR_AUTO);
    // Start second nested child
        lr_start_sub_transaction("FirstT_Child2", "FirstT");  
    // Artificially create some elapsed time
            for (i=0; i<(20 * baseIter); ++i)
                sprintf(dude, 
                    "This is the way we kill time in a script = %d", i);
    	lr_end_sub_transaction("FirstT_Child2",LR_AUTO);
        lr_end_sub_transaction("FirstT",LR_AUTO);
        //Start a second sub transaction
        lr_start_sub_transaction("SecondT", "Master");    
            for (i=0; i< (20 * baseIter); ++i)
                sprintf(dude, 
                    "This is the way we kill time in a script = %d", i);            
        lr_end_sub_transaction("SecondT",LR_AUTO);
        lr_end_transaction("Master", LR_AUTO);
    
    
    	return 0;
    }
    

      

     3、lr_stop_transaction  &  lr_resume_transaction

     此处不再进行具体举例说明,推荐使用lr_start_sub_transaction和lr_set_transaction。

    4、lr_set_transaction

    lr_set_transaction_Func()
    {
    	lr_set_transaction("Multiple_Orders", 45.3, LR_PASS);
    	return 0;
    }
    

      

     5、lr_set_transaction_status

    lr_set_transaction_status_Func()
    {
    	int i, baseIter = 10;
        char dude[1000];
    //Start Parent
        lr_start_transaction("Master");
        
     // Artificially create some elapsed time
        for (i=0; i<(20 * baseIter); ++i)
            sprintf(dude, 
                "This is the way we kill time in a script = %d", i);
        
        //Start a second sub transaction
        lr_start_sub_transaction("FirstT", "Master");    
    	    for (i=0; i< (20 * baseIter); ++i)
    	        sprintf(dude, 
    	            "This is the way we kill time in a script = %d", i);
    	    
    			if (i>1)//超过1秒则修改事务状态为失败
    			    lr_set_transaction_status(LR_FAIL);	
    
    	
    	lr_end_sub_transaction("FirstT",LR_AUTO);
    
        
        lr_end_transaction("Master", LR_PASS);
            
    	return 0;
    }
    

      

     可以看到,事务FirstT的状态被修改为Fail,而Master事务的状态不受影响。

    6、lr_set_transaction_status_by_name

    lr_set_transaction_status_by_name_Func()
    {
    	int i, baseIter = 10;
        char dude[1000];
    //Start Parent
        lr_start_transaction("Master");
        
     // Artificially create some elapsed time
        for (i=0; i<(20 * baseIter); ++i)
            sprintf(dude, 
                "This is the way we kill time in a script = %d", i);
        
        //Start a second sub transaction
        lr_start_sub_transaction("FirstT", "Master");    
    	    for (i=0; i< (20 * baseIter); ++i)
    	        sprintf(dude, 
    	            "This is the way we kill time in a script = %d", i);
    	    
    			if (i>1)//超过1秒则修改事务状态为失败
    			    lr_set_transaction_status_by_name(LR_FAIL,"FirstT");	
    
    	
    	lr_end_sub_transaction("FirstT",LR_AUTO);
    
        
        lr_end_transaction("Master", LR_AUTO);
    	return 0;
    }
    

     可以看到根据子事务FirstT的名称将其LR_AUTO状态成功修改为LR_FAIL,但是父事务Master不受影响。

    7、lr_get_transaction_duration

    lr_get_transaction_duration_Func()
    {
    	double trans_time;
    	int status;
    /*Correlation comment - Do not change!  Original value='131159.414823815zHtzfVcpttAtHQpAHtt' Name ='userSession' Type ='ResponseBased'*/
    	web_reg_save_param_ex(
    		"ParamName=userSession",
    		"LB=name="userSession" value="",
    		"RB="/>
    <table border",
    		SEARCH_FILTERS,
    		"Scope=Body",
    		"IgnoreRedirections=No",
    		"RequestUrl=*/nav.pl*",
    		LAST);
    	
    	
    	web_url("WebTours", 
    		"URL=http://127.0.0.1:1080/WebTours/", 
    		"Resource=0", 
    		"RecContentType=text/html", 
    		"Referer=", 
    		"Snapshot=t8.inf", 
    		"Mode=HTML", 
    		LAST);
    		
    	lr_start_transaction("login");
    	
    	web_submit_data("login.pl",
    		"Action=http://127.0.0.1:1080/cgi-bin/login.pl",
    		"Method=POST",
    		"RecContentType=text/html",
    		"Referer=http://127.0.0.1:1080/cgi-bin/nav.pl?in=home",
    		"Snapshot=t9.inf",
    		"Mode=HTML",
    		ITEMDATA,
    		"Name=userSession", "Value={userSession}", ENDITEM,
    		"Name=username", "Value=jojo", ENDITEM,
    		"Name=password", "Value=bean", ENDITEM,
    		"Name=JSFormSubmit", "Value=on", ENDITEM,
    		"Name=login.x", "Value=0", ENDITEM,
    		"Name=login.y", "Value=0", ENDITEM,
    		LAST);
    	
    	lr_end_transaction("login", LR_AUTO);
    
    	web_image("Search Flights Button", 
    		"Alt=Search Flights Button", 
    		"Snapshot=t10.inf", 
    		LAST);
    
    	lr_start_transaction("Flight");
    	
    	//步骤1:选择航班出发地和目的地及座位属性
    	web_submit_form("reservations.pl", 
    		"Snapshot=t11.inf", 
    		ITEMDATA, 
    		"Name=depart", "Value=Denver", ENDITEM, 
    		"Name=departDate", "Value=04/24/2021", ENDITEM, 
    		"Name=arrive", "Value=London", ENDITEM, 
    		"Name=returnDate", "Value=04/25/2021", ENDITEM, 
    		"Name=numPassengers", "Value=1", ENDITEM, 
    		"Name=roundtrip", "Value=<OFF>", ENDITEM, 
    		"Name=seatPref", "Value=None", ENDITEM, 
    		"Name=seatType", "Value=Coach", ENDITEM, 
    		"Name=findFlights.x", "Value=52", ENDITEM, 
    		"Name=findFlights.y", "Value=6", ENDITEM, 
    		LAST);
    
    	//步骤2:选择乘坐航班
    	web_submit_form("reservations.pl_2", 
    		"Snapshot=t12.inf", 
    		ITEMDATA, 
    		"Name=outboundFlight", "Value=020;338;04/24/2021", ENDITEM, 
    		"Name=reserveFlights.x", "Value=36", ENDITEM, 
    		"Name=reserveFlights.y", "Value=5", ENDITEM, 
    		LAST);
    	
    
    	
    	//步骤3:完成支付
    	status=web_submit_form("reservations.pl_3", 
    		"Snapshot=t13.inf", 
    		ITEMDATA, 
    		"Name=firstName", "Value=Jojo", ENDITEM, 
    		"Name=lastName", "Value=Bean", ENDITEM, 
    		"Name=address1", "Value=", ENDITEM, 
    		"Name=address2", "Value=", ENDITEM, 
    		"Name=pass1", "Value=Jojo Bean", ENDITEM, 
    		"Name=creditCard", "Value=", ENDITEM, 
    		"Name=expDate", "Value=", ENDITEM, 
    		"Name=saveCC", "Value=<OFF>", ENDITEM, 
    		"Name=buyFlights.x", "Value=47", ENDITEM, 
    		"Name=buyFlights.y", "Value=9", ENDITEM, 
    		LAST);
    		
    	// Get transaction time to this point,即获取支付的时间
    	trans_time=lr_get_transaction_duration("Flight");
    	
    	 /* End transaction with operation result - pass or fail */
    	if (status == 0)
    	     lr_end_transaction("Flight", LR_PASS);
    	else
    	     lr_end_transaction("Flight", LR_FAIL);
    
    	
    	if (trans_time)
    	     lr_output_message("The duration up to the submit is %f seconds", trans_time);
    	else
    	     lr_output_message("The duration cannot be determined.");
    
    	web_image("SignOff Button", 
    		"Alt=SignOff Button", 
    		"Ordinal=1", 
    		"Snapshot=t14.inf", 
    		LAST);
    
    	return 0;
    }
    

     

     可以看到,lr_get_transaction_duration函数获取的响应时间0.286135秒与事务结束时统计的响应时间为0.2901秒非常接近,这是因为我将lr_get_transaction_duration插在了事务结束的前面。

    8、lr_get_transaction_think_time

    lr_get_transaction_think_time_Func()
    {
    	double think_time;
    	int status;
    
    /*Correlation comment - Do not change!  Original value='131159.414823815zHtzfVcpttAtHQpAHtt' Name ='userSession' Type ='ResponseBased'*/
    	web_reg_save_param_ex(
    		"ParamName=userSession",
    		"LB=name="userSession" value="",
    		"RB="/>
    <table border",
    		SEARCH_FILTERS,
    		"Scope=Body",
    		"IgnoreRedirections=No",
    		"RequestUrl=*/nav.pl*",
    		LAST);
    
    	web_url("WebTours", 
    		"URL=http://127.0.0.1:1080/WebTours/", 
    		"Resource=0", 
    		"RecContentType=text/html", 
    		"Referer=", 
    		"Snapshot=t8.inf", 
    		"Mode=HTML", 
    		LAST);
    		
    	lr_think_time(1);
    
    	//登录
    	web_submit_data("login.pl",
    		"Action=http://127.0.0.1:1080/cgi-bin/login.pl",
    		"Method=POST",
    		"RecContentType=text/html",
    		"Referer=http://127.0.0.1:1080/cgi-bin/nav.pl?in=home",
    		"Snapshot=t9.inf",
    		"Mode=HTML",
    		ITEMDATA,
    		"Name=userSession", "Value={userSession}", ENDITEM,
    		"Name=username", "Value=jojo", ENDITEM,
    		"Name=password", "Value=bean", ENDITEM,
    		"Name=JSFormSubmit", "Value=on", ENDITEM,
    		"Name=login.x", "Value=0", ENDITEM,
    		"Name=login.y", "Value=0", ENDITEM,
    		LAST);
    	
    
    	web_image("Search Flights Button", 
    		"Alt=Search Flights Button", 
    		"Snapshot=t10.inf", 
    		LAST);
    	
    	lr_start_transaction("Flight");
    	
    	lr_think_time(1);
    	
    	//步骤1:选择航班出发地和目的地及座位属性
    	web_submit_form("reservations.pl", 
    		"Snapshot=t11.inf", 
    		ITEMDATA, 
    		"Name=depart", "Value=Denver", ENDITEM, 
    		"Name=departDate", "Value=04/24/2021", ENDITEM, 
    		"Name=arrive", "Value=London", ENDITEM, 
    		"Name=returnDate", "Value=04/25/2021", ENDITEM, 
    		"Name=numPassengers", "Value=1", ENDITEM, 
    		"Name=roundtrip", "Value=<OFF>", ENDITEM, 
    		"Name=seatPref", "Value=None", ENDITEM, 
    		"Name=seatType", "Value=Coach", ENDITEM, 
    		"Name=findFlights.x", "Value=52", ENDITEM, 
    		"Name=findFlights.y", "Value=6", ENDITEM, 
    		LAST);
    	
    	lr_think_time(2);
    	
    	//步骤2:选择乘坐航班
    	web_submit_form("reservations.pl_2", 
    		"Snapshot=t12.inf", 
    		ITEMDATA, 
    		"Name=outboundFlight", "Value=020;338;04/24/2021", ENDITEM, 
    		"Name=reserveFlights.x", "Value=36", ENDITEM, 
    		"Name=reserveFlights.y", "Value=5", ENDITEM, 
    		LAST);
    	think_time=lr_get_transaction_think_time("Flight");//请确保在RunTime Settings中勾选Replay think time as recorded,否则将显示The think time cannot be determined.
    	
    	//步骤3:完成支付
    	status=web_submit_form("reservations.pl_3", 
    		"Snapshot=t13.inf", 
    		ITEMDATA, 
    		"Name=firstName", "Value=Jojo", ENDITEM, 
    		"Name=lastName", "Value=Bean", ENDITEM, 
    		"Name=address1", "Value=", ENDITEM, 
    		"Name=address2", "Value=", ENDITEM, 
    		"Name=pass1", "Value=Jojo Bean", ENDITEM, 
    		"Name=creditCard", "Value=", ENDITEM, 
    		"Name=expDate", "Value=", ENDITEM, 
    		"Name=saveCC", "Value=<OFF>", ENDITEM, 
    		"Name=buyFlights.x", "Value=47", ENDITEM, 
    		"Name=buyFlights.y", "Value=9", ENDITEM, 
    		LAST);
    	
    	 /* End transaction with operation result - pass or fail */
    	if (status == 0)
    	    lr_end_transaction("Flight", LR_PASS);
    	else
    	    lr_end_transaction("Flight", LR_FAIL);
    	if (think_time)
    	    lr_output_message("The transaction think time is %f seconds", think_time);
    	else
    	    lr_output_message("The think time cannot be determined.");
    
    
    	web_image("SignOff Button", 
    		"Alt=SignOff Button", 
    		"Ordinal=1", 
    		"Snapshot=t14.inf", 
    		LAST);
    
    	return 0;
    }
    

     可以看到,函数获取的思考时间3.000505秒与事务统计的思考时间3.0005秒基本一致。

    9、lr_get_transaction_wasted_time

    lr_get_transaction_wasted_time_Func()
    {
    	double wasteTime,trans_time;
    	int status;
    /*Correlation comment - Do not change!  Original value='131159.414823815zHtzfVcpttAtHQpAHtt' Name ='userSession' Type ='ResponseBased'*/
    	web_reg_save_param_ex(
    		"ParamName=userSession",
    		"LB=name="userSession" value="",
    		"RB="/>
    <table border",
    		SEARCH_FILTERS,
    		"Scope=Body",
    		"IgnoreRedirections=No",
    		"RequestUrl=*/nav.pl*",
    		LAST);
    
    	web_url("WebTours", 
    		"URL=http://127.0.0.1:1080/WebTours/", 
    		"Resource=0", 
    		"RecContentType=text/html", 
    		"Referer=", 
    		"Snapshot=t8.inf", 
    		"Mode=HTML", 
    		LAST);
    		
    
    	//登录
    	web_submit_data("login.pl",
    		"Action=http://127.0.0.1:1080/cgi-bin/login.pl",
    		"Method=POST",
    		"RecContentType=text/html",
    		"Referer=http://127.0.0.1:1080/cgi-bin/nav.pl?in=home",
    		"Snapshot=t9.inf",
    		"Mode=HTML",
    		ITEMDATA,
    		"Name=userSession", "Value={userSession}", ENDITEM,
    		"Name=username", "Value=jojo", ENDITEM,
    		"Name=password", "Value=bean", ENDITEM,
    		"Name=JSFormSubmit", "Value=on", ENDITEM,
    		"Name=login.x", "Value=0", ENDITEM,
    		"Name=login.y", "Value=0", ENDITEM,
    		LAST);
    	
    
    	web_image("Search Flights Button", 
    		"Alt=Search Flights Button", 
    		"Snapshot=t10.inf", 
    		LAST);
    	
    	lr_start_transaction("Flight");
    	
    	
    	//步骤1:选择航班出发地和目的地及座位属性
    	web_submit_form("reservations.pl", 
    		"Snapshot=t11.inf", 
    		ITEMDATA, 
    		"Name=depart", "Value=Denver", ENDITEM, 
    		"Name=departDate", "Value=04/24/2021", ENDITEM, 
    		"Name=arrive", "Value=London", ENDITEM, 
    		"Name=returnDate", "Value=04/25/2021", ENDITEM, 
    		"Name=numPassengers", "Value=1", ENDITEM, 
    		"Name=roundtrip", "Value=<OFF>", ENDITEM, 
    		"Name=seatPref", "Value=None", ENDITEM, 
    		"Name=seatType", "Value=Coach", ENDITEM, 
    		"Name=findFlights.x", "Value=52", ENDITEM, 
    		"Name=findFlights.y", "Value=6", ENDITEM, 
    		LAST);
    	
    	
    	//步骤2:选择乘坐航班
    	web_submit_form("reservations.pl_2", 
    		"Snapshot=t12.inf", 
    		ITEMDATA, 
    		"Name=outboundFlight", "Value=020;338;04/24/2021", ENDITEM, 
    		"Name=reserveFlights.x", "Value=36", ENDITEM, 
    		"Name=reserveFlights.y", "Value=5", ENDITEM, 
    		LAST);
    
    	//步骤3:完成支付
    	status=web_submit_form("reservations.pl_3", 
    		"Snapshot=t13.inf", 
    		ITEMDATA, 
    		"Name=firstName", "Value=Jojo", ENDITEM, 
    		"Name=lastName", "Value=Bean", ENDITEM, 
    		"Name=address1", "Value=", ENDITEM, 
    		"Name=address2", "Value=", ENDITEM, 
    		"Name=pass1", "Value=Jojo Bean", ENDITEM, 
    		"Name=creditCard", "Value=", ENDITEM, 
    		"Name=expDate", "Value=", ENDITEM, 
    		"Name=saveCC", "Value=<OFF>", ENDITEM, 
    		"Name=buyFlights.x", "Value=47", ENDITEM, 
    		"Name=buyFlights.y", "Value=9", ENDITEM, 
    		LAST);
    	
    	// Get transaction wasted time to this point获取截止到此刻的事务浪费时间
    	wasteTime=lr_get_transaction_wasted_time("Flight");
    	
    	 /* End transaction with operation result - pass or fail */
    	if (status == 0)
    	    lr_end_transaction("Flight", LR_PASS);
    	else
    	    lr_end_transaction("Flight", LR_FAIL);
    	if (wasteTime)
    	    lr_output_message("The transaction wasted time is %f seconds", wasteTime);
    	else
    	    lr_output_message("The wasted time cannot be determined.");
    
    
    	web_image("SignOff Button", 
    		"Alt=SignOff Button", 
    		"Ordinal=1", 
    		"Snapshot=t14.inf", 
    		LAST);
    
        
    	return 0;
    }
    

    可以看出,函数获取的浪费时间0.011592基本与事务统计的浪费时间0.0116基本一致,这是因为我将函数放在了事务结束前面。

    10.lr_get_transaction_status

    lr_get_transaction_status_Func()
    {
    
    	int status;
    
    /*Correlation comment - Do not change!  Original value='131159.414823815zHtzfVcpttAtHQpAHtt' Name ='userSession' Type ='ResponseBased'*/
    	web_reg_save_param_ex(
    		"ParamName=userSession",
    		"LB=name="userSession" value="",
    		"RB="/>
    <table border",
    		SEARCH_FILTERS,
    		"Scope=Body",
    		"IgnoreRedirections=No",
    		"RequestUrl=*/nav.pl*",
    		LAST);
    
    	web_url("WebTours", 
    		"URL=http://127.0.0.1:1080/WebTours/", 
    		"Resource=0", 
    		"RecContentType=text/html", 
    		"Referer=", 
    		"Snapshot=t8.inf", 
    		"Mode=HTML", 
    		LAST);
    		
    
    	//登录
    	web_submit_data("login.pl",
    		"Action=http://127.0.0.1:1080/cgi-bin/login.pl",
    		"Method=POST",
    		"RecContentType=text/html",
    		"Referer=http://127.0.0.1:1080/cgi-bin/nav.pl?in=home",
    		"Snapshot=t9.inf",
    		"Mode=HTML",
    		ITEMDATA,
    		"Name=userSession", "Value={userSession}", ENDITEM,
    		"Name=username", "Value=jojo", ENDITEM,
    		"Name=password", "Value=bean", ENDITEM,
    		"Name=JSFormSubmit", "Value=on", ENDITEM,
    		"Name=login.x", "Value=0", ENDITEM,
    		"Name=login.y", "Value=0", ENDITEM,
    		LAST);
    	
    
    	web_image("Search Flights Button", 
    		"Alt=Search Flights Button", 
    		"Snapshot=t10.inf", 
    		LAST);
    	
    	lr_start_transaction("Flight");
    	
    	
    	//步骤1:选择航班出发地和目的地及座位属性
    	web_submit_form("reservations.pl", 
    		"Snapshot=t11.inf", 
    		ITEMDATA, 
    		"Name=depart", "Value=Denver", ENDITEM, 
    		"Name=departDate", "Value=04/24/2021", ENDITEM, 
    		"Name=arrive", "Value=London", ENDITEM, 
    		"Name=returnDate", "Value=04/25/2021", ENDITEM, 
    		"Name=numPassengers", "Value=1", ENDITEM, 
    		"Name=roundtrip", "Value=<OFF>", ENDITEM, 
    		"Name=seatPref", "Value=None", ENDITEM, 
    		"Name=seatType", "Value=Coach", ENDITEM, 
    		"Name=findFlights.x", "Value=52", ENDITEM, 
    		"Name=findFlights.y", "Value=6", ENDITEM, 
    		LAST);
    	
    
    	
    	//步骤2:选择乘坐航班
    	web_submit_form("reservations.pl_2", 
    		"Snapshot=t12.inf", 
    		ITEMDATA, 
    		"Name=outboundFlight", "Value=020;338;04/24/2021", ENDITEM, 
    		"Name=reserveFlights.x", "Value=36", ENDITEM, 
    		"Name=reserveFlights.y", "Value=5", ENDITEM, 
    		LAST);
    	
    	lr_set_transaction_status(LR_FAIL);//修改事务状态
    		
    	if (lr_get_transaction_status("Flight") == LR_FAIL) {
    
         /* web_url has failed the transaction. No point in continuing, 
          * because future calls will probably fail too */
         lr_end_transaction("Flight", LR_FAIL);
         return 0;
    	}
    	
    	//步骤3:完成支付
    	status=web_submit_form("reservations.pl_3", 
    		"Snapshot=t13.inf", 
    		ITEMDATA, 
    		"Name=firstName", "Value=Jojo", ENDITEM, 
    		"Name=lastName", "Value=Bean", ENDITEM, 
    		"Name=address1", "Value=", ENDITEM, 
    		"Name=address2", "Value=", ENDITEM, 
    		"Name=pass1", "Value=Jojo Bean", ENDITEM, 
    		"Name=creditCard", "Value=", ENDITEM, 
    		"Name=expDate", "Value=", ENDITEM, 
    		"Name=saveCC", "Value=<OFF>", ENDITEM, 
    		"Name=buyFlights.x", "Value=47", ENDITEM, 
    		"Name=buyFlights.y", "Value=9", ENDITEM, 
    		LAST);
    
    
    	web_image("SignOff Button", 
    		"Alt=SignOff Button", 
    		"Ordinal=1", 
    		"Snapshot=t14.inf", 
    		LAST);
    	return 0;
    }
    

     可以看到,修改事务的状态后通过该函数成功获取修改后的事务最新状态。

    11、lr_wasted_time

    lr_wasted_time_Func() {
        int i, baseIter = 10;
        char dude[1000];
        double wasteTime, actualElapsedTime; 
        merc_timer_handle_t MasterT, timer;
    
        // Examine the total elapsed time of the action
        MasterT = lr_start_timer();
    
        //Start transaction
        lr_start_transaction("Demo");
    
        // Create some elapsed time for the transaction
        for (i=0; i< (10 * baseIter); ++i)
                sprintf(dude, "This is the way we create elapsed time artificially = %d", i);            
    
        // Add some think time
        lr_think_time(0.5);
        // Create some wasted time and record it with timer
        timer = lr_start_timer();
    
        for (i=0; i< (5 * baseIter); ++i)
                sprintf(dude, "This is the way we waste time in a script = %d", i);
    
        wasteTime = lr_end_timer(timer);
        lr_output_message("User created waste time = %lf", wasteTime);
        lr_output_message("Before lr_waste_time: Duration = %lf - Waste = %lf",        
            lr_get_transaction_duration("Demo"),
            lr_get_transaction_wasted_time("Demo"));
        /* Convert Timer in seconds to wasted time in milliseconds and add to internally generated waste time */
        wasteTime *= 1000;
        lr_wasted_time(wasteTime);
        lr_output_message("After lr_waste_time: Duration = %lf - Waste = %lf",
                lr_get_transaction_duration("Demo"),
                lr_get_transaction_wasted_time("Demo"));
    
        lr_output_message("Think time = %lf", 
            lr_get_transaction_think_time("Demo"));
    
        lr_end_transaction("Demo", LR_AUTO);
        actualElapsedTime = lr_end_timer(MasterT);
        lr_output_message("Total Elapsed time for Action = %lf", actualElapsedTime);
        return 0;
    }
    

    12、lr_fail_trans_with_error

    lr_fail_trans_with_error_Func()
    {
    	int i, baseIter = 10;
        char dude[1000];
    //Start Parent
        lr_start_transaction("Master");
        
     // Artificially create some elapsed time
        for (i=0; i<(20 * baseIter); ++i)
            sprintf(dude, 
                "This is the way we kill time in a script = %d", i);
        
        //Start a second sub transaction
        lr_start_sub_transaction("FirstT", "Master");    
    	    for (i=0; i< (20 * baseIter); ++i)
    	        sprintf(dude, 
    	            "This is the way we kill time in a script = %d", i);
    	    
    			if (i>1)//超过1秒则修改事务状态为失败,并打印错误消息
    				lr_fail_trans_with_error("An error has occurred,the time %d secs is more than 1 sec", i);
    
    	
    	lr_end_sub_transaction("FirstT",LR_AUTO);
    
        
        lr_end_transaction("Master", LR_PASS);
            
    	return 0;
    }
    

    待续.....

  • 相关阅读:
    哈希表
    c++中的虚函数
    struct并不报错
    c风格的字符串
    动态数组
    常量指针和指针常量
    关于struct和typedef struct
    常量成员函数
    关于free的使用疑惑
    mutable用于修改const成员函数中的成员变量
  • 原文地址:https://www.cnblogs.com/apple2016/p/14694149.html
Copyright © 2011-2022 走看看