Pylot Learning notes-using

Source: Internet
Author: User

    • 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             :  
    • Starting Pylot remotely:

Pylot contains an XML-RPC server that can is launched so 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 is overridden if specified on the command line.

AGENTS = 1DURATION = 60  # secsRAMPUP = 0  # secsINTERVAL = 0  # millisecsTC_XML_FILENAME = ‘testcases.xml‘OUTPUT_DIR = NoneTEST_NAME = NoneLOG_MSGS = FalseGENERATE_RESULTS = TrueSHUFFLE_TESTCASES = False  # randomize order of testcases per agentWAITFOR_AGENT_FINISH = True  # wait for last requests to complete before stoppingSMOOTH_TP_GRAPH = 1  # secs.  smooth/dampen throughput graph based on an intervalSOCKET_TIMEOUT = 300  # secsCOOKIES_ENABLED = True
    • Using Pylot
Step 1:create Test Cases

Test cases is declared in an XML file named "Testcases.xml", or a different XML file specified on the command line. This is the format of 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 a example of the simplest possible test case file. It contains a single test case which would 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 would default to sending a HTTP GET to this resource. Since No verifications is defined, it would pass/fail the test case based on the HTTP status code it receives (pass if STA Tus 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 being contained in the response body. A negative verification is a string or regular expression this must not being 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 would be Set and passed back in the header of subsequent R Equests.

Example:yahoo! Search Web Services (REST API)

Yahoo offers various REST Web Services to access search results. In this example, I'll show how to create pylot test cases to interact with the REST API.

Here's 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&amp;query=foo</url></case>

Notice the ampersand (&) in the URL is escaped with the code: "&amp;" This is do becasue certain characters ("<" and "&") is illegal in XML documents. Since We are definig test cases within a XML doc, we must either escape these with ampersand codes, or place them within A CDATA section.

Yahoo also allows the query parameters to being passed in the POST data block. In this case we must also 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&amp;query=foo</url>  </case>    <case>    <url>http://search.yahooapis.com/WebSearchService/V1/webSearch?appid=YahooDemo&amp;query=bar</url>  </case>    <case>    <url>http://search.yahooapis.com/WebSearchService/V1/webSearch?appid=YahooDemo&amp;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 the any HTTP API. This example shows how do you could send requests to a SOAP service. The SOAP envelope we need to send would 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 was useful if you have a value of shared among several test cases that your change often. In the example below, we define an ' http_server ' parameter and then use the ' 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

Want to store POST data in a external file rather than declaring it directly in your testcase XML file. This was useful if you had very large POST bodys or want to send binary data which can isn't be embedded in XML. Use the syntax below-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 is started. They'll is evenly distributed throughout this time span. (See note below)
    • Interval: Interval at which each user sends requests. The requests from each user agent was paced at even intervals (unless the respone time is slower thean the interval define D
    • 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 is 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 was finished, a results directory is created and A are automatically generated to summarize the test ResU Lts. It includes various statistics and graphs for response times and throughput. A sample of the results report can is seen here:

Sample Report

Pylot also writes results to CSV text files Why can import them into your favorite spreadsheet to crunch numbers, Gener Ate statistics, and create graphs.

Appendix:

XML-RPC clients for starting Pylot remotely:

Clients can developed in any programming language that supports XML-RPC. Below is example clients in Python and Perl.


Remote starter script in Python:
#!/usr/bin/env pythonimport xmlrpclibhost = ‘http://myhost‘port = ‘8888‘server = xmlrpclib.Server(‘%s:%s‘ % (host, port))response = server.start()print response


Remote starter script in Perl:
#!/usr/bin/perl -wuse 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 Learning notes-using

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.