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.


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:

[CodedStep("Relative path download")]
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);

You'll need to include the following at the top of your code file to use the above sample:

using System.IO;