Properties

static

botId  Number

The bot index starting at 0 and increasing by one for every bot launched for the duration of the test. Normally you don't need this, instead the userId can be used.

static

ip  String

The public ip of the machine (bot) running the test. This IP will be the one used by the bot to connect to your website.

Example

// Log the ip to the console
console.log(pizza.getIp());
static

loadTestId  Number

The id of the load test that is running

static

location  String

The location the test is running from. Our tests run primarily on Google Compute Engine, so this is normally the Google Compute region the script is running in.

static

pages  Array of module:Page

Any pages that were loaded during the test (including the current page or pages added with {@link module:Browser#newPage).

Example

// Log the pages loaded so far to the console
var r = pizza.result;
for (var i = 0; i < r.length; ++i) {
    console.log(r[i].url);
}
static

result

The test results that will be uploaded when the test ends.

Example

// Log the name of the test to the console
console.log(pizza.result.testName);
Returns

module:TestResult 

static

sequenceId  Number

The number of samples ran on this user id so far, starts at 0 and increments by 1 for every sample that is processed by the current user.

Unique only to the current pizza.botId + pizza.workerId.

See also
module:pizza.workerId
module:pizza.userId
static

userId  Number

The user id that the script is running under, it's unique across the load test and starts at 0. The value of the user id will never exceed the max number of users used during a load test.

static

version  String

The version of the bot running the test (this is mostly for diagnostic purposes).

static

workerId  Number

The worker id that the script is running under, it's unique per browser on the bot and starts at 0. Normally you don't need this, instead the userId can be used.

See also
module:pizza.sequenceId
module:pizza.userId

Methods

static

browser() → module:Browser

Returns the current browser if one is open

Example

// Get the currently open browser
var b = pizza.browser();
Returns

module:Browser 

The current browser if open, null otherwise

static

getRequestByFullUrl(pageIndexOrPartialUrl[, partialUrl]) → module:HttpRequest

Gets the first request matching the given partial url

Parameters

Name Type Optional Description

pageIndexOrPartialUrl

(String or Number)

 

the zero based page index (ordered by when they started loading), or the partial url to match the request against.

partialUrl

String

Yes

the partial url to match against if a page index is specified

Returns

module:HttpRequest 

static

getRequestByFullUrl(pageIndexOrFullUrl[, fullUrl]) → module:HttpRequest

Gets the first request matching the given full url

Parameters

Name Type Optional Description

pageIndexOrFullUrl

(String or Number)

 

the zero based page index (ordered by when they started loading), or the full url to match the request against.

fullUrl

String

Yes

the full url to match against if a page index is specified

Returns

module:HttpRequest 

static

nextSeqId(Named)

Generate a new sequential id unique to this load test and unique per passed in named sequence.

Sequences start at zero and are incremented by 1 every time this function is called across the load test.

Parameter

Name Type Optional Description

Named

String

 

sequence to return a value from.

See also
module:pizza.sequenceId
module:pizza.userId
static

open() → module:Browser

Open the browser.

Takes an optional URL or browser settings parameter. See the examples below.

Examples

// Open browser at "http://www.mysite.com"
var b = pizza.open("www.mysite.com");
// You may want to setup the browser before navigating
var b = pizza.open();
...
// Navigate to "http://www.mysite.com"
b.open("mysite.com");
// Open the browser and ignore bad certificates (e.g. unsigned certs)
var b = pizza.open({ignoreCertErrors: true});
b.open("https://my-unsigned-test-server.com");
// Pass a command line arg to Chrome when launching the Chrome executable.
// List of switches: https://src.chromium.org/svn/trunk/src/chrome/common/chrome_switches.cc
var b = pizza.open({args: ["--force-device-scale-factor=1"]});
b.open("google.com");
// Open the browser and enable QUIC (http://en.wikipedia.org/wiki/QUIC)
var b = pizza.open({enableQuic: true, forceQuic: "my-site-that-supports-quic.com:443"});
b.open("https://my-site-that-supports-quic.com");
// Go to a 404 page but don't throw an error
b.ignoreHttpErrors();
b.open("mysite.com/404");
See also
module:Browser#ignoreHttpErrors
Returns

module:Browser 

the newly opened browser

static

openCSV(filename) → module:CSV

Open a CSV file for read access.

This is useful to parameterise your tests.

Parameter

Name Type Optional Description

filename

String

 

the CSV filename to open.

Returns

module:CSV 

The CSV data

static

saveFile(filename, data)

Save a file to the script results.

When ran with the script runner, these files will be saved along side the script results and attached to the JUnit tests result.

Example

b.open("www.google.com");
// Get response body of the main HTML request
var d = b.getResponseBody(pizza.getRequestByUrl("www.google.com")));
pizza.saveFile(d);

Parameters

Name Type Optional Description

filename

String

 

the filename to save.

data

(String or module:Data)

 

the file contents to save.

static

sleep(milliseconds)

Sleep for the given amount of milliseconds.

It's almost always better to wait on an element being visible or some change to the DOM to happen, than having a hard wait. Often sleeps require a significant amount of tweaking and have to be changed several times in response to failures that happen after you have written the script.

Example

// Sleep for one second
pizza.sleep(1000);

Parameter

Name Type Optional Description

milliseconds

Number

 

time to wait

See also
module:pizza.waitFor
module:Browser#waitVisible
module:Browser#waitText
module:Browser#waitForHttpRequests
static

waitFor(func[, waitIterationMilliseconds])

Wait for the given function to return true

Examples

// Wait for window.myVar to be set
pizza.waitFor(function() {
   return b.execute("window.myVar ? true : false");
});
// Wait for window.myVar to be set, with 1 second between retries
pizza.waitFor(function() {
    return b.execute("window.myVar ? true : false");
}, 1000);

Parameters

Name Type Optional Description

func

function()

 

the function to check

waitIterationMilliseconds

Number

Yes

the milliseconds to wait before calling func again