pylot 学习笔记-使用
Console and Blocking Mode - Command Line Options:
usage: run.py [options] args
-a, --agents=NUM_AGENTS : number of agents
-d, --duration=DURATION : test duration in seconds
-r, --rampup=RAMPUP : rampup in seconds
-i, --interval=INTERVAL : interval in milliseconds
-x, --xmlfile=TEST_CASE_XML : test case xml file
-o, --output_dir=PATH : output directory
-n, --name=TESTNAME : name of test
-l, --log_msgs : log messages
-b, --blocking : blocking mode
-g, --gui : start GUI
-p, --port=PORT : xml-rpc listening port
Starting Pylot Remotely:
Pylot contains an XML-RPC server that can be launched so you can start tests with a remote client.
Configuration Options:
The file /core/config.py contains some global configuration options. You can set certain defauls and alter certain behavior here. These options here are overridden if specified on the command line.
AGENTS = 1
DURATION = 60 # secs
RAMPUP = 0 # secs
INTERVAL = 0 # millisecs
TC_XML_FILENAME = 'testcases.xml'
OUTPUT_DIR = None
TEST_NAME = None
LOG_MSGS = False
GENERATE_RESULTS = True
SHUFFLE_TESTCASES = False # randomize order of testcases per agent
WAITFOR_AGENT_FINISH = True # wait for last requests to complete before stopping
SMOOTH_TP_GRAPH = 1 # secs. smooth/dampen throughput graph based on an interval
SOCKET_TIMEOUT = 300 # secs
COOKIES_ENABLED = True
Using Pylot
Step 1: Create Test Cases
Test cases are declared in an XML file named "testcases.xml", or a different XML file specified on the command line. This is the format that the test engine understands.
A test case is defined using the following syntax. Only the URL element is required.
<case>
<url>URL</url>
<method>HTTP METHOD</method>
<body>REQUEST BODY CONTENT</body>
<add_header>ADDITIONAL HTTP HEADER</add_header>
<verify>STRING OR REGULAR EXPRESSION</verify>
<verify_negative>STRING OR REGULAR EXPRESSION</verify_negative>
<timer_group>TIMER GROUP NAME</timer_group>
</case>
Below is an example of the simplest possible test case file. It contains a single test case which will be executed continuously during the test run. The test case contains a URL for the service under test. Since no method or body defined, it will default to sending an HTTP GET to this resource. Since no verifications are defined, it will pass/fail the test case based on the HTTP status code it receives (pass if status is < 400).
<testcases>
<case>
<url>http://www.example.com/foo</url>
</case>
</testcases>
We can add positive and negative verifications. A positive verification is a string or regular expression that must be contained in the response body. A negative verification is a string or regular expression that must not be contained in the response body.
<case>
<url>http://www.goldb.org/foo</url>
<verify>Copyright.*Corey Goldberg</verify>
<verify_negative>Error</verify_negative>
<case>
Cookies:
Cookies are handled automatically. If a response is received with a "Set-cookie" header, the cookie will be set and passed back in the header of subsequent requests.
Example: Yahoo! Search Web Services (REST API)
Yahoo offers various REST Web Services to access search results. In this example, I will show how to create Pylot test cases to interact with the REST API.
Here is a simple GET request against the service:
http://search.yahooapis.com/WebSearchService/V1/webSearch?appid=YahooDemo&query=foo
A Pylot test case for this request would look like this:
<case>
<url>http://search.yahooapis.com/WebSearchService/V1/webSearch?appid=YahooDemo&query=foo</url>
</case>
Notice that the ampersand (&) in the URL was escaped with the code: "&" This is done becasue certain characters ("<" and "&") are illegal in XML documents. Since we are definig test cases within an XML doc, we must either escape these with ampersand codes, or place them within a CDATA section.
Yahoo also allows the query parameters to be passed in the POST data block. In this case we must also change the "Content-type" HTTP header to: "application/x-www-form-urlencoded". (Pylot defaults to "text/xml")
Here is a POST request against the service:
<case>
<url>http://search.yahooapis.com/WebSearchService/V1/webSearch</url>
<method>POST</method>
<body><![CDATA[appid=YahooDemo&query=webinject]]></body>
<add_header>Content-type: application/x-www-form-urlencoded</add_header>
</case>
Now that we know how to create individual cases, we can create a test case file containing several of these. In this example, our test case file contains Yahoo web search queries for: "foo", "bar", "baz"
<testcases>
<case>
<url>http://search.yahooapis.com/WebSearchService/V1/webSearch?appid=YahooDemo&query=foo</url>
</case>
<case>
<url>http://search.yahooapis.com/WebSearchService/V1/webSearch?appid=YahooDemo&query=bar</url>
</case>
<case>
<url>http://search.yahooapis.com/WebSearchService/V1/webSearch?appid=YahooDemo&query=baz</url>
</case>
</testcases>
HTTP_DEBUG = False # only useful when combined with blocking mode BLOCKING = False # stdout blocked until test finishes, then result is returned as XML GUI = False
Example: SOAP API
We can model our test cases to talk to any HTTP API. This example shows how you could send requests to a SOAP service. The SOAP envelope we need to send will be enclosed in the HTTP POST body.
<case>
<url>http://www.example.org/StockPrice</url>
<method>POST</method>
<add_header>Content-Type: application/soap+xml; charset=utf-8</add_header>
<body><!
[CDATA[
<!-- This is the SOAP Envelope -->
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
<soap:Body xmlns:m="http://www.example.org/stock">
<m:GetStockPrice>
<m:StockName>IBM</m:StockName>
</m:GetStockPrice>
</soap:Body>
</soap:Envelope>
]]>
</body>
</case>
Example: Setting Static Variables/Parameters
You can define global parameters in your test case file. This is useful if you have a value shared among several test cases that you change often. In the example below, we define an "http_server" parameter and then use that token in a test case.
<testcases>
<param name="http_server" value="http://www.example.com" />
<case>
<url>${http_server}/foo</url>
</case>
</testcases>
Example: File-based HTTP Payloads
You may want to store POST data in an external file rather than declaring it directly in your testcase XML file. This is useful if you have very large POST BODYs or want to send binary data which can not be embedded in XML. Use the syntax below to pull data from a file and POST it at runtime.
<case>
<url>http://www.example.com/foo</url>
<method>POST</method>
<body file="./myfile.dat"></body>
</case>
Step 2: Model Workload Scenario
Define a workload using the controls on the UI. Using the options below. you can create a steady-state or increasing load test.
- Agents: number of agents (virtual users) to run
- Rampup: time span over which agents are started. They will be evenly distributed throughout this time span. (see note below)
- Interval: interval at which each user sends requests. The requests from each user agent are paced at even intervals (unless the respone time is slower thean the interval defined)
- Duration: time span of the test
Step 3: Execute and Monitor
Run Modes
- Console Mode: During the test, you can view real-time stats on the UI
- Blocking Mode: STDOUT is blocked until test finishes, results are returned as XML
- GUI Mode: Manage and view running tests with the GUI interface
At the end of a test run, an HTML report is automatically generated, showing test results and graphs.
Step 4: View Results
When a test is finished, a results directory is created and a report is automatically generated to summarize the test results. It includes various statistics and graphs for response times and throughput. A sample of the results report can be seen here:
Pylot also writes results to CSV text files so you can import them into your favorite spreadsheet to crunch numbers, generate statistics, and create graphs.
Appendix:
XML-RPC clients for starting Pylot remotely:
Clients can be developed in any programming language that supports XML-RPC. Below are example clients in Python and Perl.
Remote starter script in Python:
#!/usr/bin/env python
import xmlrpclib
host = 'http://myhost'
port = '8888'
server = xmlrpclib.Server('%s:%s' % (host, port))
response = server.start()
print response
Remote starter script in Perl:
#!/usr/bin/perl -w
use strict;
use Frontier::Client;
my $host = 'http://myhost';
my $port = '8888';
my $server = Frontier::Client->new('url' => "$host:$port");
my $response = $server->call('start');
print $response;
pylot 学习笔记-使用的更多相关文章
- pylot 学习笔记
安装步骤 1.下载pylot 版本是1.26,文件名是:pylot_1.26.zip 2.下载python 版本是2.5,文件名是:python-2.5.msi 3.下载numpy 版本是1.4.1, ...
- js学习笔记:webpack基础入门(一)
之前听说过webpack,今天想正式的接触一下,先跟着webpack的官方用户指南走: 在这里有: 如何安装webpack 如何使用webpack 如何使用loader 如何使用webpack的开发者 ...
- PHP-自定义模板-学习笔记
1. 开始 这几天,看了李炎恢老师的<PHP第二季度视频>中的“章节7:创建TPL自定义模板”,做一个学习笔记,通过绘制架构图.UML类图和思维导图,来对加深理解. 2. 整体架构图 ...
- PHP-会员登录与注册例子解析-学习笔记
1.开始 最近开始学习李炎恢老师的<PHP第二季度视频>中的“章节5:使用OOP注册会员”,做一个学习笔记,通过绘制基本页面流程和UML类图,来对加深理解. 2.基本页面流程 3.通过UM ...
- 2014年暑假c#学习笔记目录
2014年暑假c#学习笔记 一.C#编程基础 1. c#编程基础之枚举 2. c#编程基础之函数可变参数 3. c#编程基础之字符串基础 4. c#编程基础之字符串函数 5.c#编程基础之ref.ou ...
- JAVA GUI编程学习笔记目录
2014年暑假JAVA GUI编程学习笔记目录 1.JAVA之GUI编程概述 2.JAVA之GUI编程布局 3.JAVA之GUI编程Frame窗口 4.JAVA之GUI编程事件监听机制 5.JAVA之 ...
- seaJs学习笔记2 – seaJs组建库的使用
原文地址:seaJs学习笔记2 – seaJs组建库的使用 我觉得学习新东西并不是会使用它就够了的,会使用仅仅代表你看懂了,理解了,二不代表你深入了,彻悟了它的精髓. 所以不断的学习将是源源不断. 最 ...
- CSS学习笔记
CSS学习笔记 2016年12月15日整理 CSS基础 Chapter1 在console输入escape("宋体") ENTER 就会出现unicode编码 显示"%u ...
- HTML学习笔记
HTML学习笔记 2016年12月15日整理 Chapter1 URL(scheme://host.domain:port/path/filename) scheme: 定义因特网服务的类型,常见的为 ...
随机推荐
- 第三章 类文件结构与javap的使用
注:本文主要参考自<深入理解java虚拟机(第二版)> 1.javap的使用与类文件结构 使用过程: java源代码: package compile; /** * class字节码 */ ...
- 渐进结构—条件生成对抗网络(PSGAN)
Full-body High-resolution Anime Generation with Progressive Structure-conditional Generative Adversa ...
- iOS开发-音乐播放
现在的各种App大行其道,其实常用也就是围绕着吃喝玩乐基本的需求,视频,音乐在智能手机出现之前更是必不可少的功能,每个手机都会有一个自带的音乐播放器,当然公众也有自己的需求所以也就造就了各种音乐播放软 ...
- Cognos中新建SQLserver数据源的步骤
1:配置-数据源连接-新建数据源-指定数据源名称 2:选择数据库类型,暂时不配置jdbc 3:指定服务器,数据库名称,登陆用户名和密码 4:测试 5:测试OK(OLE DB类型的) 6:返回上一步 , ...
- 如何在MVC的ActionLink中应用Resource文件
项目中建立Resources文件夹. 添加Resource文件,必须添加一个默认的,其他语言可以添加很多个.我这里只添加了一个中文的. 双击每个资源文件,将Access Modifier 设置成pub ...
- Mac 苹果OS X小技巧:如何更改文件的默认打开方式
OS X小技巧:如何更改文件的默认打开方式 1.command + i 打开简介 2.选择合适的软件打开方式 3.选择全部更改 如图: 转自:http://digi.tech.qq.com/a/201 ...
- Python模拟登录wap版百度贴吧+自己主动回贴
模拟登录的原理都差点儿相同.大致都是这样: 打开首页获取相关cookie: 提交登陆表单(即username与password). 确认是否登录成功. 假设想了解更具体的原理与相关知识,推荐到具体解释 ...
- 相似qq的IM聊天应用源代码
这个是IM聊天应用源代码,该应用IM支持实现XMPP,以及图片和表情,语音.消息回执等功能,基本覆盖了常见的im应用的功能了,大家能够參考一下吧. 源代码下载:http://code.662p.com ...
- C#.NET常见问题(FAQ)-VS如何整个项目中查找字符串
Ctrl+F打开查找对话框,然后输入查找字符串,电机右边的小三角,选择整个解决方案,就可以遍历所有文件查找指定字符了 更多教学视频和资料下载,欢迎关注以下信息: 我的优酷空间: http:// ...
- xhEditor在线编辑器使用实例
使用xhEditor的最大好处就是不用去处理烦人的HTML标签问题,研究了一天,记录备用 前台HTML: <%@ Page Language="C#" AutoEventWi ...