Validating a downloaded file

To download a file and validate the download, use a Custom action for an event hook handler in conjunction with an HTTP action that downloads the file.

The following example shows the code to use in the Custom action. The example code validates that the size is not equal to zero. You can also validate for the exact file size.

var getUrl = new AddEventHookCommand
(
  {
    "eventType": "replyReceived",
    "name": "directNavigate",
    "handler":"if(response.getRequest().getUrl().indexOf('http://www.w3schools.com/xml/note.xml') != -1)
    {
      if (response.content.length != 0){ alert(response.content);
      script.steps[i].actions[j].type = 'do not execute';}
    }"
  }
);
getUrl.execute();

The attached example script DownloadFileExample.gsl fetches an XML file and validates the content length. The script contains four actions:

  1. The Custom action for the event hook.
  2. The HTTP action for the GET request that downloads the file.
  3. A Wait for Network action to allow enough time for the file to be completely downloaded.
  4. A Validate action that tests whether the size condition is met.