I have this step that I want to upload a file. I want to make the location of the file dynamic/parameterized so that when my team gets the latest solution in TFS they no longer need to change the file location.
I've use the code:
string
File = Environment.CurrentDirectory + @
"\Datasource\SampleFile.docx"
;
SetExtractedValue(
"File"
, File);
Log.WriteLine(Data[
"File"
].ToString());
And the current directory it points to is "C:\Program Files\Telerik\Test Studio 2011.2\Bin" not the location of the TestStudio Directory.
Using the VSTS CodedUI it works properly since I can add the Solution directory to the Deployment Settings of the Project.
8 Answers, 1 is accepted
For cases like this we recommend using this.ExecutionContext.DeploymentDirectory like this:
string
File = System.IO.Path.Combine(
this
.ExecutionContext.DeploymentDirectory, @
"\Datasource\SampleFile.docx"
);
DeploymentDirectory represents the directory the test is running out of. When running the test under Visual Studio it will be the execution folder that Visual Studio generates and copies the test project files to. Be sure you include the folder and file as a deployment item. When running it under Test Studio it will be the root folder of your test project. Best wishes,
Cody
the Telerik team
string File = System.IO.Path.Combine(this.ExecutionContext.DeploymentDirectory, @"\Data\DataSource.xlsx");
SetExtractedValue("File", File);
Log.WriteLine(Data["File"].ToString());
Doesn't work. The deployment directory of the test is not found. the Log Result is empty.
Thanks
When Test Studio executes a test "this.ExecutionContext.DeploymentDirectory" is set to the current location of the test on disk. For example:
C:\Users\testUser\Documents\TestProjects\MySampleTests
This will be the folder where the test that is running is located e.g. "UploadTest.tstest". You should be able to specify a path relative to that location.
Cody
the Telerik team
Thanks! It already worked. I have a last question. I'm using the extracted value as a data bind for a "Handle FileUpload Dialog" and it uses the FileUploadPath entered text not the extracted value
FYI: The Test have a local data source.
Can you share with me what the binding looks like for your FileUpload dialog handler looks like? It should resemble the attached screen shot.
All the best,Cody
the Telerik team
Yes you're right. I now see the problem and I am working on how to overcome it. I will get back to you shortly.
Best wishes,Cody
the Telerik team
So it turns out that due to a bug on our framework (technically it's a design flaw) we cannot bind the file upload path to an extracted variable. I have filed a bug on this here.
We'll have to resort to doing all the dialog handling in code. You will need to delete the Handle File Upload test step because implementing it in code will actually conflict with a non-coded dialog handler of the same type.
Here's a code sample how to do this in code. Please also node you will need to put in code the action that clicks the "browse" button (or whatever the button is called that launches the Open File dialog).
// Initialize and activate a Handle FileUpload dialog handler
// Pass in a relative file path to the file to upload
FileUploadDialog dlg =
new
FileUploadDialog(ActiveBrowser, System.IO.Path.Combine(
this
.ExecutionContext.DeploymentDirectory,
"FileToUpload.txt"
), DialogButton.OPEN);
Manager.DialogMonitor.AddDialog(dlg);
// Click the button that causes the Open File dialog to launch
Pages.TryitEditorV15.FrameView.PicFile.Click(
false
);
// Wait up to 10 seconds for the dialog to be handled, then deactivate the dialog handler
// so we can create and use a new one later in the test if we want to.
dlg.WaitUntilHandled(10000);
Manager.DialogMonitor.RemoveDialog(dlg);
Lastly you may need to add this using statement at the top of the class file:
using ArtOfTest.WebAii.Win32.Dialogs;
Cody
the Telerik team