Validating multiple items with snapshot

Class library usage, coding and language questions.
cpalex
Posts: 35
Joined: Sat Feb 17, 2018 12:37 am

Validating multiple items with snapshot

Post by cpalex » Mon Mar 23, 2020 5:41 am

Our AUT has a lot of totals sections, and once a screen is loaded, they do not change.

However, when using the standard Validate.AttributeEquals, Ranorex has to find each element. When I am doing 20 separate validations on one page, this can take some time.

So, I am looking for a method to speed up a handful of validations in a particular container.

I have tried a couple things, but the most recent is to load a snapshot of the item. That way, the AUT only has to be scanned once.

However, once I have the snapshot, I am not entirely sure how to use it to validate the elements inside the snapshot quickly

Here is the simple code I use to grab the snapshot:

Code: Select all

MyRepository repo = MyRepository.Instance;
ElementSnapshot snap = ElementSnapshot.Capture(repo.FrmMainCMW.PanelMain, false, false);
This produces the snapshot attached.

From here, how can I validate attributes of elements inside that snapshot? Or is there a better way to do multiple validations quickly?

For example, I would like to validate the window text of the 'editTotal_Cores' element.
Attachments
snap.rxsnp
(14.93 KiB) Downloaded 2 times

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

Re: Validating multiple items with snapshot

Post by odklizec » Mon Mar 23, 2020 8:59 am

Hi,

The snapshot you posted contains no screenshots and so it's a bit hard to understand the UI. Plus you forgot to post an xpath of element, that returns the elements you want to validate?

Generally speaking, you should be able to use Advanced Validation example (entire table) shown here:
https://www.ranorex.com/help/latest/han ... -examples/
Of course, it may require some adaptations to your UI.

Another approach could be getting all elements you want to validate via single xpath, loop through all elements and save them to CSV file. Then you can use this file as a reference file for validation purposes. But this approach would require some heavy coding.
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

cpalex
Posts: 35
Joined: Sat Feb 17, 2018 12:37 am

Re: Validating multiple items with snapshot

Post by cpalex » Mon Mar 23, 2020 2:20 pm

The problem with the "entire table" code, is that isn't a table, and I use this code group about 5,000 times in my AUT. So creating a snapshot and storing them for each test case would be impractical.

I took a new snapshot with screen shots and uploaded it.

When you say to use a single XPATH that gets all the elements.... Are you referring to an ambiguous path, and then using a for loop to search for each one? like

//container/element

And then search for each one by index? If so, that would take just as much time as defining each one, and using Validate.AttributeEquals for each one.

Or is there a different technique to the path that will loop through them all?

My main goal here is to shave time, since, like I said, I use this type of container validation in MANY places. 2 seconds per container time saving would add up to a much faster test suite.
Attachments
snap.rxsnp
(118.31 KiB) Downloaded 3 times

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

Re: Validating multiple items with snapshot

Post by odklizec » Tue Mar 24, 2020 11:31 am

Hi,

Here is a rough sample solution, where you can find basic concept of comparing snapshots with UI. It's definitely not perfect ;) But you may get the idea and eventually improve it according your needs.

However, I'm personally using snapshots only for very large HTML tables. I think that using snapshots for too few elements is like going on fleas with cannon :) In your case, it would be probably better to store all elements of given container to ref. csv file, do the same with UI in realtime and simply compare csv files. But this would require another code.
Attachments
SnapshotValidation.zip
(135.59 KiB) Downloaded 1 time
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

cpalex
Posts: 35
Joined: Sat Feb 17, 2018 12:37 am

Re: Validating multiple items with snapshot

Post by cpalex » Tue Mar 24, 2020 9:19 pm

Thank you very much!

I took your example, and adapted it to work for my situation. However, I discovered that the snapshot was taking almost as long to grab as the individual validations took, so I wasn't saving much time.

However, I gleaned from your example the use of the container elements, and moved away from snapshots.

What I came up with shaved my validations from about 3 seconds down to about .3 seconds. Multiplied by 3 different elements, and about 500 test cases.... This will speed things up a LOT.

Here is a slimmed down version of what I came up with. This allows me to create a UserCodeModule for each element I am identifying, and just pass in the variables with a data source or data binding, so I don't need a reference snapshot or CSV:

Code: Select all

string _TotalCores = "";
[TestVariable("91de586f-3c39-4824-a6ce-5a4285b176a6")]
public string TotalCores
{
	get { return _TotalCores; }
	set { _TotalCores = value; }
}

string _Remaining = "";
[TestVariable("238346b5-d2dd-4bfb-ab0e-53ddbb592c34")]
public string Remaining
{
	get { return _Remaining; }
	set { _Remaining = value; }
}

string _Deposited = "";
[TestVariable("f160199c-5f46-4e57-9711-db0f5bb69a08")]
public string Deposited
{
	get { return _Deposited; }
	set { _Deposited = value; }
}

void ITestModule.Run()
{
	MyRepo repo = MyRepo.Instance;
	
	Ranorex.Container credContainer = repo.FrmMainCMW.PanelMainInfo.CreateAdapter<Ranorex.Container>(false);

	IList<Ranorex.Unknown> listOfElements = credContainer.Find<Ranorex.Unknown>("./element");
	
	ValidateControl(listOfElements,"editTotal_Cores",TotalCores);
	
	ValidateControl(listOfElements,"editTotal_Balance",Remaining);
	
	ValidateControl(listOfElements,"editTotal_AmtDeposited",Deposited);
}

private void ValidateControl(IList<Ranorex.Unknown> listOfElements, string controlName, string expectedValue)
{
	// Find index of controlName
	int i;
	for (i = 0; i < listOfElements.Count; i++)
	{
		string find = listOfElements[i].Element.GetAttributeValueText("ControlName");
		if (find == controlName)
		{
			break;
		}
		if (i == listOfElements.Count)
		{
			throw new RanorexException("Control name not found!");
		}
	}
	string actualValue = listOfElements[i].Element.GetAttributeValueText("WindowText");
	Report.Log(ReportLevel.Info,"Info","Validating " + controlName);
	
	if (actualValue == expectedValue)
	{
		Report.Log(ReportLevel.Success,controlName + " is correct");
	}
	else
	{
		Report.Log(ReportLevel.Failure,controlName + " is incorrect!  Actual value = '" + actualValue + "', expected value = '" + expectedValue + "'");
	}
}

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

Re: Validating multiple items with snapshot

Post by odklizec » Tue Mar 24, 2020 9:25 pm

Hi,

I'm glad you found a viable solution and thanks for sharing it! ;)
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