Get RowIndex Programatically

Ask general questions here.
praneet
Posts: 20
Joined: Thu Nov 08, 2018 2:22 am

Get RowIndex Programatically

Post by praneet » Thu Feb 21, 2019 12:22 pm

I used below code for getting the current RowIndex from ExcelDataSource
but for each datsource row it always return 0.
var TC = TestSuite.CurrentTestContainer;
int rowId1 = TC.DataContext.CurrentRowIndex;

Could you please help me

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

Re: Get RowIndex Programatically

Post by odklizec » Thu Feb 21, 2019 12:54 pm

Hi,

I'm using code like this in many of my tests and it works OK? So I guess you are applying it at wrong place? Are you sure you started whole test suite? Additionally, as far as I remember, it does not work with SmartFolder/TestCase iteration count (i.e. if SF/TC is looped via plain "iteration count", instead of data connector). But since you mentioned Excel connector, it should work just fine?
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

manish
Posts: 45
Joined: Fri Aug 10, 2018 12:46 pm

Re: Get RowIndex Programatically

Post by manish » Thu Feb 21, 2019 1:15 pm

Hi,

I guess you must be handling the datasource (excel) connector at the wrong place. As it has already been said, it needs to be associated with the Testcase rather than the Smart Folder.
Unbenannt.png
Unbenannt.png (8.55 KiB) Viewed 149 times
Regards,
Manish

praneet
Posts: 20
Joined: Thu Nov 08, 2018 2:22 am

Re: Get RowIndex Programatically

Post by praneet » Thu Feb 21, 2019 2:37 pm

manish wrote:
Thu Feb 21, 2019 1:15 pm
Hi,

I guess you must be handling the datasource (excel) connector at the wrong place. As it has already been said, it needs to be associated with the Testcase rather than the Smart Folder.
Unbenannt.png
Regards,
Manish
How do you create TestCase under smartfolder.
My Project structure as
---TEST SUITE
-----Test Case(DS associated)
--------- SmartFolder(IF Condition)
-------------- Recorded Module{Here I need row Count]

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

Re: Get RowIndex Programatically

Post by odklizec » Thu Feb 21, 2019 2:49 pm

Hi,

As I thought, and also suggested by Manish, the place where you obtaining data connector row is incorrect. In your actual testsuite configuration, TestSuite.CurrentTestContainer points to SmartFolder without Data Connector, hence it returns 0. So you must either create a codemodule/recording directly in Test Case (just before SmartFolder) or you must change your existing code like this:
var TC = TestSuite.Current.GetTestContainer("TestCaseName");
int rowId1 = TC.DataContext.CurrentRowIndex;
Where the TestCaseName must be replaced with TestCase name of your choice, from which you want to extract the actual row index. Hope this helps?
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