zoukankan      html  css  js  c++  java
  • 关联、参数化、思考时间、检查点、事务的设置方式

    Action()
    {

    //如果关联的数据过于长,需要在这里将参数存储的值变大
    web_set_max_html_param_len("1024");

    /*

    登陆关联,关联函数就是通过指定的左右边界来获取值的。 手动关联,执行会报错,错误信息如下:
    错误 -26377: 找不到所请求参数“userSessionlogin”的匹配项。请检查响应数据中是否存在请求的边界

    第一,需要检查关联函数放的位置是否有问题,如果没问题,仍报错,

    第二,取消其他关联规则,重新创建一个新关联规则,可以试下自动关联,我试下自动关联,26377这个

    报错问题就解决了

    */
    web_reg_save_param_ex(
    "ParamName=CorrelationParameter_1", //关联的名称,可自定义
    "LB=userSession value=", //左边界
    "RB=> <table border", //右边界
    SEARCH_FILTERS,
    "Scope=All",
    "IgnoreRedirections=Yes",
    "RequestUrl=*/nav.pl*",
    LAST);


    //首页加载插入事务,检查响应时间
    lr_start_transaction("the_first_page_load");
    //首页加载


    web_url("WebTours",
    "URL=http://127.0.0.1:1080/WebTours/",
    "TargetFrame=",
    "Resource=0",
    "RecContentType=text/html",
    "Referer=",
    "Snapshot=t2.inf",
    "Mode=HTML",
    LAST);

    lr_end_transaction("the_first_page_load",LR_AUTO);

    lr_think_time(3); //思考时间设置3秒,如果需要启动的话,需要在run_time settings>general>think time 去掉勾选的ignore think time设置


    //检查点设置,检查登陆成功页面是否有显示用户名,如有,则事务执行成功

    /*
    web_reg_find("Search=All",
    "SaveCount=SaveCountFail",
    "Text=Web Tours Error - Incorrect Password",
    LAST);

     */

    web_reg_find("SaveCount=SaveCountFail",
    "TextPfx=Welcome,",
    "TextSfx=, to the ",
    LAST);

    //登陆事务
    lr_start_transaction("login");

    //登陆页面,输入账号和密码

    /* Request with GET method to URL "http://127.0.0.1:1080/favicon.ico" failed during recording. Server response : 404*/

    /* Request with GET method to URL "http://bho.xl7.xunlei.com/platform/2.6.x.xxxx/config.xml" failed during recording. Server response : 404*/

    lr_think_time(12);

    web_submit_data("login.pl",
    "Action=http://127.0.0.1:1080/WebTours/login.pl",
    "Method=POST",
    "TargetFrame=body",
    "RecContentType=text/html",
    "Referer=http://127.0.0.1:1080/WebTours/nav.pl?in=home",
    "Snapshot=t3.inf",
    "Mode=HTML",
    ITEMDATA,
    "Name=userSession", "Value={CorrelationParameter_1}", ENDITEM,
    "Name=username", "Value={username}", ENDITEM,
    "Name=password", "Value={password}", ENDITEM,
    "Name=JSFormSubmit", "Value=off", ENDITEM,
    "Name=login.x", "Value=70", ENDITEM,
    "Name=login.y", "Value=20", ENDITEM,
    LAST);

    lr_output_message("关联输出的字符串:%s",lr_eval_string("{CorrelationParameter_1}"));

    /*如果参数化的密码是错误的,这里的判断有问题,密码是错误的,web_reg_find查找的是username参数化,SaveCountFail应该返回0才对,但是返回却是2,而输入正确的用户名和密码反而SaveCountFail变成0,这个问题待解决
    以上问题的解决思路是反向操作,web_reg_find查找Web Tours Error - Incorrect Password,如果找到,则登陆失败,如果找不到,则登陆成功,可以解决上面问题,如果事务返回错误的话,SaveCountFail的值输出也是不正确的。

    20160204找到解决方法:不要直接查找用户名或者报错信息,当用户名和密码不匹配,输出SaveCountFail的值总是不正确的;可以采用查找左边界和右边界的值。这样输入的SaveCountFail的值就是正确的了。

    */
    //判断事务是否执行成功
    if (atoi(lr_eval_string("{SaveCountFail}"))==0)
    {
    lr_end_transaction("login",LR_FAIL);
    lr_log_message("find the number:%s",lr_eval_string("{SaveCountFail}"));
    lr_log_message("login fail,username:%s",lr_eval_string("{username}"));
    lr_log_message("login fail,password:%s",lr_eval_string("{password}"));

    }


    else

    {

    lr_end_transaction("login",LR_PASS);
    lr_log_message("find the number:%s",lr_eval_string("{SaveCountFail}"));
    lr_output_message("success");
    //输出用户名和密码
    lr_log_message("the correct username:%s",lr_eval_string("{username}"));
    lr_log_message("the correct password:%s",lr_eval_string("{password}"));
    }


    lr_think_time(3);

    lr_start_transaction("loginout");

    lr_think_time(21);

    web_url("SignOff Button",
    "URL=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=1",
    "TargetFrame=body",
    "Resource=0",
    "RecContentType=text/html",
    "Referer=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=home",
    "Snapshot=t4.inf",
    "Mode=HTML",
    LAST);

    lr_end_transaction("loginout",LR_AUTO);

    return 0;
    }

  • 相关阅读:
    python第22天作业
    python之常见模块(一)
    python之包和文件目录规范
    python第20天作业
    python之模块
    python之匿名函数
    Python算法之二分法
    间间间间简陋版书城系统
    python第十九天作业
    4-1作业
  • 原文地址:https://www.cnblogs.com/zhangyublogs/p/5172866.html
Copyright © 2011-2022 走看看