In cases where Linux and/or Unix boxes are part of the system setup, the use of the Secure Shell protocol (SSH) is typically necessary in test cases. SSH is used to carry out different types of task on the servers using a secure protocol.

Leaptest doesn’t ship with building blocks for SSH and the associated processes (e.g. SFTP), but it’s possible to use the Command-Line block together with Powershell to get full access to the SSH universe. In this example we will copy a file from the local computer to a remote server using SFTP.

Using the Command-Line block you can trigger a powershell file like this:

In this case the building block will execute the “ssh_example.ps1” script located in “c:\scripts”.

To add parameters to the powershell execution, simply just add the individual parameters in the Command field and add FIELDS to assign values. In the example below 2 parameters, [file] and [destination], are added. The values for the parameters are added through normal Leaptest fields – in this case “hard coded” in Set Text blocks. When the case runs the values from the Set Text blocks are transferred to the Command-line block and the tokens in the Command field are replaced by the values.

In the powershell script the 2 parameters are defined in the Param section.

In the “Parameters” section the remote server name/IP is defined as well as the destination of the local key file and the username. Once everything is set, a new SFTP session is initiated and the local file copied to the remote server using the Set-SFTPFile commandlet.

To try this in your local Leaptest installation against your own SSH server do the following:

  1. Download the test case from here: ssh-example
  2. Download the powershell script from here: ps-ssh-download. Place it in a folder that is accessible from Leaptest.
  3. Import the test case by selecting “Projects” in the main menu in Leaptest Studio and select the project you want to add the test case to. Click “In-Out” at the top of the list of projects and click “Import”.
  4. Point at the downloaded in (1), select the “SSH example” test case and click Import.
  5. Close down the Import dialog.
  6. Adjust the parameters in the test case:
    1. Local file
    2. Destination
    3. Working folder (you can add a full path in the Command line field instead of using a ‘working folder’)
    4. Script name and location.
  7. Update ssh_example.ps1:
    1. Server name
    2. Key file
    3. User name

You should now be ready to run the test case. In case of errors you can read the output from the powershell script (Write-Output, Write-Host etc.) by attaching a Log Message block to the Text Result property. This will write the output to the activity log and can be inspected after the run of the test case.