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.
LEAPWORK 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 LEAPWORK 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 LEAPWORK installation against your own SSH server do the following:
- Download the test case from here: ssh-example
- Download the powershell script from here: ps-ssh-download. Place it in a folder that is accessible from LEAPWORK.
- Import the test case by selecting "Projects" in the main menu in LEAPWORK 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".
- Point at the ssh-example.zip downloaded in (1), select the "SSH example" test case and click Import.
- Close down the Import dialog.
- Adjust the parameters in the test case:
- Local file
- Destination
- Working folder (you can add a full path in the Command line field instead of using a 'working folder')
- Script name and location.
- Update ssh_example.ps1:
- Server name
- Key file
- 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.