Noregress lets you write junit tests to verify your websites performance does not degrade over time.
Noregress uses Google PageSpeed Online API. You will need to register with Google and obtain a (free) API key.
- Visit Google’s API Console. In the Services pane, activate Page Speed Online API; if the Terms of Service appear, read and accept them
- Next, go to the API Access pane. The API key is near the bottom of that pane, in the section titled “Simple API Access.”
Consult Google’s API Console Help if you need more information.
For maven users :
<dependency>
<groupId>org.noregress</groupId>
<artifactId>noregress</artifactId>
<version>0.2.0</version>
<scope>test</scope>
</dependency>
If you don’t use maven, download the jar from sonatype repository. Noregress-x.y.z.jar is self-contained and does not have any external dependencies.
See GithubPerformanceTest for a complete example. An excerpt is shown below.
@Test
public void testGithubHomePageInAnonymousMode() {
PageTester tester = new PageSpeedOnlineV1Service("<INSERT-PAGE-SPEED-API-KEY>");
Result result = tester.testPage(new Request("http://github.com/"));
/*
* Basic Assertions
*/
assertEquals("Http Response Code", 200, result.getResponseCode());
assertEquals("404's on page", 0, result.getBadRequests().size());
assertTrue("Too many domains used on the page", result.getNumberHosts() < 6);
/*
* If somebody adds a new image or a new css/js file, these tests will catch them
*/
assertTrue("Too many resources on page", result.getNumberResources() < 35);
assertTrue("Too many JS resources on page", result.getNumberJsResources() < 5);
assertTrue("Too many CSS resources on page", result.getNumberCssResources() < 2);
/*
* Github doesn't compress SVG files, when they should.
* But just to demonstrate the flexibility of Noregress,
* we will ignore svg files as part of this test
*/
List<URI> resourcesWithoutGzip = result.getResourcesWithoutCompression();
List<URI> filteredResources = ignoreURIPatterns(resourcesWithoutGzip, "^.*svg$");
assertTrue("GZip not enabled on some ", filteredResources.isEmpty());
/*
* Several other assertions are possible.
* Look at org.noregress.Result and org.noregress.pagespeed.PageSpeedResult
*/
}
- Noregress makes a call to Google Page Speed Online API with the URL of your website
- Google’s servers make a request to your website, analyse the performance and return a JSON result
- Noregress parses the result and provides a convenient API to assert there are no regressions
Noregress can be made to work against WebPageTest.org ‘s REST API. That’s a TODO. See Issue #1
- Use Noregress as part of your integration tests. Its a great idea to run these tests along with your Selenium tests
- Make lots of small “actionable assertions”, instead of one big assertion. For example, asserting the overall page score will catch all regressions, but you won’t know what change caused that regression. Instead, checking for something like “Number of JS resources on a page” will tell you exactly what broke the test and how to fix it.
- You have a limit of 250 requests a day. Assuming you do 10 commits per day, you can test 25 pages on your website. Choose wisely!
- This library wraps Google’s API, so you should read and comply with their terms and conditions
- You can only test 250 pages per day. This limit is set by Google’s Page Speed API
- The pages need to be accessible over public internet. You cannot use this library behind the firewall
- You cannot use this library for password protected pages
Noregress is licensed under the MIT License
The MIT License
Copyright © 2011 Sripathi Krishnan
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Sripathi Krishnan
Email : <FirstName><dot><LastName> at gmail.com