Network request - test subject

Network request test subject represent a single network request made during the test execution.


Assertions involving the network request subject will only work with requests that go through Suitestify.

Basic Usage

To check if the app has loaded a particular URL:

In Test Editor:

Basic network request assertion
Basic network request assertion

In the Suitest JavaScript API use the networkRequest subject:

await suitest.assert.networkRequest().equal('https://suite.st/docs/').wasMade();

Matching a set of URLs

Instead of looking for an exact URL, you can look for a substring.

In Test Editor:

Network request with matching by part of a URL
Network request with matching by part of a URL

In JavaScript API:

await suitest.assert.networkRequest().contains('suite.st').wasMade();

This is especially useful if the URL you are looking for contains dynamic parameters.

Matching repetitive requests

Sometimes the app may load the same or similar URL multiple times. You can instruct Suitest to ignore the requests that have previously had a match.

In Test Editor:

Network request with matching by part of a URL - excluding previously matched requests
Network request with matching by part of a URL - excluding previously matched requests

In JavaScript API:

await suitest.assert.networkRequest().contains('suite.st').willBeMade();

Matching headers

You can add HTTP headers to the assertion. Both request and response headers are supported.

In Test Editor:

Network request matching URL - with headers
Network request matching URL - with headers

In JavaScript API:

await suitest.assert.networkRequest().equals('http://file.suite.st/sampleapp/index-hbbtv.html').requestMatch([
    {
        name: suitest.NETWORK_PROP.METHOD,
        val: suitest.NETWORK_METHOD.GET,
    }
]).responseMatch([
    {
        name: NETWORK_PROP.STATUS,
        val: 200,
    },
    {
        name: 'Content-Type',
        val: 'application/vnd.hbbtv.xhtml+xml',
    },
]).wasMade();

HTTP headers containing random or changing information are most of the time not suited for assertions.

Network log lifecycle

Suitest starts a fresh network log at every test execution initiation. The log is empty at the beginning and fills up as the application progresses through the test. All assertions involving the network request subject are made against that log.

When running the test line-by-line every next execution is considered a separate test run and the network log is cleared. Therefore if you run only the line with a network request assertion it will most definitely fail. You should run the network assertion line together with other parts of the test that will ensure that the network log is properly filled.

Creating network assertions from Suitest console

All network requests made during interactive sessions are listed in Suitest console. You can easily add an assertion based on that network request to your test by pressing Create assertion link

Network logs shown in console with create assertion link
Network logs shown in console with create assertion link