Environment Current Directory

9 posts, 0 answers
  1. Mariko
    Mariko avatar
    39 posts
    Member since:
    Jun 2011

    Posted 26 Oct 2011 Link to this post

    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.
  2. Cody
    Admin
    Cody avatar
    3354 posts

    Posted 28 Oct 2011 Link to this post

    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
  3. Mariko
    Mariko avatar
    39 posts
    Member since:
    Jun 2011

    Posted 21 Nov 2011 Link to this post

    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

  4. Cody
    Admin
    Cody avatar
    3354 posts

    Posted 21 Nov 2011 Link to this post

    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
  5. Mariko
    Mariko avatar
    39 posts
    Member since:
    Jun 2011

    Posted 29 Nov 2011 Link to this post

    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.
  6. Cody
    Admin
    Cody avatar
    3354 posts

    Posted 29 Nov 2011 Link to this post

    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
  7. Mariko
    Mariko avatar
    39 posts
    Member since:
    Jun 2011

    Posted 30 Nov 2011 Link to this post

    Hi Cody,

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

    Thanks
  8. Cody
    Admin
    Cody avatar
    3354 posts

    Posted 05 Dec 2011 Link to this post

    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
  9. Cody
    Admin
    Cody avatar
    3354 posts

    Posted 07 Dec 2011 Link to this post

    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
Back to Top