• LR关联实例,web_tours自带


    LR关联练习

    录制LR9.10自带web tours网站

    录制过程,

     

     

    测试脚本 :

     

    登录操作放在了初始化

    主要关联sessionid

     

    vuser_init()

    {

           web_url("WebTours",

                  "URL=http://127.0.0.1:1080/WebTours/",

                  "Resource=0",

                  "RecContentType=text/html",

                  "Referer=",

                  "Snapshot=t1.inf",

                  "Mode=HTTP",

                  LAST);

     

           web_url("header.html",

                  "URL=http://127.0.0.1:1080/WebTours/header.html",

                  "Resource=0",

                  "RecContentType=text/html",

                  "Referer=http://127.0.0.1:1080/WebTours/",

                  "Snapshot=t2.inf",

                  "Mode=HTTP",

                  LAST);

     

           web_url("welcome.pl",

                  "URL=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=true",

                  "Resource=0",

                  "RecContentType=text/html",

                  "Referer=http://127.0.0.1:1080/WebTours/",

                  "Snapshot=t5.inf",

                  "Mode=HTTP",

                  LAST);

     

           web_url("hp_logo.png",

                  "URL=http://127.0.0.1:1080/WebTours/images/hp_logo.png",

                  "Resource=1",

                  "RecContentType=image/png",

                  "Referer=http://127.0.0.1:1080/WebTours/header.html",

                  "Snapshot=t3.inf",

                  LAST);

     

           web_url("webtours.png",

                  "URL=http://127.0.0.1:1080/WebTours/images/webtours.png",

                  "Resource=1",

                  "RecContentType=image/png",

                  "Referer=http://127.0.0.1:1080/WebTours/header.html",

                  "Snapshot=t4.inf",

                  LAST);

     

           web_url("home.html",

                  "URL=http://127.0.0.1:1080/WebTours/home.html",

                  "Resource=0",

                  "RecContentType=text/html",

                  "Referer=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=true",

                  "Snapshot=t6.inf",

                  "Mode=HTTP",

                  LAST);

     

           //读取登录用户相关信息,和后面的订票确认相关联

    //此过程通过切换树形目录下,读取server response获得

           web_reg_save_param("login",

                  "LB=userSession value=",

                  "RB=>",

                  "Ord=1",

                  "Search=Body",

                  "RelFrameId=1",

                  LAST);

     

           web_url("nav.pl",

                  "URL=http://127.0.0.1:1080/WebTours/nav.pl?in=home",

                  "Resource=0",

                  "RecContentType=text/html",

                  "Referer=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=true",

                  "Snapshot=t7.inf",

                  "Mode=HTTP",

                  LAST);

     

           web_url("mer_login.gif",

                  "URL=http://127.0.0.1:1080/WebTours/images/mer_login.gif",

                  "Resource=1",

                  "RecContentType=image/gif",

                  "Referer=http://127.0.0.1:1080/WebTours/nav.pl?in=home",

                  "Snapshot=t8.inf",

                  LAST);

     

           lr_think_time(4);

    // 登录动作,这里把session进行关联

           web_submit_data("login.pl",

                  "Action=http://127.0.0.1:1080/WebTours/login.pl",

                  "Method=POST",

                  "RecContentType=text/html",

                  "Referer=http://127.0.0.1:1080/WebTours/nav.pl?in=home",

                  "Snapshot=t9.inf",

                  "Mode=HTTP",

                  ITEMDATA,

                  "Name=userSession", "Value={login}", ENDITEM,

                  "Name=username", "Value=jojo", ENDITEM,

                  "Name=password", "Value=bean", ENDITEM,

                  "Name=JSFormSubmit", "Value=off", ENDITEM,

                  "Name=login.x", "Value=0", ENDITEM,

                  "Name=login.y", "Value=0", ENDITEM,

                  LAST);

     

           web_url("login.pl_2",

                  "URL=http://127.0.0.1:1080/WebTours/login.pl?intro=true",

                  "Resource=0",

                  "RecContentType=text/html",

                  "Referer=http://127.0.0.1:1080/WebTours/login.pl",

                  "Snapshot=t10.inf",

                  "Mode=HTTP",

                  LAST);

     

           web_url("nav.pl_2",

                  "URL=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=home",

                  "Resource=0",

                  "RecContentType=text/html",

                  "Referer=http://127.0.0.1:1080/WebTours/login.pl",

                  "Snapshot=t11.inf",

                  "Mode=HTTP",

                  LAST);

     

           web_url("itinerary.gif",

                  "URL=http://127.0.0.1:1080/WebTours/images/itinerary.gif",

                  "Resource=1",

                  "RecContentType=image/gif",

                  "Referer=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=home",

                  "Snapshot=t12.inf",

                  LAST);

     

           web_url("signoff.gif",

                  "URL=http://127.0.0.1:1080/WebTours/images/signoff.gif",

                  "Resource=1",

                  "RecContentType=image/gif",

                  "Referer=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=home",

                  "Snapshot=t13.inf",

                  LAST);

     

           web_url("in_home.gif",

                  "URL=http://127.0.0.1:1080/WebTours/images/in_home.gif",

                  "Resource=1",

                  "RecContentType=image/gif",

                  "Referer=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=home",

                  "Snapshot=t14.inf",

                  LAST);

     

           web_url("flights.gif",

                  "URL=http://127.0.0.1:1080/WebTours/images/flights.gif",

                  "Resource=1",

                  "RecContentType=image/gif",

                  "Referer=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=home",

                  "Snapshot=t15.inf",

                  LAST);

     

           web_url("Search Flights Button",

                  "URL=http://127.0.0.1:1080/WebTours/welcome.pl?page=search",

                  "Resource=0",

                  "RecContentType=text/html",

                  "Referer=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=home",

                  "Snapshot=t16.inf",

                  "Mode=HTTP",

                  LAST);

     

           web_url("reservations.pl",

                  "URL=http://127.0.0.1:1080/WebTours/reservations.pl?page=welcome",

                  "Resource=0",

                  "RecContentType=text/html",

                  "Referer=http://127.0.0.1:1080/WebTours/welcome.pl?page=search",

                  "Snapshot=t17.inf",

                  "Mode=HTTP",

                  LAST);

     

           web_url("nav.pl_3",

                  "URL=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=flights",

                  "Resource=0",

                  "RecContentType=text/html",

                  "Referer=http://127.0.0.1:1080/WebTours/welcome.pl?page=search",

                  "Snapshot=t18.inf",

                  "Mode=HTTP",

                  LAST);

     

           web_url("in_flights.gif",

                  "URL=http://127.0.0.1:1080/WebTours/images/in_flights.gif",

                  "Resource=1",

                  "RecContentType=image/gif",

                  "Referer=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=flights",

                  "Snapshot=t19.inf",

                  LAST);

     

           web_url("home.gif",

                  "URL=http://127.0.0.1:1080/WebTours/images/home.gif",

                  "Resource=1",

                  "RecContentType=image/gif",

                  "Referer=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=flights",

                  "Snapshot=t21.inf",

                  LAST);

     

           web_url("button_next.gif",

                  "URL=http://127.0.0.1:1080/WebTours/images/button_next.gif",

                  "Resource=1",

                  "RecContentType=image/gif",

                  "Referer=http://127.0.0.1:1080/WebTours/reservations.pl?page=welcome",

                  "Snapshot=t20.inf",

                  LAST);

     

           web_url("FormDateUpdate.class",

                  "URL=http://127.0.0.1:1080/WebTours/FormDateUpdate.class",

                  "Resource=0",

                  "RecContentType=text/html",

                  "Referer=",

                  "Mode=HTTP",

                  LAST);

     

           web_url("CalSelect.class",

                  "URL=http://127.0.0.1:1080/WebTours/CalSelect.class",

                  "Resource=0",

                  "RecContentType=text/html",

                  "Referer=",

                  "Mode=HTTP",

                  LAST);

     

           web_url("Calendar.class",

                  "URL=http://127.0.0.1:1080/WebTours/Calendar.class",

                  "Resource=0",

                  "RecContentType=text/html",

                  "Referer=",

                  "Mode=HTTP",

                  LAST);

     

           return 0;

    }

    以下是Action,主要针对城市,生成对应的机票信息关联

     

    Action()

    {

           char fromCity[50];//记录出发城市

           char toCity[50];//记录到达城市

          

           lr_start_transaction("filght");

           lr_think_time(14);

           //条件判断,如果出发城市和目的城市不一样,进行订票

           strcpy( fromCity,lr__string("{testcp1}") );

           strcpy( toCity,lr__string("{testcp2}") );

          

           while(strcmp(fromCity,toCity)==0)

                  {

                         strcpy( toCity,lr__string("{testcp2}") );

                         lr_output_message("current testcp2=%s", toCity);

                         lr_output_message("current testcp1=%s", fromCity);

                  }

    //使用转换函数,将C语言的变量,存储为LR得变量

    //C变量tocity,存放与LR临时变量TargetCity中,

     

    lr_save_string(lr__string(toCity),"TargetCity");

     

    //C变量fromCity存放于LR临时变量TrivalCity中,

     

    lr_save_string(lr__string(fromCity),"TrivalCity");

     

           //关联单程机票相关信息,确认及支付过程使用

           web_reg_save_param("FLIGHT",

                  "LB=input type = radio name=outboundFlight value=",

                  "RB=checked >",

                  LAST);

           //关联返程机票相关信息,确认及支付过程使用

           web_reg_save_param("returnFli",

                  "LB=input type = radio name=returnFlight value=",

                  "RB=checked >",

                  LAST);

     

           web_submit_data("reservations.pl_2",

                  "Action=http://127.0.0.1:1080/WebTours/reservations.pl",

                  "Method=POST",

                  "RecContentType=text/html",

                  "Referer=http://127.0.0.1:1080/WebTours/reservations.pl?page=welcome",

                  "Snapshot=t22.inf",

                  "Mode=HTTP",

                  ITEMDATA,

                  "Name=advanceDiscount", "Value=0", ENDITEM,

                  "Name=depart", "Value={TrivalCity }", ENDITEM,

                  "Name=departDate", "Value=06/09/2009", ENDITEM,

                  "Name=arrive", "Value={TargetCity}", ENDITEM,

                  "Name=returnDate", "Value=06/10/2009", ENDITEM,

                  "Name=numPassengers", "Value=1", ENDITEM,

                  "Name=roundtrip", "Value=on", ENDITEM,

                  "Name=seatPref", "Value=None", ENDITEM,

                  "Name=seatType", "Value=Coach", ENDITEM,

                  "Name=.cgifields", "Value=roundtrip", ENDITEM,

                  "Name=.cgifields", "Value=seatType", ENDITEM,

                  "Name=.cgifields", "Value=seatPref", ENDITEM,

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

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

                  LAST);

     

    //根据城市的选择,生成对应的机票信息,因票价及航班为变化的,固此处必须关联

           web_submit_data("reservations.pl_3",

                  "Action=http://127.0.0.1:1080/WebTours/reservations.pl",

                  "Method=POST",

                  "RecContentType=text/html",

                  "Referer=http://127.0.0.1:1080/WebTours/reservations.pl",

                  "Snapshot=t23.inf",

                  "Mode=HTTP",

                  ITEMDATA,

                  "Name=outboundFlight", "Value={FLIGHT}", ENDITEM,

                  "Name=returnFlight", "Value={returnFli}", ENDITEM,

                  "Name=numPassengers", "Value=1", ENDITEM,

                  "Name=advanceDiscount", "Value=0", ENDITEM,

                  "Name=seatType", "Value=Coach", ENDITEM,

                  "Name=seatPref", "Value=None", ENDITEM,

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

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

                  LAST);

     

           //此步骤为用户身份确认,来自登录客户的session中,前面如果session失效,测试结果显示通过,实际未对服务器产生压力

           //判断: 来自执行结果中的机票信息

           //脚本中,还可以发现生成的对应的关联机票信息

           web_submit_data("reservations.pl_4",

                  "Action=http://127.0.0.1:1080/WebTours/reservations.pl",

                  "Method=POST",

                  "RecContentType=text/html",

                  "Referer=http://127.0.0.1:1080/WebTours/reservations.pl",

                  "Snapshot=t24.inf",

                  "Mode=HTTP",

                  ITEMDATA,

                  "Name=firstName", "Value=Joseph", ENDITEM,

                  "Name=lastName", "Value=Marshall", ENDITEM,

                  "Name=address1", "Value=234 Willow Drive", ENDITEM,

                  "Name=address2", "Value=San Jose/CA/94085", ENDITEM,

                  "Name=pass1", "Value=Joseph Marshall", ENDITEM,

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

                  "Name=expDate", "Value=", ENDITEM,

                  "Name=oldCCOption", "Value=", ENDITEM,

                  "Name=numPassengers", "Value=1", ENDITEM,

                  "Name=seatType", "Value=Coach", ENDITEM,

                  "Name=seatPref", "Value=None", ENDITEM,

                  "Name=outboundFlight", "Value={FLIGHT}", ENDITEM,

                  "Name=advanceDiscount", "Value=0", ENDITEM,

                  "Name=returnFlight", "Value={returnFli}", ENDITEM,

                  "Name=JSFormSubmit", "Value=off", ENDITEM,

                  "Name=.cgifields", "Value=saveCC", ENDITEM,

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

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

                  LAST);

           web_url("bookanother.gif",

                  "URL=http://127.0.0.1:1080/WebTours/images/bookanother.gif",

                  "Resource=1",

                  "RecContentType=image/gif",

                  "Referer=http://127.0.0.1:1080/WebTours/reservations.pl",

                  "Snapshot=t25.inf",

                  LAST);

     

           lr_end_transaction("filght", LR_AUTO);

     

           return 0;

    }

     

    为什么要关联:

    所谓的关联(correlation)就是把脚本中某些写死的(hard-coded)数据,转变成是撷取自服务器所送的、动态的、每次都不一样的数据。

    通过关联,上下文中变化的信息,其值的获取来自服务器,而不在是生成脚本中的固定值

    即:参数变化的同时,服务器的返回值通过关联函数,被调用。

    关联的取值,通过左右边界,

    web_reg_save_param函数主要是透过动态数据的前面和后面的固定字符串,来辨识要撷取的动态数据的,所以我们还需要找出动态数据的边界字符串。

    例子:

    web_reg_save_param("outFlightVal",

                  "LB=outboundFlight value=", "RB=>",

                   "ORD=ALL",

                   "SaveLen=18",

                 LAST);

    ORD 用来确定第几次出现的值,是要关联的值 ,默认值为1,就是第一次出现的值为关联的值,而设置成ALL则表示关联全部存在于左右边界的值。

    SaveLen用来截取获得的结果,如果结果中,存在我们不需要的信息,使用SaveLen来获取,例子中,只去的18个字节的串,后面的内容就被删减掉。 

  • 相关阅读:
    ZZZZ
    linux expect, spawn用法小记
    小议common lisp程序开发流程
    解决编译apache出现的问题:configure: error: APR not found . Please read the documentation
    SMART原则_百度百科
    心态不够青春,所以身上的技术也容易衰老
    What is tradebit?
    About VirtualBoxImages.com
    ssh-copy-id -i ~/.ssh/id_rsa.pub admin@172.17.42.66
    香港mtmit真皮休闲商务双用时尚浮点手拿包1018 烟灰色-大号 均码【图片 价格 品牌 报价】-京东商城
  • 原文地址:https://www.cnblogs.com/ITwangy/p/1686916.html
Copyright © 2020-2023  润新知