//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 ...
随机推荐
- iOS 集成银联支付(绕过文档的坑,快速集成)-转
本文是投稿文章,作者:南栀倾寒当初集成支付宝的时候,觉得见了这么丑的代码,加上这么难找的下载地址,在配上几乎为零的文档,寒哥就要吐血了. 下午去集成银联,才知道血吐的早了. 下载地址:https:// ...
- 利用Wamp在本地搭建一个wordpress站点
原文链接:利用Wamp在本地搭建一个wordpress站点 有时候我们会想搭建一个自己的站点,可是由于只是想自己访问,就不是很想为这个站点在买一个服务器和域名,那我们可能首先就想到把自己电脑当做服务器 ...
- APP崩溃处理
以前经常遇到APP内部异常情况下的Exception,最初是通过try catch这样的方式处理:但是APP上线后,用户在特地的情况下触发 了某些Exception,当然这些Exception从理论和 ...
- php中字符与字节的区别
字符: 字符是可使用多种不同字符方案或代码页来表示的抽象实体.例如,Unicode UTF-16 编码将字符表示为 16 位整数序列,而 Unicode UTF-8 编码则将相同的字符表示为 8 位字 ...
- iOS 对overflow:scroll使用
让子标签的高度在初始化的时候就比父标签大,可以设置height: 101%:这样就出发了内置的scrollview的滚动. -webkit-overflow-scrolling:touch;可以让滚动 ...
- uiviewcontroller顶级布局控制
@available(iOS 7.0, *) open var edgesForExtendedLayout: UIRectEdge // Defaults to UIRectEdgeAll @ava ...
- boostrapvalidator
一个例子 <%@ page contentType="text/html;charset=UTF-8" language="java" %> < ...
- laravel jwt 做API 退出登录(注销) 该怎么弄? 如何让token失效
laravel jwt 做API 退出登录(注销) 该怎么弄? 如何让token失效 php框架 laravel 2.1k 次浏览 问题对人有帮助,内容完整,我也想知道答案0问题没有实际价值,缺少关键 ...
- CAD参数绘制实心圆弧填充(com接口)
C#中实现代码说明: private void DrawPathToHatch1() { //把路径的开始位置移动指定的点 //参数一为点的X坐标 ,参数二为点的Y坐标,参数三为该点处开始宽度,对Po ...
- _bbox_pred函数
fast中的_bbox_pred函数和faster中的bbox_transform_inv是一样的,是将框进行4个坐标变换得到新的框坐标.fast中是将selective search生成的框坐标进行 ...