//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 ...
随机推荐
- magento 用程序生成优惠劵码
参考自http://fragmentedthought.com/fragments/programatically-creating-sales-rule-coupon-code 上面的代码只能生成C ...
- glassfish应用服务器安装配置
1.Glassfish4.0下载地址:https://glassfish.java.net/download.html#gfoseTab 2.将下载的glassfish-4.0.zip传输到服务器/h ...
- shell 2 解析
---- shell 3 /home/oracle/utility/macro/call_autopurge_arch.sh Description: Call purge archive log f ...
- 187 Repeated DNA Sequences 重复的DNA序列
所有DNA由一系列缩写为A,C,G和 T 的核苷酸组成,例如:“ACGAATTCCG”.在研究DNA时,识别DNA中的重复序列有时非常有用.编写一个函数来查找DNA分子中所有出现超多一次的10个字母长 ...
- Tcpdump的用法
见 超级详细Tcpdump 的用法 http://www.itshouce.com.cn/linux/linux-tcpdump.html
- Html标签杂记
<html> <head> <title> </title> </head> <body> </body> < ...
- PHP(二)常用函数
数学函数 数组函数 字符串函数
- 一种结合hudson的算法自动化测试构想
作者:朱金灿 来源:http://blog.csdn.net/clever101 有时我在思考:未来软件测试的趋势是什么?其实答案和其它行业一样简单:低技术含量的测试工作都将由机器承担,人只能干机器干 ...
- iOS---数据离线缓存
离线缓存 为了用户的体验,不需要每次打开App都加载新数据,或者重新请求数据,因此需要把每次浏览的数据保存起来,当下次打开软件时,首先从沙盒中加载数据:或者当软件未联网时,也只能从沙盒中加载旧数据. ...
- SQL——时间戳
mysql 低版本,date.datetime.timestamp 无法精确到毫秒 可以舍弃时间类型字段,用 bigint 来代替,如果用字符串类型代替,还是比较担心排序的时候只是根据第一个字母进行排 ...