Search code examples
javafitnessewebpagetest

Java testing client for WebPagetest


I'm trying to include WebPagetest tests as a part of my continuous integration process. In other words I'd like to have broken build whenever a critical performance metric is out of range.

WebPagetest provides restful API to drive it.

Most of my tests are FitNesse-based so I'd like to express my performance requirements in FitNesse language.

Is there a Java client that is able to drive WebPagetest, verify if the results are within required ranges and produce them in some format (for example JUnit). Ideally I'd like to have a set of FitNesse fixtures that allow to invoke WebPagetest.


Solution

  • I don't know of a specific fixture for this tool, but its REST API (requesting XML or JSON as response format) seems easy enough to consume using a standard REST fixture.

    You could, for instance, use my XmlHttpTest in a script table: setting input parameters using 'set value', doing a 'get from' and then checking result elements/values using 'xPath'.

    To make the wiki tables a bit nicer you could either write a subclass of a standard fixture, or create some scenarios.

    For example (with scenarios)

    |scenario |start web pagetest                                                             |location                    |
    |set value|http://stackoverflow.com/questions/34595522/java-testing-client-for-webpagetest|for                |url     |
    |set value|<your key>                                                                     |for                |k       |
    |set value|@{location}                                                                    |for                |location|
    |set value|xml                                                                            |for                |f       |
    |get from |http://www.webpagetest.org/runtest.php                                                                      |
    |show     |response                                                                                                    |
    |check    |xPath                                                                          |//statusCode/text()|200     |
    |$xmlUrl= |xPath                                                                          |//xmlUrl/text()             |
    
    |scenario           |get web pagetest result|url                                 |
    |clear values                                                                    |
    |set value          |xml                    |for                       |f        |
    |get from           |@{url}                                                      |
    |show               |response                                                    |
    |check              |xPath                  |//statusCode/text()       |200      |
    |$firstViewAverage= |xPath                  |//average/firstView/loadTime/text() |
    |$repeatViewAverage=|xPath                  |//average/repeatView/loadTime/text()|
    
    
    |script|xml http test|
    
    |start web pagetest       |
    |location         |xmlUrl?|
    |Dulles:Chrome.DSL|$url1= |
    |Dulles:Firefox   |$url2= |
    
    |script         |
    |wait|40|seconds|
    
    |get web pagetest result                   |
    |url  |firstViewAverage?|repeatViewAverage?|
    |$url1|<4000            |<3000             |
    |$url2|<2000            |<1000             |