//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
- 分享一个SQLSERVER脚本(计算数据库中各个表的数据量和每行记录所占用空间)
分享一个SQLSERVER脚本(计算数据库中各个表的数据量和每行记录所占用空间) 很多时候我们都需要计算数据库中各个表的数据量和每行记录所占用空间 这里共享一个脚本 CREATE TABLE #tab ...
- (转)分享一个SQLSERVER脚本(计算数据库中各个表的数据量和每行记录所占用空间)
分享一个SQLSERVER脚本(计算数据库中各个表的数据量和每行记录所占用空间) 很多时候我们都需要计算数据库中各个表的数据量和每行记录所占用空间 这里共享一个脚本 CREATE TABLE #tab ...
- 分享一个SQLSERVER脚本
原文:分享一个SQLSERVER脚本 分享一个SQLSERVER脚本 很多时候我们都需要计算数据库中各个表的数据量很每行记录所占用空间 这里共享一个脚本 CREATE TABLE #tablespac ...
- shell脚本中执行另一个shell脚本
分类: 可以在一个shell脚本中执行另一个shell脚本(或非可执行文件,主要用于取得一些变量的值),方法是: . 文件名(包括路径) 或 变量=文件名(包括路径) . $变量 注意,圆点后面有 ...
- 开始你的第一个npm脚本工具
在实际开发中,一般刚开始一个项目或者刚接手一个项目,我们会运行 npm install 下载安装所有依赖, 在实际开发中,可能也会使用各种命令行-- 来提高我们开发的效率. 与它相处了这么久,你真的了 ...
- Shell 脚本中调用另一个 Shell 脚本的三种方式
主要以下有几种方式: Command Explanation fork 新开一个子 Shell 执行,子 Shell 可以从父 Shell 继承环境变量,但是子 Shell 中的环境变量不会带回给父 ...
- 写一个python脚本监控在linux中的进程
在虚拟机中安装Linux中的CentOS7系统 https://baijiahao.baidu.com/s?id=1597320700700593557&wfr=spider&for= ...
- 【病毒分析】对一个vbs脚本病毒的分析
[病毒分析]对一个vbs脚本病毒的分析 本文来源:i春秋社区-分享你的技术,为安全加点温度 一.前言 病毒课老师丢给我们一份加密过的vbs脚本病毒的代码去尝试分析,这里把分析过程发出来,供大家参考,如 ...
- 编写第一个 Shell 脚本
什么是 Shell 脚本? 一个 shell 脚本就是一个包含一系列命令的文件.shell 读取这个文件,然后执行 文件中的所有命令,就好像这些命令已经直接被输入到了命令行中一样. 怎样编写一个 Sh ...
随机推荐
- Sequence POJ - 2442
Sequence POJ - 2442 口胡一个结论:就是前i行产生的最小的n个和,一定可以在"前i-1行产生的最小n个和,每一个加上这一行的任意一个数,产生的n2个数"中找到.( ...
- VS2010环境下.NET4.0中Tuple<T>的一个小BUG问题
启动一个桌面程序后,发现一个窗体cfdata=null, 执行时发生错误, 但是在初始化的时候,我明明是cfdata=new Cfdata();为什么会出现这个错误呢. 我开始跟踪,发现当执行cfda ...
- 一命令安装nginx
#!/bin/bash yum -y install wget pcre-devel openssl openssl-devel libtool gcc automake autoconf libto ...
- [转]查询表达式 (F#)
本文转自:http://msdn.microsoft.com/zh-cn/library/hh225374.aspx 查询表达式可以查询数据源并将数据是一种预期形式. 查询表达 ...
- 11 DOM基础
1.css 标签 js 元素 dom 节点,元素节点,属性节点,文本节点 2.dom浏览器支持率 ie 10% chrome 60% FF 99% 3. ...
- 希尔排序法及其js实现
希尔(Shell)排序又称为缩小增量排序,它是一种插入排序.它是直接插入排序算法的加强版. 希尔增量: 希尔增量是指希尔提出了一种冲破二次时间屏障的算法. Donald Shell 提出了一种冲破二次 ...
- iOS----创建静态库
静态库 1.什么是库? 库是程序代码的集合,是共享程序代码的一种方式 2.根据源代码的公开情况,库可以分为2种类型 开源库 公开源代码,能看到具体实现 比如SDWebImage.AFNetworkin ...
- java 解析四则混合运算表达式并计算结果
package ch8; import java.util.LinkedList; import java.util.List; import java.util.Stack; /** * 四则混合运 ...
- CREATE CAST - 定义一个用户定义的转换
SYNOPSIS CREATE CAST (sourcetype AS targettype) WITH FUNCTION funcname (argtype) [ AS ASSIGNMENT | A ...
- CAD参数绘制直径标注(网页版)
主要用到函数说明: _DMxDrawX::DrawDimDiametric 绘制一个直径标注.详细说明如下: 参数 说明 DOUBLE dChordPointX 在被标注的曲线上的第一个点X值 DOU ...