Page 1 of 1

access data/iteration in data driven test case

Posted: Wed May 13, 2015 1:15 am
by c676228
Hi Folks,

I have set data source/data bind with excel sheet in a test case.How can I access data source in each iteration in the user code in order to handling some of the data specifically. I just don't know how to get the data source in the test case.

Re: access data/iteration in data driven test case

Posted: Wed May 13, 2015 1:58 am
by c676228
I got it. Please add any suggestions and comments.
Looks like I can access DataContext with Ranorex.Core.Testing.TestCase.Current.DataContex

Re: access data/iteration in data driven test case

Posted: Wed May 13, 2015 6:25 am
by odklizec
Hi,

Another hint, in case you need to access DataContext from another than current TestCase, you can use this code to do so:
TestSuite.Current.GetTestCase("TestCasename").DataContext

Re: access data/iteration in data driven test case

Posted: Wed May 13, 2015 10:38 pm
by c676228
Can someone check the attached the screenshot for me?
I was trying to access a cell value through row index or column string.
why am I getting "integer expected" in run time?

myDataContext.Source.Rows[1]["GroupName"];
myDataContext.Source.Columns[0]
myDataContext.Source.Columns["GroupName"].ToString();

Thanks,
Betty

Re: access data/iteration in data driven test case

Posted: Mon May 18, 2015 4:03 pm
by Starlord
Hello Betty,
It seems you are trying to assign the value in the variable to the column index position. The reason you are getting the “Integer Expected” error is because the value in the variable is stored as a String. You will need to convert the variable to an integer before the assignment.
You could use the below method to do the conversion:
ValueConverter.FromString("GroupName", Int32);
Hope this helps.
Thanks

Re: access data/iteration in data driven test case

Posted: Sat May 23, 2015 12:35 am
by c676228
Starlord,

My code works perfectly fine in the code. The screenshot is from the watch window. I don't get what you mean.

Re: access data/iteration in data driven test case

Posted: Sat May 23, 2015 12:36 am
by c676228
odklizec ,

Thanks for your extra info. That's good info.

Betty