//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

一个WebLoad 脚本范例的更多相关文章

  1. 分享一个SQLSERVER脚本(计算数据库中各个表的数据量和每行记录所占用空间)

    分享一个SQLSERVER脚本(计算数据库中各个表的数据量和每行记录所占用空间) 很多时候我们都需要计算数据库中各个表的数据量和每行记录所占用空间 这里共享一个脚本 CREATE TABLE #tab ...

  2. (转)分享一个SQLSERVER脚本(计算数据库中各个表的数据量和每行记录所占用空间)

    分享一个SQLSERVER脚本(计算数据库中各个表的数据量和每行记录所占用空间) 很多时候我们都需要计算数据库中各个表的数据量和每行记录所占用空间 这里共享一个脚本 CREATE TABLE #tab ...

  3. 分享一个SQLSERVER脚本

    原文:分享一个SQLSERVER脚本 分享一个SQLSERVER脚本 很多时候我们都需要计算数据库中各个表的数据量很每行记录所占用空间 这里共享一个脚本 CREATE TABLE #tablespac ...

  4. shell脚本中执行另一个shell脚本

    分类: 可以在一个shell脚本中执行另一个shell脚本(或非可执行文件,主要用于取得一些变量的值),方法是: . 文件名(包括路径) 或 变量=文件名(包括路径) . $变量   注意,圆点后面有 ...

  5. 开始你的第一个npm脚本工具

    在实际开发中,一般刚开始一个项目或者刚接手一个项目,我们会运行 npm install 下载安装所有依赖, 在实际开发中,可能也会使用各种命令行-- 来提高我们开发的效率. 与它相处了这么久,你真的了 ...

  6. Shell 脚本中调用另一个 Shell 脚本的三种方式

    主要以下有几种方式: Command Explanation fork 新开一个子 Shell 执行,子 Shell 可以从父 Shell 继承环境变量,但是子 Shell 中的环境变量不会带回给父 ...

  7. 写一个python脚本监控在linux中的进程

    在虚拟机中安装Linux中的CentOS7系统 https://baijiahao.baidu.com/s?id=1597320700700593557&wfr=spider&for= ...

  8. 【病毒分析】对一个vbs脚本病毒的分析

    [病毒分析]对一个vbs脚本病毒的分析 本文来源:i春秋社区-分享你的技术,为安全加点温度 一.前言 病毒课老师丢给我们一份加密过的vbs脚本病毒的代码去尝试分析,这里把分析过程发出来,供大家参考,如 ...

  9. 编写第一个 Shell 脚本

    什么是 Shell 脚本? 一个 shell 脚本就是一个包含一系列命令的文件.shell 读取这个文件,然后执行 文件中的所有命令,就好像这些命令已经直接被输入到了命令行中一样. 怎样编写一个 Sh ...

随机推荐

  1. 找规律 UVALive 6506 Padovan Sequence

    题目传送门 /* 找规律:看看前10项就能看出规律,打个表就行了.被lld坑了一次:( */ #include <cstdio> #include <algorithm> #i ...

  2. Android学习备忘笺02Fragment

    Android中Fragment可以将UI界面分成多个区块,一般静态或动态添加Fragment. 01.新建Fragment实例 一个Fragment实例包括两个部分:类对象和布局文件(可视化部分). ...

  3. 前端--1、HTML基础

    web服务 处于应用层的http协议负责的数据传输与解析.位于socket上层,用socket传输http数据时需要在消息开头处声明是http协议/相应http版本 状态码 状态码含义 \r\n\r\ ...

  4. 关于Android软键盘把布局顶上去的问题(一)

    最近接触到了一个登陆页面,布局最上面显示的是一个波纹的view,中间显示账号和密码的EditText,紧接着还有一个Button: 希望:点击EditText时,软键盘不能把波纹的view顶出去,也不 ...

  5. ubunut在线音乐比方软件

    今天安装了一个音乐在线播放软件,忍不住要来赞一下, 之前一直都是用网页在线的qq音乐听的,这样就有点感觉不爽了, 今天突然想起来好像在网上看到的在ubuntu下有用网易云音乐的,就上网看了一下 还真的 ...

  6. nutwk的maven中央仓库及配置

    官方maven服务器:https://jfrog.nutz.cn/artifactory/jcenter/ 如果用阿里的maven服务器,特别提醒:

  7. Android(java)学习笔记195:ContentProvider使用之添加数据到联系人(掌握)

    1.添加联系人逻辑思路 (1)首先在raw_contacts创建一个新的id (2)在data表里面添加这个id对应的数据 2.下面通过一个案例,说明一下如何添加一条数据到联系人: (1)首先我们关注 ...

  8. 【VBA研究】如何用Base64 编解码方法实现简单的加解密

    Base64编码的思想是是采用64个基本的ASCII码字符对数据进行重新编码,将数据变成字符串实现文本传输.由于编码简单,所以很容易实现,代码也是现成的.利用这个编码规则可以实现简单的加解密.编解码方 ...

  9. Linux之基础命令——文件操作

    ls(显示指定工作目录下的内容) -a 显示所有文件及目录 包括隐藏文件 -l 除文件名称外,还会将文件类型.权限.拥有者.文件大小等信息详细列出[可以ll简写] -r 将文件以相反次序显示(默认是a ...

  10. 【软件构造】(转)Java中的comparable和comparator

    为了方便阅读和复习,转载至此,原地址:温布利往事的博客 阅读目录 一.Comparable简介 二.Comparator简介 三.Comparable和Comparator区别比较 回到顶部 一.Co ...