access data/iteration in data driven test case

Class library usage, coding and language questions.
c676228
Posts: 176
Joined: Mon Apr 06, 2015 5:40 am

access data/iteration in data driven test case

Post by c676228 » Wed May 13, 2015 1:15 am

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.

c676228
Posts: 176
Joined: Mon Apr 06, 2015 5:40 am

Re: access data/iteration in data driven test case

Post by c676228 » Wed May 13, 2015 1:58 am

I got it. Please add any suggestions and comments.
Looks like I can access DataContext with Ranorex.Core.Testing.TestCase.Current.DataContex

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3922
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: access data/iteration in data driven test case

Post by odklizec » Wed May 13, 2015 6:25 am

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
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

c676228
Posts: 176
Joined: Mon Apr 06, 2015 5:40 am

Re: access data/iteration in data driven test case

Post by c676228 » Wed May 13, 2015 10:38 pm

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
Attachments
2015-05-DataSourceQuestion.png
see "integer expected" in the value column
2015-05-DataSourceQuestion.png (16.08 KiB) Viewed 1145 times

Starlord
Posts: 10
Joined: Thu May 14, 2015 4:51 pm

Re: access data/iteration in data driven test case

Post by Starlord » Mon May 18, 2015 4:03 pm

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

c676228
Posts: 176
Joined: Mon Apr 06, 2015 5:40 am

Re: access data/iteration in data driven test case

Post by c676228 » Sat May 23, 2015 12:35 am

Starlord,

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

c676228
Posts: 176
Joined: Mon Apr 06, 2015 5:40 am

Re: access data/iteration in data driven test case

Post by c676228 » Sat May 23, 2015 12:36 am

odklizec ,

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

Betty