New to Telerik Test Studio? Download free 30-day trial

Use Relative Paths in File Upload/Downloads

I need to upload/download a file to a path relative to my test execution folder. I don't want to use an absolute file path.

Solution

This can only be done in a coded step. The key is to use this.ExecutionContext.DeploymentDirectory. This property identifies the folder the test is running in. You want to use it in a coded step to create an absolute path for file upload/download like this:

public void RelativePathDownloadStep()
{
    Directory.CreateDirectory(System.IO.Path.Combine(this.ExecutionContext.DeploymentDirectory, "download"));
    string fullPath = System.IO.Path.Combine(this.ExecutionContext.DeploymentDirectory, "download\\myfile.txt");
    Pages.ThinkbroadbandDownload.IconDownload5MBPngImage.Download(false, DownloadOption.Save, fullPath, 30000);
}
Public Sub RelativePathDownloadStep()
    Directory.CreateDirectory(System.IO.Path.Combine(Me.ExecutionContext.DeploymentDirectory, "download"))
    Dim fullPath As String = System.IO.Path.Combine(Me.ExecutionContext.DeploymentDirectory, "download\myfile.txt")
    Pages.ThinkbroadbandDownload.IconDownload5MBPngImage.Download(False, DownloadOption.Save, fullPath, 30000)
End Sub

You'll have to add an assembly reference to System.Windows.Forms.dll and to include the following line at the top of your code file to use the given sample:

using System.IO;
Imports System.IO
In this article