Sie sind auf Seite 1von 3

/* In Example 1, web_reg_find searches for the text string "Welcome".

If the string is not found, it fails and the script execution stops. In Example 2, based on example 1, shows error handling in the script. In Example 3, web_reg_find searches for the text string "Error." If the string i s found, it fails and the script execution stops. In Example 4, web_reg_find searches for the text string "ABC". The path of scrip t execution depends on whether the string is found. In Example 5, an ID argument "XYZ" associates the call to web_reg_find with a li ne in the log file. */

/* In the following Example 1, web_reg_find searches for the text string "Welcome". If the string is not found, it fails and the script execution stops. */ // Run the Web Tours sample web_url("MercuryWebTours", "URL=http://localhost/MercuryWebTours/", "Resourc e=0", "RecContentType=text/html", "Referer=", "Snapshot=t1.inf", "Mode=HTML", LAST ); // Set up check for successful login by looking for "Welcome" web_reg_find("Text=Welcome", // Now log in web_submit_form("login.pl", ITEMDATA, "Name=username", "Value=jojo", ENDITEM, n", ENDITEM, "Name=password", "Value=bea "Snapshot=t2.inf", LAST );

"Name=login.x", "Value=35", ENDITEM, "Name=login.y", "Value=14", EN DITEM, LAST ); /* Example 2 is the same as example 1, but because Save Count is used, the script e xecution is not halted on failure. Instead, the error is handled in the code. */ // Run the Web Tours sample web_url("MercuryWebTours", "URL=http://localhost/MercuryWebTours/", urce=0", "RecContentType=text/html", "Referer=", "Snapshot=t1.inf", "Mode=HTML", LAST ); "Reso

// Set up check for successful login by looking for "Welcome"

web_reg_find("Text=Welcome", "SaveCount=Welcome_Count", // Now log in web_submit_form("login.pl", ITEMDATA, "Snapshot=t2.inf",

LAST );

"Name=username", "Value=jojo", ENDITEM, "Name=password", "Value=bean", ENDITEM, ITEM, "Name=login.x", "Value=35", ENDITEM, LAST ); "Name=login.y", "Value=14", END

// Check result if (atoi(lr_eval_string("{Welcome_Count}")) > 0) { lr_output_message("Log on successful."); } else { lr_error_message("Log on failed"); return(0); }

/* In the following example 3, web_reg_find searches for the text string "Error." I f the string is found, it fails and the script execution stops. web_reg_find("Text/IC=Error", "Fail=Found", LAST ); web_url("Step", "URL=...", LAST ); */ /* In the following example 4, web_reg_find searches for the text string "ABC". If the string is not found, the script executes Action A. If the string is found on e or more times, it executes Action B. */ web_reg_find("Text=ABC", "SaveCount=abc_count", LAST ); web_url("Step", "URL=...", LAST ); if (strcmp(lr_eval_string("{abc_count}"), "0") == 0) Action A else

Action B

/* In the following example 5, an ID argument "XYZ" associates the call to web_reg_ find with a line in the log file. When looking for the entry in the log file tha t logged the call to web_reg_find, searching for the string "XYZ" will make it m uch easier. */ web_reg_find("Text=mitcham", "ID=XYZ", LAST ); web_url("web_url", "URL=http://lazarus/", "TargetFrame=", "Resource=0", "Referer=", LAST ); The entries in the log file will be one of the following, depending on whether t he web_reg_find succeeded in finding the text "mitcham" was found: Action1.c(12): Matched web_reg_find with "Fail=NotFound" ("XYZ"). Text "mitcham" (count=78) Action1.c(10): Error: No match for web_reg_find with "Fail=NotFound" ("XYZ"). Te xt "mitcham"

Das könnte Ihnen auch gefallen