Repository navigation
OPP UX Jenkins Integration
To integrate a Web Page Test script with the Jenkins Performance UX Job Builder, the WPT script must be encapsulated inside a groovy script. The Performance UX Job Builder reads all the WPT groovy files in the Tests directory of the Git repository: your-repo/WPT. The directory structure is by functional area. Any file with a '.groovy' extension will be evaluated (read in) by the job builder for processing and job creation.
The groovy script contains the wpt test script along with any user data for test parameterization, and the logic necessary to build the WPT test and it's associated Jenkins job. Note that a WPT test script does have built-in logic to iterate through multiple sets of user data. We handle this by adding logic to a groovy script to create multiple WPT tests as separate Jenkins jobs.
The groovy script should contain the following sections:
- WPT Script Template: This is the actual WPT test script
- User Data (if parameterizing a single script with multiple data sets)
- Script Gen: Add the test and meta data to be processed by the Jenkins job builder
Global Variables Used In Your Script wptTests : A map of WPT test that includes the WPT script, runtime parameters, and meta data to be processed by the job builder DEFAULT_HASH : A map of all the runtime parameters used to execute a web page test (with default settings). See WPT Parameters Description
Below is our template script which can be found at:
https://future-repo-to-be-updated/WPT/blob/master/Tests/TemplateTest.groovy
Our script template users some helper methods found here:
https://future-repo-to-be-updated/WPT/blob/master/Tests/_Shared/Helpers_v1.groovy
Using our template makes building multiple jobs really easy. In the script below, we are able to generate 12 Jenkins jobs that will test our script across 2 browsers, 3 environments, and 2 regional locations.
// importing helper
File sourceFile = new File(wptRootPath + "/_Shared/Helpers_v1.groovy")
Class groovyClass = new GroovyClassLoader(getClass().getClassLoader()).parseClass(sourceFile);
helper = (GroovyObject) groovyClass.newInstance();
// ----- Set configs ---------
def app = "myapp"
def testName = "load-galileo-editor"
def testDescription = "layout-2-template" // optional
def environments = ["l1", "p2", "s1"] // list of environments you want to run against ["d1", "l1", "f1", "s1", "s1load", "p2"]
def browsers = ["firefox"] // list of browsers ["firefox", "chrome", "ie10", "ie11"]
// these should be whatever you have setup in WPT
def regions = ["us-east"] // list of regions ["us-east", "aws-us-east", "aws-us-west", "aws-eu-de"]
def connections = ["cable"] // list of connection types ["cable", "native", "dsl", "fios", "3G", "4G", "dial",...]
def users = ["user1": "123456"]
// ---- additional configs ----
def testRuns = 6 // number of test iterations
def saveToGraphite = false // saves your data to graphite as well under "ux.{env}.{appName}.{pageOrTestName}.{location}.{browser}.{connectionType}.{description-optional}"
def firstViewOnly = false // only runs the test on an uncached page.
def hipchatRoomNotification = "My Team's Room Name" // Get notified of runs and SLA results in your hipchat room (leave blank to disable this)
// ------ set SLAS ------------
def slas = """
{
"successfulFVRuns": 6,
"median": {
"firstView": {
"TTFB": 500, "SpeedIndex": 3000, "visualComplete": 3000,
"userTime.galileo.loaded": 4000, "userTime.ctct_visually_complete": 3000,
"breakdown": {
"js": { "requests": 10 },
"css": { "requests": 5 }
}
}
}
}"""
// ---- Set WPT script
def wptScript = """
logData 0
navigate https://ui{ENV}.constantcontact.com/roving/wdk/API_LoginSiteOwner.jsp?loginName={USERNAME}&loginPassword={PASSWORD}
navigate https://ui{ENV}.constantcontact.com/rnavmap/distui/em-ui/wizard/create?campaignType=11&step=templatePicker
logData 1
setActivityTimeout 10000
clickAndWait data-template-name={TEMPLATE_NAME}
logData 0
setActivityTimeout 1000
navigate https://ui{ENV}.constantcontact.com/rnavmap/evaluate.rnav?activepage=site.logout.eval
"""
// removing unsafe xml characters since this will be stored in a jenkins xml file
wptScript = helper.makeXmlSafe(wptScript);
// ------- TODO: change this to meet your scripts needs
// parameterize your script
def parameterizeScript(wptScript, user, pass, env, templateName){
return wptScript.replace("{USERNAME}", user).replace("{PASSWORD}", pass).replace("{ENV}", helper.envUrlFormat(env)).replace("{TEMPLATE_NAME}", templateName)
}
// loop through maps to create tests
environments.each() { env ->
regions.each() { region ->
browsers.each() { browser ->
connections.each() { connection ->
users.each() { user, password ->
// user helper methods to generate label and location
def label = helper.getLabel(env, app, testName, region, browser, connection, testDescription)
def browserConnection = helper.getBrowserAndConnection(browser, connection)
def location = helper.getLocation(region, browser) + ":" + browserConnection["browser"] + "." + browserConnection["connection"]
// ------- TODO: Modify here to parameterize your script -------
def script = parameterizeScript(wptScript, user, password, env, testDescription)
// -------------------------------------------------------------
// store data in map to be later executed by our jenkins job builder
tmpHash = DEFAULT_HASH.clone()
tmpHash.putAll([environment: [env], location: location, label: label, script: script, slas:slas, hipchatRoomName:hipchatRoomNotification, saveToGraphite:saveToGraphite, runs:testRuns, fvonly:(firstViewOnly)? '1' : ''])
wptTests.put(label, tmpHash)
}
}
}
}
}In order to make our scripts dynamic we need to parameterize them. You can do this with a simple function that just replaces Strings in your script. Below are two excerpts from the code above that show the only two real pieces of code you will need to modify.
// change this function to meet your needs
def parameterizeScript(wptScript, user, pass, env, templateName){
return wptScript.replace("{USERNAME}", user).replace("{PASSWORD}", pass).replace("{ENV}", helper.envUrlFormat(env)).replace("{TEMPLATE_NAME}", templateName)
}
...
...
// here the script will do everything for you except parameterize your script. You will just need to modify the variables passed into your "parameterizeScript" function.
users.each() { user, password ->
...
...
// ------- TODO: Modify here to parameterize your script -------
def script = parameterizeScript(wptScript, user, password, env, testDescription)
// -------------------------------------------------------------
...
tmpHash.putAll([environment: [env], location: location, label: label, script: script])
wptTests.put(label, tmpHash)
}WPT Parameters Description
Key Description Default Value
wpturl URL of wpt runner - DO NOT CHANGE http://wpt.roving.com/runtest.php
environment env setting: s1, l1, p2
url URL to be tested
label Label for the test
location Location to test from. Syntax: LOCATION_NAME:BROWSER.CONNECTION Bedford_W7_01_Chrome-FFX-IE11:Firefox.Cable
runs Number of test runs (1-10 on the public instance) 6
fvonly Set to 1 to skip the Repeat View test
domelement DOM Element to record for sub-measurement
private Set to 1 to keep the test hidden from the test log
connections Override the number of concurrent connections IE uses (0 to not override)
web10 Set to 1 to force the test to stop at Document Complete (onLoad)
script Scripted test to execute
block space-delimited list of urls to block (substring match)
login User name to use for authenticated tests (http authentication)
password Password to use for authenticated tests (http authentication)
authType Type of authentication to use: 0 = Basic Auth, 1 = SNS
video Set to 1 to capture video
f
Format. Set to "xml" to request an XML response instead
of a redirect ("json" is also provisionally supported)
r When using the xml interface, will echo back in the response
notify e-mail address to notify with the test results
pingback URL to ping when the test is complete (the test ID will be passed as an "id" parameter)
bwDown Download bandwidth in Kbps (used when specifying a custom connectivity profile)
bwUp Upload bandwidth in Kbps (used when specifying a custom connectivity profile)
latency First-hop Round Trip Time in ms (used when specifying a custom connectivity profile)
plr Packet loss rate - percent of packets to drop (used when specifying a custom connectivity profile)
k
API Key (if assigned) - applies only to runtest.php calls.
Contact the site owner for a key if required (pmeenan@webpagetest.org for the public instance)
tcpdump Set to 1 to enable tcpdump capture
noopt Set to 1 to disable optimization checks (for faster testing)
noimages Set to 1 to disable screen shot capturing
noheaders
Set to 1 to disable saving of the http headers
(as well as browser status messages and CPU utilization)
pngss Set to 1 to save a full-resolution version of the fully loaded screen shot as a png
iq Specify a jpeg compression level (30-100) for the screen shots and video capture
noscript Set to 1 to disable javascript (IE, Chrome, Firefox)
clearcerts Set to 1 to clear the OS certificate caches (causes IE to do OCSP
mobile
Set to 1 to have Chrome emulate a mobile browser
(screen resolution, UA string, fixed viewport). Added in 2.11
mv Set to 1 when capturing video to only store the video from the median run.
cmdline Custom command-line options (Chrome only)
htmlbody Set to 1 to save the content of the first response (base page) instead of all of the text resp
cmdline Custom command-line options (Chrome only)
htmlbody Set to 1 to save the content of the first response (base page) instead of all of the text resp