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

Data Driven testing With Coded Steps-How to Set Relative Path

2 Answers 141 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Krishna
Top achievements
Rank 1
Krishna asked on 18 Apr 2012, 11:52 AM
Hello,

I am using coded step for data driven testing instead of UI binding in one of my Test Case.

Everything seems to working fine when I give Fix path to open CSV file. It will work fine if  I want to run Test case from TestList Editor. But my requirement is to run it as TFS nightly build which is at different location. For that how to set relative Path to open CSV file.

I have also added code for reference.

Also it will be very helpful if you guide on how to close browser window in coded step. I have added:
ActiveBrowser.Close(1000);(it is added in "else" part in code).
it is passed also but browser window remains open.

Waiting for Reply!!

--Krishna Gandhi.

public void AM4_CreateGroups_CodedStep()
        {
 
            //StreamReader reader = new StreamReader("C:/Work/Krishna_TFS_Local/ABC.Test.AutomatedUITests/Banking/CreateGroups1.csv");
            StreamReader reader = new StreamReader("~/CreateGroups1.csv");
            {
                Pages.ABC.SilverlightApp.UserManagementTextblock.User.Click(ArtOfTest.WebAii.Core.MouseClickType.LeftClick);
                Pages.ABC.SilverlightApp.GroupsTextblock.User.Click(ArtOfTest.WebAii.Core.MouseClickType.LeftClick);
                System.Threading.Thread.Sleep(5000);
                Pages.ABC.SilverlightApp.XamlButtonButton.User.Click(ArtOfTest.WebAii.Core.MouseClickType.LeftClick);
                string line = reader.ReadLine();
                line = reader.ReadLine();
                while (string.IsNullOrEmpty(line) == false)
                {
                    string[] S = line.Split(',');
                    Log.WriteLine(line);
                    Pages.ABC.SilverlightApp.APXamlUserGroupNameTextboxex.SetText(true, S[0], 10, 100, false);
                    Pages.ABC.SilverlightApp.APXamlDescriptionTextboxex.SetText(true, S[1], 10, 100, false);
                    Pages.ABC.SilverlightApp.APXamlEmailAddressTextboxex.SetText(true, S[2], 10, 100, false);
                    Pages.ABC.SilverlightApp.SaveTextblock.User.Click(ArtOfTest.WebAii.Core.MouseClickType.LeftClick);
                    System.Threading.Thread.Sleep(5000);
                    line = reader.ReadLine();
                    if (line != null)
                    {
                        Pages.ABC.SilverlightApp.XamlTitleTextblock.User.Click(ArtOfTest.WebAii.Core.MouseClickType.RightClick);
                        Pages.ABC.SilverlightApp.CloseAllTextblock.User.Click(ArtOfTest.WebAii.Core.MouseClickType.LeftClick);
                        Pages.ABC.SilverlightApp.GroupsTextblock.User.Click(ArtOfTest.WebAii.Core.MouseClickType.LeftClick);
                        System.Threading.Thread.Sleep(5000);
                        Pages.ABC.SilverlightApp.XamlButtonButton.User.Click(ArtOfTest.WebAii.Core.MouseClickType.LeftClick);
                        System.Threading.Thread.Sleep(5000);
                    }
                    else
                    {
                        ActiveBrowser.Close(1000);
 
                    }

2 Answers, 1 is accepted

Sort by
0
Krishna
Top achievements
Rank 1
answered on 18 Apr 2012, 12:16 PM
Hello Again,

I forgot to give some more information in my previous post.

Here I have my CSV file in project\data folder and my .cs file is in project root folder.

Now if I give relative path like this:
StreamReader reader = new StreamReader("~/CreateGroups1.csv");
OR
StreamReader reader = new StreamReader("CreateGroups1.csv");
and try to run from "Quick Execution":
It will throw exception and try to find CSV file at location :
C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE

Regards,
Krishna Gandhi.

0
Plamen
Telerik team
answered on 23 Apr 2012, 11:43 AM
Hello Krishna,

I'm sorry you are experiencing this problem. It turns out that:
    1. If you launch Visual Studio using the Start > All Programs > Microsoft Visual Studio 2010 > Microsoft Visual Studio 2010 shortcut, then the working directory is “C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\” (or the equivalent 32 bit path).

    2. If you launch Visual Studio by double-clicking the solution file, the working directory is the directory the solution file is in.

To overcome this problem you can use the ExecutionContext class of our Testing Framework to get the current deployment directory. Here's the code:
string str = ExecutionContext.Current.DeploymentDirectory;
 
StreamReader reader = new StreamReader(str + @"\datafolder\CreateGroups1.csv");

For the second problem, are you getting some kind of exception when the ActiveBrowser.Close method fails? Try using a simple "break;" instead of closing the browser. Test Studio is supposed to close it automatically at the end of the execution. If this is not happening we need to investigate further why it isn't working as expected. A Jing Video of this happening may significantly help us to understand the problem.  

Greetings,
Plamen
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
Tags
General Discussions
Asked by
Krishna
Top achievements
Rank 1
Answers by
Krishna
Top achievements
Rank 1
Plamen
Telerik team
Share this question
or