Select range according to the current value in the "main" Smart Folder

Best practices, code snippets for common functionality, examples, and guidelines.
EdJulio
Posts: 2
Joined: Mon Nov 01, 2021 12:11 pm

Select range according to the current value in the "main" Smart Folder

Post by EdJulio » Mon Nov 01, 2021 12:48 pm

Hi,
I couldn't find a good answer for a situation that I'm having here. I'll try to explain:

I have a smart folder that has a data source that uses a specific product (Range 4,9) .
Inside the Smart_Folder1 has some Recording (using the specific ranges). Inside the Smart_Folder1 has the Smart_Folder2 (with other data source) that I want to use to validate a table in a website (specific for each product). However, I want to use different ranges in the Smart_Folder2 according to the current product selected in the Smart_Folder1. (Confusing?).
Hierarchy.jpg
I found on looping-module-in-a-test-case-t10499.html#p42114 that I can create a code module to to change the range in each iteration. However, the code in that post is outdated. I tried to change myself but without success.

Does anyone know a way to make that (code or through Ranorex.)
You do not have the required permissions to view the files attached to this post.

Jacob
Certified Professional
Certified Professional
Posts: 120
Joined: Mon Mar 22, 2021 10:01 pm

Re: Select range according to the current value in the "main" Smart Folder

Post by Jacob » Fri Nov 05, 2021 4:22 pm

Hi EdJulio,

Welcome to the Ranorex Forums! The first thing that comes to mind would be to use the Command Line parameters for Selective Test Runs. Look under the "Set a data range in a test container’s data source" in the linked article. It is possible to create a batch file with specific parameters passed to the Test Suite's executable file so that you can dynamically set the selected rows to pull from the data source at runtime. I think this is simpler than trying to code my way out of situations like this, and can be dynamic enough to do all kinds of stuff. I hope this helps!

--Jacob
Image

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

Re: Select range according to the current value in the "main" Smart Folder

Post by odklizec » Fri Nov 12, 2021 10:52 am

Hi,

Here is the updated code reflecting your test:

Code: Select all

string curTCName = TestSuite.CurrentTestContainer.Name;
var curTC = TestSuite.Current.GetTestContainer(curTCName);
var setRangeTC = TestSuite.Current.GetTestContainer("Validate_Qty_Break_table");
 
string rowValue = curTC.DataContext.CurrentRow.Values[curTC.DataContext.Source.Columns["columnName"].Index]; //get value from current data range 
if (rowValue == "0")
{
    setRangeTC.DataRange.MinRange = 0;
    setRangeTC.DataRange.MaxRange = 2;
    setRangeTC.DataContext.SetRange(sitesTC.DataRange.MinRange,sitesTC.DataRange.MaxRange); // sets first 3 rows of QtyBreakProdutSearch2 data source
} 
else if (rowValue == "3")
{
    setRangeTC.DataContext.SetRange(DataRangeSet.Parse("5-7,9")); // sets rows 6-8 and 10 
}
Simply add the above code in a new code module, placed anywhere inside Search_Product TC (but "before" Validate_Qty_Break_table SF). Of course, change the column name and data ranges according your needs. 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

EdJulio
Posts: 2
Joined: Mon Nov 01, 2021 12:11 pm

Re: Select range according to the current value in the "main" Smart Folder

Post by EdJulio » Tue Jan 18, 2022 10:00 am

Thanks for all the answer of this post, and sorry for the late reply.
Pavel, I tried through code again but I noticed the CurrentRow is returning null which I think is what causes the "Object reference not set to an instance of an object". I can't find where the problem could be. Any thoughts of what could be?
CurrentRow.jpg
You do not have the required permissions to view the files attached to this post.