This is a migrated thread and some comments may be shown as answers.

Environment Current Directory

8 Answers 420 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Mariko
Top achievements
Rank 1
Mariko asked on 26 Oct 2011, 10:24 AM
Hi,

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

Sort by
0
Cody
Telerik team
answered on 28 Oct 2011, 10:45 PM
Hi Mariko,

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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Mariko
Top achievements
Rank 1
answered on 21 Nov 2011, 07:55 AM
Hi Cody.
 
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

0
Cody
Telerik team
answered on 21 Nov 2011, 08:12 PM
Hi Mariko,

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.

All the best,
Cody
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Mariko
Top achievements
Rank 1
answered on 29 Nov 2011, 08:47 AM
Hi Cody,

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.
0
Cody
Telerik team
answered on 30 Nov 2011, 04:43 AM
Hi Mariko,

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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Mariko
Top achievements
Rank 1
answered on 01 Dec 2011, 02:39 AM
Hi Cody,

Here is the binding from my test. I also included where the source came from.

Thanks
0
Cody
Telerik team
answered on 06 Dec 2011, 01:04 AM
Hi Mariko,

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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Cody
Telerik team
answered on 07 Dec 2011, 05:15 PM
Hello Mariko,

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;

All the best,
Cody
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
General Discussions
Asked by
Mariko
Top achievements
Rank 1
Answers by
Cody
Telerik team
Mariko
Top achievements
Rank 1
Share this question
or