Let's Go!

web_url/ web_submit_data / web_submit_form / web_custom_request 几个函数区别

上一篇 / 下一篇  2011-11-10 15:10:21 / 个人分类:LoadRunner

 web_submit_data
/
web_submit_form
/
web_custom_request





三个函数的差别;
web_url

The web_url function is an action function that loads the Web page (GET request) specified by the URL argument. The web_url function does not require a context.

web_url is recorded only when VuGen is in either URL–based recording mode, or in HTML–based recording mode with the A script. containing explicit URLs only option checked (see VuGen's Recording Options).

You can use web_url to simulate the download of a file from an FTP server. The web_url function causes the server to perform. the same tasks as if a file were actually being downloaded. The download is done in binary mode, unless "FtpAscii=1" is specified.

Examples of non–HTML–generated resources are .gif and .jpg images. The List of Resource Attributes is only inserted when the recording option for these resources is set at Record within the current script. step. This is the default setting. Refer to the Creating Vuser Scripts guide.

The HTTP header can be modified to pass additional information about the request to the server. Using HTTP headers you can, for example, allow other content types in the response such as compressed files, or you can request a Web page only on certain conditions. To modify the HTTP header in the request, see web_add_header. To modify all subsequent requests, see web_add_auto_header.

This function is supported for all Web scripts, and for WAP scripts running in HTTP mode or Wireless Session Protocol (WSP) replay mode.



Example: web_url
Example 1 – Send an HTTP GET request to ABC's home page
web_url("www.abc.com",

       "URL=http://www.abc.com/",

       "TargetFrame=",

       "TargetBrowser=Mercury Technologies",

       "Resource=0",

       "RecContentType=text/html",

       "Snapshot=t1.inf",

       "Mode=HTML",

       LAST);

Example 2 – Send a HTTP request with a referrer page
web_url("Hit the Slopes and Save",

       "URL=http://www.saleserver.com/American?BV_EngineID=

       ..fm_ski_sale_fall00guest.html",

       "TargetFrame=Main",

       "Resource=0",

       "RecContentType=text/html",

       "Referer=http://www.saleserver.com/American?BV_Operation=
       Dyn_Frame&..main–guest.tmpl",

       "Snapshot=t3.inf",

       "Mode=HTML",

       LAST);

Example 3– Download a game
web_url("Games",

       "URL=ftp://joe:secret@mygames.com/games/archive/loderunner.exe",

       "FtpAscii=1",

       LAST);

Example 4– Login to Secure Site
web_url("Login",

       "URL=https://secure.computing.com/scripts/login.asp?
       user=(username)&session={ssid}",

       "RecContentType=text/html", //Expected content–type



========================================================================================================================================================================================
 web_submit_data


Performs an "unconditional" or "contextless" form. submission.



The web_submit_data function is an action function that performs an "unconditional" or "contextless" form. submission. It allows you to generate GET and POST requests as made by the HTML forms. You don't need to have a form. context to execute this request.

web_submit_data is recorded only when VuGen is in either the URL–based recording mode, or in the HTML–based recording mode with the A script. containing explicit URLs only option checked (see VuGen's Recording Options).

The method indicates how the data of the form. is sent to the server, whether as a query within the URL (GET), or as a request body (POST).

This function is generated when VuGen is set to record a Web session in HTTP (all requests from the server) recording mode. VuGen also records a web_submit_data statement whenever a form. is submitted and it is unable to generate a web_submit_form. statement.

Examples of non–HTML–generated resources are .gif and .jpg images. The List of Resource Attributes is only inserted when the recording option for these resources is set at Record within the current script. step. This is the default setting. Refer to the Creating Vuser Scripts guide.

In Java calls to lrapi.web.submit_data the list of attributes, including hidden fields, is part of the options array. The list of data and the list of resources are part of the data array.

The HTTP header can be modified to pass additional information about the request to the server. Using HTTP headers you can, for example, allow other content types in the response such as compressed files, or you can request a Web page only on certain conditions. To modify the HTTP header in the request see web_add_header, or to modify all subsequent requests see web_add_auto_header.



Example: web_submit_data
In the following example, the web_submit_data function submits a form. using the POST method:

web_submit_data("default.aspx",

       "Action=http://lazarus/flightnet/default.aspx",

       "Method=POST",

       "TargetFrame=",

       "RecContentType=text/html",

       "Referer=http://lazarus/flightnet/",

       "Snapshot=t7.inf",

       "Mode=HTML",

       ITEMDATA,

       "Name=grpType", "Value=radRoundtrip", ENDITEM,

       "Name=lstDepartingCity", "Value=DEN", ENDITEM,

       "Name=lstDestinationCity", "Value=LAX", ENDITEM,

       "Name=txtDepartureDate", "Value=8/19/2003", ENDITEM,

       "Name=txtReturnDate", "Value=8/19/2003", ENDITEM,

       "Name=txtQuantity", "Value=1", ENDITEM,

       "Name=radClass", "Value=1", ENDITEM,

       "Name=radSeat", "Value=1", ENDITEM,

       "Name=btnAvailableFlights", "Value=Next >", ENDITEM,

       LAST);

In the following example, the web_submit_data function submits two files using the POST method:

web_submit_data("Attachments",

       "Action=http://barton.cottage@.Devonshire.uk/Attachments?YY=45434",

       "Method=POST",

       "EncType=multipart/form–data",

       "TargetFrame=",

       "RecContentType=text/html",

       "Referer=http:///barton.cottage@.Devonshire.uk/Compose?YY=20435",

       "Snapshot=t5.inf",

       "Mode=HTML",

       ITEMDATA,

              "Name=userFile0",

              "Value=E:\\sense_sensibility\\Elinor.txt",

              "File=yes",

              "ContentType=text/html", // Override default "text/plain" for .txt files

       ENDITEM,

              "Name=userFile1",

              "Value=E:\\sense_sensibility\\Marianne.jpg",

              "File=yes",

       ENDITEM,

       LAST);






========================================================================================================================================================================================
web_submit_form

Submits a form.



The web_submit_form. function is an action function that submits a form. The web_submit_form. function may be executed only in the context of a previous operation.

web_submit_form. is recorded only when VuGen is in HTML–based recording mode (see VuGen's Recording Options).

Examples of non–HTML–generated resources are .gif and .jpg images. The List of Resource Attributes is only inserted when the recording option for these resources is set at "Record within the current script. step". This is the default setting. Refer to the Creating Vuser Scripts guide.

When web_submit_form. is recorded, "name" and "value" are generally recorded for items in the ITEMDATA section. If you do not wish the recorded value to appear in the script, you can encrypt it. Change the word "Value" to "EncryptedValue", and substitute the encrypted value for the recorded value. For example:





Example 1
In the following example, the name of the web_submit_form. function is "employee.exe". The function submits a request for information about the employee John Green. The function has no attributes because the form. is uniquely identified by the item data.

web_submit_form("employee.exe",

       ITEMDATA,

       "name=persons", "value=John Green – John", ENDITEM,

       "name=go_page", "value=Go to Page", ENDITEM,

       LAST);

Example 2
In the following example, a user submitted a search in a company's library, for the book "Practical UNIX Security" by Garfinkel.

web_url("dogbert", "URL=http://dogbert/", LAST);

web_link("Departments:", "Text=Departments:", LAST);

web_url("index.html", "URL=http://dogbert/groups/library/index.html", LAST);

web_link("Book Search:", "Text= Book Search:", LAST);

web_submit_form("db2net.exe",

       ITEMDATA,

       "name=library.TITLE", "value=Practical UNIX Security", ENDITEM,

       "name=library.AUTHOR_S_", "value=Garfinkel", ENDITEM,

       "name=library.SUBJECTS", "value=", ENDITEM,

       LAST);




========================================================================================================================================================================================


web_custom_request


Allows you to create a custom HTTP request with any method supported by HTTP.

The web_custom_request function is an action function that allows you to create a custom HTTP request using any method or body. By default, VuGen generates this function only for requests that could not be interpreted with other web functions.

To insert this function manually, use the Add Step dialog box. To specify an HTTP header to be sent before the custom request, add a web_add_header or web_add_auto_header function.


Attributes
URL – the URL (Uniform. Resource Locator) of the Web page to load.

Method – the form. submission method: POST or GET.

Body – the body of the request. See the Body Attribute section for a complete list of available options.

Raw Body – the body of the request is passed as a pointer to the data. See the Raw Body Attribute section.

BodyFilePath – The path to a file to be passed as the body of the request. BodyFilePath can not be used together with Body, or any Body Attribute or Raw Body Attribute: BodyBinary, BodyUnicode, RAW_BODY_START , or Binary=1.

Mode – the Recording Level: HTML or HTTP. Click here for more information.




Example: web_custom_request
In the following recorded script, the user began recording from http://lazarus/html/forms/file.html.
When the user submitted his request, VuGen inserted a web_add_header function, followed by a web_custom_request function.
web_url("file.html", "URL=http://lazarus/html/forms/file.html",

       "TargetFrame=_TOP", LAST);

web_add_header("Content–Type",

"multipart/form–data; boundary=–––––––––––––––––––––––––––292742461228954");

web_custom_request("post_query.exe", "Method=POST",

       "URL=http://lazarus/cgi–bin/post_query.exe",

       "Body=–––––––––––––––––––––––––––––292742461228954\r\nContent–Disp"

       "osition: form–data; name=\"entry\"\r\n\r\nText\r\n––––––––––"

       "–––––––––––––––––––292742461228954\r\nContent–Disposition: f"

       "–––––––––––292742461228954––\r\n",

       "TargetFrame=",

       LAST);





web_submit_data

Performs an "unconditional" or "contextless" form. submission.


The web_submit_data function is an action function that performs an "unconditional" or "contextless" form. submission.
It allows you to generate GET and POST requests as made by the HTML forms. You don't need to have a form. context to execute this request.

web_submit_data is recorded only when VuGen is in either the URL–based recording mode, or in the HTML–based recording mode with the A script. containing explicit URLs only option checked (see VuGen's Recording Options).

The method indicates how the data of the form. is sent to the server, whether as a query within the URL (GET), or as a request body (POST).

This function is generated when VuGen is set to record a Web session in HTTP (all requests from the server) recording mode. VuGen also records a web_submit_data statement whenever a form. is submitted and it is unable to generate a web_submit_form. statement.

Examples of non–HTML–generated resources are .gif and .jpg images. The List of Resource Attributes is only inserted when the recording option for these resources is set at Record within the current script. step. This is the default setting. Refer to the Creating Vuser Scripts guide.

In Java calls to lrapi.web.submit_data the list of attributes, including hidden fields, is part of the options array. The list of data and the list of resources are part of the data array.

The HTTP header can be modified to pass additional information about the request to the server. Using HTTP headers you can, for example, allow other content types in the response such as compressed files, or you can request a Web page only on certain conditions. To modify the HTTP header in the request see web_add_header, or to modify all subsequent requests see web_add_auto_header.


web_submit_form
Submits a form.
The web_submit_form. function is an action function that submits a form. The web_submit_form. function may be executed only in the context of a previous operation.
web_submit_form. is recorded only when VuGen is in HTML–based recording mode (see VuGen's Recording Options).


web_custom_request
Allows you to create a custom HTTP request with any method supported by HTTP.









============================================================================


web_get_int_property
Returns specific information about the previous HTTP request.

The web_get_int_property function returns specific information about the previous HTTP request.

The meaning of the return value depends on the HttpInfoType argument. HttpInfoType can be any of the following options. The first constant in each pair (HTTP_*) is for C, the second (object.HTTP_*) is for object oriented languages.

HTTP_INFO_RETURN_CODE or object.HTTP_INFO_RETURN_CODE

The return code in HTTP response header.

HTTP_INFO_DOWNLOAD_SIZE or object.HTTP_INFO_DOWNLOAD_SIZE

The size (in bytes) of the last download, including the header, body, and communications overhead (for example, NTLM negotiation).

HTTP_INFO_DOWNLOAD_TIME or object.HTTP_INFO_DOWNLOAD_TIME

The time in (milliseconds) of the last download.

HTTP_INFO_TOTAL_REQUEST_STAT or object.HTTP_INFO_TOTAL_REQUEST_STAT

Returns the accumulated size of all headers and bodies since the first time web_get_int_property was issued with HTTP_INFO_TOTAL_REQUEST_STAT.

HTTP_INFO_TOTAL_RESPONSE_STAT or object.HTTP_INFO_TOTAL_RESPONSE_STAT

Returns the accumulated size, including header and body, of all responses since the first time web_get_int_property was issued with HTTP_INFO_TOTAL_RESPONSE_STAT

This function is supported for all Web scripts, and for WAP scripts running in HTTP mode only. It is not supported for WAP scripts running in Wireless Session Protocol (WSP) replay mode.

Example: web_get_int_property
The following example uses the web_get_int_property function to check if the script. successfully accessed the my_home home page.

{

int HttpRetCode;

web_url("my_home",

       "URL=http://my_home",

       "TargetFrame=_TOP",

       LAST);

HttpRetCode = web_get_int_property(HTTP_INFO_RETURN_CODE);

if (HttpRetCode == 200)

       lr_log_message("The script. successfully accessed the My_home home page");

       else

       lr_log_message("The script. failed to access the My_home home page ");

}

Output:

HTTP_INFO_RETURN_CODE = 200

HTTP_INFO_DOWNLOAD_SIZE = 53685

HTTP_INFO_DOWNLOAD_TIME = 2204

The following example uses the web_get_int_property function to calculate the traffic in an action, and for a single step.

Action()

{

       int initial_byte_request_ct, before_submit_request_ct, after_submit_request_ct, submit_byte_request_ct, final_request_ct;

       int initial_byte_response_ct, before_submit_response_ct, after_submit_response_ct, submit_byte_response_ct, final_response_ct;

       initial_byte_request_ct = web_get_int_property(HTTP_INFO_TOTAL_REQUEST_STAT);

       initial_byte_response_ct = web_get_int_property(HTTP_INFO_TOTAL_RESPONSE_STAT);

       web_submit_data("com.mercurytours.servlet.ReservationServlet",

              "Action=http://newtours.mercuryinteractive.com/servlets/com.mercurytours.servlet.ReservationServlet?procSub=1&pg=1",

              "Method=POST",

              "RecContentType=text/html",

              "Referer=http://newtours.mercuryinteractive.com/servlets/com.mercurytours.servlet.ReservationServlet",

              "Snapshot=t7.inf",

              "Mode=HTML",

              ITEMDATA,

              "Name=tripType", "Value=roundtrip", ENDITEM,

              "Name=passCount", "Value=2", ENDITEM,

              "Name=fromPort", "Value=San Francisco", ENDITEM,

              "Name=fromMonth", "Value=12", ENDITEM,

              "Name=fromDay", "Value=10", ENDITEM,

              "Name=toPort", "Value=Acapulco", ENDITEM,

              "Name=toMonth", "Value=12", ENDITEM,

              "Name=toDay", "Value=14", ENDITEM,

              "Name=servClass", "Value=Business", ENDITEM,

              "Name=airline", "Value=Pangea Airlines", ENDITEM,

              "Name=findFlights.x", "Value=63", ENDITEM,

              "Name=findFlights.y", "Value=10", ENDITEM,

              LAST);

       before_submit_request_ct = web_get_int_property(HTTP_INFO_TOTAL_REQUEST_STAT);

       before_submit_response_ct = web_get_int_property(HTTP_INFO_TOTAL_RESPONSE_STAT);

       lr_message("Before Submit:Request = %d, Response = %d",

                            before_submit_request_ct,before_submit_response_ct);

       /* Before Submit:Request = 1182, Response = 14177 */

       web_submit_data("com.mercurytours.servlet.PurchaseServlet",

              "Action=http://newtours.mercuryinteractive.com/servlets/com.mercurytours.servlet.PurchaseServlet",

              "Method=POST",

              "RecContentType=text/html",

              "Referer=http://newtours.mercuryinteractive.com/servlets/com.mercurytours.servlet.ReservationServlet?procSub=1&pg=1",

              "Snapshot=t9.inf",

              "Mode=HTML",

              ITEMDATA,

              "Name=outFlight", "Value=Pangea Airlines$612$356$9:23$", ENDITEM,

              "Name=inFlight", "Value=Pangea Airlines$162$364$16:43$", ENDITEM,

              "Name=reserveFlights.x", "Value=61", ENDITEM,

              "Name=reserveFlights.y", "Value=9", ENDITEM,

              LAST);

       after_submit_request_ct = web_get_int_property(HTTP_INFO_TOTAL_REQUEST_STAT);

       submit_byte_request_ct = after_submit_request_ct - before_submit_request_ct ;

       after_submit_response_ct = web_get_int_property(HTTP_INFO_TOTAL_RESPONSE_STAT);

       submit_byte_response_ct = after_submit_response_ct - before_submit_response_ct ;

       lr_message("After Submit:Request = %d, Response = %d",

                            after_submit_request_ct,after_submit_response_ct);

       /* After Submit:Request = 2695, Response = 58681*/

       lr_message("Submit Net traffic:Request = %d, Response = %d",

                            submit_byte_request_ct,submit_byte_response_ct);

       /*Submit Net traffic:Request = 1513, Response = 44504 */

       web_url("search_5",

              "URL=http://toolbarqueries.google.com/search?client=navclient-auto&googleip=O;66.102.11.99;240&ie=UTF-8&oe=UTF-8&features=Rank:&q=info:http%3A%2F%2Fnewtours%2Emercuryinteractive%2Ecom%2Fservlets%2Fcom%2Emercurytours%2Eservlet%2EPurchaseServlet&ch=762475275111",

              "Resource=0",

              "RecContentType=text/html",

              "Referer=",

              "Snapshot=t10.inf",

              "Mode=HTML",

              LAST);

       web_submit_data("com.mercurytours.servlet.PurchaseServlet_2",

              "Action=http://newtours.mercuryinteractive.com/servlets/com.mercurytours.servlet.PurchaseServlet?procSub=1&pg=1",

              "Method=POST",

              "RecContentType=text/html",

              "Referer=http://newtours.mercuryinteractive.com/servlets/com.mercurytours.servlet.PurchaseServlet",

              "Snapshot=t22.inf",

              "Mode=HTML",

              ITEMDATA,

              "Name=passFirst0", "Value=Fitzwilliam", ENDITEM,

              "Name=passLast0", "Value=Darcy", ENDITEM,

              "Name=pass.1.meal", "Value=VGML", ENDITEM,

              "Name=passFirst1", "Value=Elizabeth", ENDITEM,

              "Name=passLast1", "Value=Darcy", ENDITEM,

              "Name=pass.1.meal", "Value=LCML", ENDITEM,

              "Name=creditCard", "Value=CB", ENDITEM,

              "Name=creditnumber", "Value=123456789", ENDITEM,

              "Name=cc_exp_dt_mn", "Value=01", ENDITEM,

              "Name=cc_exp_dt_yr", "Value=2008", ENDITEM,

              "Name=cc_frst_name", "Value=Catherine", ENDITEM,

              "Name=cc_mid_name", "Value=", ENDITEM,

              "Name=cc_last_name", "Value=DeBourgh", ENDITEM,

              "Name=ticketLess", "Value=checkbox", ENDITEM,

              "Name=billAddress1", "Value=Rosings Park", ENDITEM,

              "Name=billAddress2", "Value=", ENDITEM,

              "Name=billCity", "Value=Lambton", ENDITEM,

              "Name=billState", "Value=Derbyshire", ENDITEM,

              "Name=billZip", "Value=94089", ENDITEM,

              "Name=billCountry", "Value=214", ENDITEM,

              "Name=ticketLess", "Value=checkbox", ENDITEM,

              "Name=delAddress1", "Value=1325 Borregas Ave.", ENDITEM,

              "Name=delAddress2", "Value=", ENDITEM,

              "Name=delCity", "Value=Sunnyvale", ENDITEM,

              "Name=delState", "Value=CA", ENDITEM,

              "Name=delZip", "Value=94089", ENDITEM,

              "Name=delCountry", "Value=215", ENDITEM,

              "Name=buyFlights.x", "Value=51", ENDITEM,

              "Name=buyFlights.y", "Value=15", ENDITEM,

              LAST);

       web_url("com.mercurytours.servlet.SignonServlet_2",

              "URL=http://newtours.mercuryinteractive.com/servlets/com.mercurytours.servlet.SignonServlet",

              "Resource=0",

              "RecContentType=text/html",

              "Referer=http://newtours.mercuryinteractive.com/servlets/com.mercurytours.servlet.PurchaseServlet?procSub=1&pg=1",

              "Snapshot=t24.inf",

              "Mode=HTML",

              LAST);

       web_url("search_6",

              "URL=http://toolbarqueries.google.com/search?client=navclient-auto&googleip=O;216.239.59.99;701&ie=UTF-8&oe=UTF-8&features=Rank:&q=info:http%3A%2F%2Fnewtours%2Emercuryinteractive%2Ecom%2Fservlets%2Fcom%2Emercurytours%2Eservlet%2ESignonServlet&ch=722304523644",

              "Resource=0",

              "RecContentType=text/html",

              "Referer=",

              "Snapshot=t25.inf",

              "Mode=HTML",

              LAST);

       final_request_ct = web_get_int_property(HTTP_INFO_TOTAL_REQUEST_STAT);

       lr_message("REQUEST: Initial = %d, before submit = %d, after_submit = %d, submit size = %d, total = %d",

                            initial_byte_request_ct, before_submit_request_ct, after_submit_request_ct, submit_byte_request_ct, final_request_ct);

       /*REQUEST: Initial = 0, before submit = 1182, after_submit = 2695, submit size = 1513, total = 7911 */

       final_response_ct = web_get_int_property(HTTP_INFO_TOTAL_RESPONSE_STAT);

       lr_message("RESPONSE: Initial = %d, before submit = %d, after_submit = %d, submit size = %d, total = %d",

                            initial_byte_response_ct, before_submit_response_ct, after_submit_response_ct, submit_byte_response_ct, final_response_ct);

       /* RESPONSE: Initial = 0, before submit = 14177, after_submit = 58681, submit size = 44504, total = 86444 */

       return 0;

}





TAG:

 

评分:0

我来说两句

Open Toolbar