Substitute request content from a file

 

+

Search Tips   |   Advanced Search

 

You can substitute the content portion of a protocol request with the contents of a file. This feature is only supported in certain sections of a test, depending on the protocol.

HTTP tests support file content substitution only in the POST data section of a request.

SOA tests support file content substitution for...

File content substitution works in the same manner as other substitutions. All of the standard test data sources can be used, including...

The data from the source is treated as a full path to a file. The file is opened, its contents are read, and then those contents are used to perform the substitution.

You must copy the files containing the substitution content to the agent computers. You must record a test with appropriate locations for substitution from a file.

For example, record an HTTP test containing multi-part MIME data in a POST request.

  1. Create a data source containing the full path to the file from which to substitute content.

    Specify an absolute path to the file. Use path separator characters appropriate to the operating system of the agent computer running the test. Optionally, specify a character set to use in reading the file. The existence of the file is not validated. If the file cannot be opened when the test runs, a message is written to the test log. If you use path separator characters that are not appropriate for the operating system of the agent computer, the substitution will fail.

    For example, if you use a path of...

      D:\DataFiles\file1

    ...on an agent computer running Linux, the substitution will fail, because Linux uses forward slashes as path separator characters.

  2. In the test editor, navigate to the request where to perform a substitution, and then select the request data to substitute.

  3. Right-click, and then select Substitute > Select Data Source.

  4. Select the data source containing the path to the file from which to substitute.

  5. Right-click the substitution site, and then select File Contents Substituter.


Results

When the test runs, the content in the protocol request is substituted with the specified file contents.

HTTP POST data is displayed in the test editor in chunks. You can create a file contents substitution in the POST data of an HTTP POST request by selecting the data chunk to correlate, and then clicking Substitute. The test data source that you select will automatically be treated as a file contents substituter. The entire data chunk is replaced with the contents of the file when the test runs, even if only a portion of the text in a text data chunk is selected by the substituter.