//initial the Agenda
function InitAgenda()
{
    wlGlobals.SaveHeaders = true;
    wlGlobals.SaveSource = true;
    IncludeFile("myFunctionLib.js");  // include an external js file
    var FolderPath = getAgendaFolder(); //get the folder path which scripts locate in
    //get testing enviroment for the scripts
    //var Env = getEnv()
   //copy the test data file into scripts
    fileMap_File = CopyFile(FolderPath + "Data/" + getEnv() + "/ClientID.txt")
}
 
//initial the Virtual Client
function InitClient() 

    //read the test data file  and define the data file parameter
    fileMap_File_DataFileParam = WLDataFileParam ( "fileMap",fileMap_File, 1,"|",WLParamRandom,WLParamGlobal,WLParamUpdateRound,WLParamCycle); 
 
    //Get the data file from the data file: get the first column 
    fileMap_User_Name = WLDataFileField( fileMap_File_DataFileParam, 1); 
   //get the second column
    fileMap_UID = WLDataFileField( fileMap_DataFileParam, 2);
}
 
BeginTransaction("TransactionName")
 
// read the start time
// var startTime = Time()
 
// define the request header
wlHttp.Header["UID"] = fileMap_UID .getValue()
 
// set the cookie if needed
//wlCookie.Set("mstar", "V655O2O527L47", "http://mercury-stg.morningstar.com","/", "")
 
//set the request content type
wlHttp.DataFile.Type = "application/json; charset=UTF-8"
//read the post contents from an external file "CreateEntity.txt"
wlHttp.DataFile.Filename = "D:\\Load Test\\Mercury\\TestData\\CreateEntity.txt"
 
//compose the URL: http://mercury-stg.morningstar.com/DataService/api/v2/entity/lists
var createURL = "http://mercury-"+ getEnv()+".morningstar.com/DataService/api/v2/entity/lists/" 
 
// send the request
wlHttp.Post(createURL)
 
// receive the response header and response content
var responseHeader = document.wlHeaders
var responseSource = document.wlSource
 
// convert the text-format response source to json-format response 
var responseJSON = eval("(" + responseSource + ")");
// extract the EntityId from the resonseJSON; the EntityId will be the input in the next request - Delete API 
var EntityId = responseJSON.EntityId
 
// read the end time and calculate the total time it takes to finish the transaction
// var endTime = Time()
// var totalTime = (endTime - startTime)/1000
//InfoMessage("Total time of the " + createURL + " is " + totalTime)
 
 //verificationFuncation can be stored in the myFunctionLib.js and call it directly
function verificationFunction() 
{
    // verify if the respone contents contain text "Entity"
    var verifyContent = checkContent(responseSource, "Entity" )
    // verify if the response header status is 201 
    var verifyHeader = checkHttpStatus201(responseHeader )
 
    if (WLSuccess == verifyContent && WLSuccess == verifyHeader)
        return  WLSuccess
    else
        return  WLMinorError
}
 
EndTransaction("TransactionName",verificationFunction(), false, "Verification failed")
 
--------------------------------------------------------------------------------
Define the myFunctionl.js 
Note: myFunction.js is located in where scripts are located
 
//define the check header 200 status function
function checkHttpStatus200(responseheader)
{
     if(responseheader[0].value == "HTTP/1.1 200 OK")
         return WLSuccess
     else
         return WLMinorError
}
 
//define the check header 201 status function 
function checkHttpStatus201(responseheader)
{
     if(responseheader[0].value == "HTTP/1.1 201 Created")
         return WLSuccess
     else
         return WLMinorError
}
 
// define a function to check if the response contents contain a specific text
function checkContent(responseSource, textToBeVerified)
{
     var strSource = responseSource.toString();
     if (strSource.indexOf (textToBeVerified) != -1)
         return WLSuccess;
     else
         return WLMinorError;
}
 
// define a function to check if the response content is null
function SourceCheck(responseSource)
{
     if (responseSource != "")
         return WLSuccess
     else
         return WLMinorError
}
 
// define a function a get the test environment
function getEnv(envStr)
{
    var env = ""; 
    switch(envStr.toLowerCase()){

        case "stg": 
            env = "-stg"; 
                break;
        case "live": 
            env = ""; 
            break; 
        case "qa": 
            env = "-qa"; 
            break; 
        case "dallas":
            env = "-dallas";
            break;
    } 
    return env; 
}
 
// get the path of current folder where the project/scripts are loated 
function getAgendaFolder()
{
     var path = "D:/Load Test/Mercury/agenda/"
     var checkPath = folderExist(path)
     if(checkPath == true)
         return path
     else
         return "C:/Codes_PMS/Performance/PFSAPI/"
}
 
// check if a folder exist
function folderExist(folderPath)
{
     var fso = new ActiveXObject("Scripting.FileSystemObject");
     if(fso.FolderExists(folderPath))
          return true;
    else
          return false;
}
 
------------------------------------------------------------------------------
目录结构:
Agenda > 脚本,TestData, myFunction.js
TestData> uat, stg, qa > CreateEntity.txt

最新文章

  1. 在命令行下使用perl
  2. Xilinx FPGA全局时钟和全局时钟资源的使用方法
  3. C#程序
  4. 开发常用到的terminal命令
  5. HTML5[5]:在移动端禁用长按选中文本功能
  6. dumpsys命令的使用及telephony.registry解读
  7. vim设置
  8. 使用vs2010编译 Python \ SIP \ PyQt4
  9. nested exception is java.sql.SQLException: IO 错误
  10. Pushgateway 介绍
  11. Python—sys模块介绍
  12. ubuntu14.04 mysql数据库允许远程访问设置
  13. Docker常见命令
  14. 挖矿病毒 qW3xT.2 最终解决方案
  15. python基础(4)-元组&字典&字符串&队列
  16. 彻底理解Netty,这一篇文章就够了
  17. JavaScript数组所有API全解密
  18. centos7下解压bz2文件
  19. mysql的myBatis,主键自增设置
  20. Class 和 MetaClass

热门文章

  1. 467 Unique Substrings in Wraparound String 封装字符串中的独特子字符串
  2. [完美方案+无懈可击]ubuntu 14.04(LTS) + GTX 980Ti显卡配置
  3. Spring MVC 结合Velocity视图出现中文乱码的解决方案
  4. suricata.yaml (一款高性能的网络IDS、IPS和网络安全监控引擎)默认配置文件(图文详解)
  5. LN : leetcode 123 Best Time to Buy and Sell Stock III
  6. PHP(二)常用函数
  7. 使用迅为iTOP-iMX6开发板-uboot-修改默认环境变量
  8. leetcode_1014. Capacity To Ship Packages Within D Days
  9. Discuz 页面不能加载插件的原因和解决方法
  10. windows测试物理网络