Base64 encoding and decoding of XML elements

In Tosca you can encode contents of resources in Base64 and add the result as value to an XML element.

Encoded values are copied to a resource during the decoding process.

Base64 encoding and inserting

The Module Open file allows files of any file format to be loaded into a resource and then encoded.

In order for the content of a resource to be encoded in Base64 and then inserted into an XML element, the following dynamic expression must be entered into the Value column of the respective XML element.

Syntax:

{INSERT[<Resource>][Base64]}

The content of the resource specified under <Resource> is encoded in Base64 and inserted into the current XML element.

In this example, it is assumed that the resources input and attachment have already been created in the same TestCase. The file whose content is to be encoded in Base64 and inserted into an XML element has been loaded into the resource attachment.

The Module of the XML file in which the Base64 encoded content is to be inserted is used for the next TestStep. The XML file is loaded into the resource input. The content of the resource attachment is encoded in Base64 and inserted in the TestStepValue Data.

Example of inserting Base64 encoded content

Base64 decoding and saving

In order to decode Base64 encoded XML elements and to copy them into a resource, the following dynamic expression must be entered into the column Value.

Syntax:

{COPY[<Resource>][Base64][REMOVE|KEEP]}

The Base64 encoded content of the current XML element is decoded and saved in the specified resource. If REMOVE is specified, the encoded content is deleted and replaced by a note indicating the TestCase with which this was removed. This is used to reduce the size of the file. If KEEP is also specified, the encoded content is retained in the XML element. If no parameter is specified, KEEP is used by default.

The content of the resource in which the decoded content has been copied can be saved in any file format with the Module Save file Resource.

In this example, the Base64 encoded content found under Data is decoded from the resource input and copied into the resource Res.

Example of copying Base64 encoded content into a resource