//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 ...
随机推荐
- Android SQLite(2)如何判断表是否已经存在
在sql语句中用 if not exists void create_table(){ SQLiteDatabase dbWireter = dbhelper.getWritableDatabase( ...
- TC609 DIV1 (500)
Problem Statement We have balls of K different colors. The colors are numbered 0 through K-1, a ...
- MVC C# 直接导出txt文件
用asp.net根据数据内容自动生成一个txt文本文件并提供用户下载,此方法文件不保存在服务器上,直接提供给用户下载,到网上搜了一下,都是用的Response.BinaryWrite(),用了几下,发 ...
- Thinkphp删除缓存
控制器代码 public function delcache(){ //当找到有Runtime的文件夹时,进入if if(is_dir(RUNTIME_PATH)){ delDir(RUNTIME ...
- 维控PLC与电流变送器modbus通讯获取电流变送器数据
2018-09-2319:28:01 今天本来要用单片机来做这个项目的,但是失败了.... 所以我又拿出了PLC来搞,也是相当之复杂,查了很多资料终于做出而来了. 今天还有事,赶紧临时备份总结一波
- 一台机器运行多个JBoss多实例
JBossXMLJVMTomcat应用服务器 我们经常会遇到这种情况,有时候希望在同一台机器上部署若干个JBoss实例,上面运行不同的应用程序,这样的话无论由于什么原因需要对某个JBoss实例进行关 ...
- Farseer.net轻量级ORM开源框架 V1.5版本升级消息
SHA-1: 0ede88104f269f108b68be1e87ffcead4a354ec6 * 提交V1.5版本1.新增:整表缓存的实现方式(提取接口,可由客户端算定义实现)2.新增:SQL配置化 ...
- webpac入门
基于node环境,必须确保node已经安装:node-v,npm-v 基础入门 前身:browserify 缺点:只能转化JS webpack作用:一切都是模块化(js.css图片等),一个模块加载器 ...
- 签名mobileconfig 重签ipa
.mobileconfig文件的签名 生成Apache专用的三个证书 双击[2331135_zgp.ink_chain.crt]可以看到它是个根证书,在mac上,双击它,导入到证书中心,然后再导出为p ...
- 关于nested exception is org.apache.ibatis.binding.BindingException:Parameter '***' not found报错解决
几天晚上遇到的奇怪的问题 传入的参数名一直没有变 但是从mapper到xml似乎有一个找不到参数的报错,实际上只要在Mapper接口形参前加“@Param(“形参名称”)”就可以了