//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 ...
随机推荐
- 简单水题 POJ 2291 Rotten Ropes
题目传送门 /* 我校oj的源题,看懂题意就很水,贴出来省的再敲:) */ #include <cstdio> #include <algorithm> #include &l ...
- NDK(10)Android.mk各属性简介,Android.mk 常用模板--未完
参考 : http://blog.csdn.net/hudashi/article/details/7059006 1. Android.mk简介 Android.mk文件是GNU Makefile的 ...
- Android网络连接判断与检测
转自: http://www.cnblogs.com/qingblog/archive/2012/07/19/2598983.html 本文主要内容: 1)判断是否有网络连接 2)判断WIFI网络是否 ...
- lavas安装
最近在研究pwa,百度基于此写了一套开源框架lavas,学习下: 1.环境准备: lavas 安装.git安装 Node.js:https://nodejs.org/ Git:https://git- ...
- js和 php 介绍
转 1. 在公司项目的改造当中,经常会遇到js与php的函数互调的情况,而实际上JS与php的设计者是不提倡这两种语言直接进行调用的,一个是客户端语言,一个服务端语言,两者之间的交互往往靠的是ajax ...
- 转】在Ubuntu中安装Redis
不多说,直接上干货! 原博文出自于: http://blog.fens.me/category/%E6%95%B0%E6%8D%AE%E5%BA%93/ 感谢! 在Ubuntu中安装Redis R利剑 ...
- Caused by: javax.el.PropertyNotFoundException: Property 'product' not found on type java.lang.String
今天在JSP利用EL表达式取值报了 "javax.el.PropertyNotFoundException”,经过debug和打印将问题定位到这段代码: HTML应该是没啥问题,看提示在ja ...
- iOS 中集成海康威视 摄像视频
本文原文地址 http://www.cnblogs.com/qianLL/p/6652104.html 一.要导入相关的库,注意 这里比较坑的是 要用和他一样的 如果开始的工程中用了AFN或者MJE ...
- sh/bash/csh/Tcsh/ksh/pdksh等shell本质区别
sh/bash/csh/Tcsh/ksh/pdksh等shell本质区别 1. Shell脚本的书写 在写Shell脚本时,往往第一行要注明用什么解释器来解释这个脚本. 如#!/bin/bash即用/ ...
- Wamp搭建的服务器登录的时候出现Access denied for user 'hello'@'localhost' (using password: YES)
想用自己电脑做一个服务器,然后就选择了Wamp,本来一切顺利,可是到登录的时候却出现了问题,出现了 Access denied for user 'hello'@'localhost' (using ...