Using html Table Snapshot for table element validation

Best practices, code snippets for common functionality, examples, and guidelines.
bthompson
Posts: 6
Joined: Fri Mar 25, 2022 9:00 pm

Using html Table Snapshot for table element validation

Post by bthompson » Fri Mar 25, 2022 10:55 pm

Good Afternoon All,

im curious as to how you pass an extracted snapshot file into the user code for html table validation.

[language=c#]

Code: Select all

 string filename_ReferenceTableSnapshot
[/language]

are we supposed to replace that with a string set to the path of the snapshots folder after extraction?
something along the lines of,

Code: Select all

string path="C:/Path_To_File/";
public void Validate_WebTableContentEqual(Ranorex.Adapter repoItem, string path, string customLogMessageOverall, string customLogMessageDetail)  
Operating system: Windows 10 x64
OS Version: 10.0.19041
Ranorex Version: 10.1.6.0

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

Re: Using html Table Snapshot for table element validation

Post by odklizec » Tue Mar 29, 2022 8:13 am

Hi,

I guess you are not pretty familiar with C# yet? Basically, you need to replace the filename_ReferenceTableSnapshot with variable of your choice, containing the path to the snapshot file. But it must be done on the line, where you actually using the validation method, not in the method declaration.

Basically, you must add the table validation method to the code module (user code collection) of your choice and then call it anywhere in your project (either from Recording or Code module). Here is how I use it in my project:
TableValidation.png
You do not have the required permissions to view the files attached to this post.
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

bthompson
Posts: 6
Joined: Fri Mar 25, 2022 9:00 pm

Re: Using html Table Snapshot for table element validation

Post by bthompson » Tue Mar 29, 2022 4:31 pm

Your response is vey much appreciated!

Yes im quite new to C# and this issue had been plaguing me, what I was doing was setting the path directly in one variable and couldn't understand why that wouldn't work haha. Seems a few extra variables are needed to express the true pathing, thank you very much im going to go ahead and give this a shot!

bthompson
Posts: 6
Joined: Fri Mar 25, 2022 9:00 pm

Re: Using html Table Snapshot for table element validation

Post by bthompson » Wed May 18, 2022 2:26 am

odklizec wrote:
Tue Mar 29, 2022 8:13 am
Hi,

I guess you are not pretty familiar with C# yet? Basically, you need to replace the filename_ReferenceTableSnapshot with variable of your choice, containing the path to the snapshot file. But it must be done on the line, where you actually using the validation method, not in the method declaration.

Basically, you must add the table validation method to the code module (user code collection) of your choice and then call it anywhere in your project (either from Recording or Code module). Here is how I use it in my project:
TableValidation.png
Sorry for my delayed response, another project came up which had much higher priority. I added the source code for the html web table validation to a user code module, so I then call this method in a separate code module with the code you showed? When doing so, I was met with many errors as variables weren't defined, like `rm_FileName` and `rm_Location`, I understand those are probably just templates for naming convention to be used in the function but I couldn't seem to target the snapshot file properly and decided to start over from scratch as I had tried it in 2 different methods. I saw something about snapshots needing to be extracted but when I try to do so, I get an error stating that the snapshot cant be opened as an archive, is this to be expected? The Snapshot Im using is for an html table with over 200 rows, so traditional validation row by row is cumbersome. The loop described on https://www.ranorex.com/help/latest/han ... les/#c8203 is exactly what im looking for, and as a pre-existing ranorex method is something I want to learn to use.
You do not have the required permissions to view the files attached to this post.

bthompson
Posts: 6
Joined: Fri Mar 25, 2022 9:00 pm

Re: Using html Table Snapshot for table element validation

Post by bthompson » Wed May 18, 2022 2:42 am

Here are pictures of what I'm trying to do haphazardly.
Image

Image

AdminPortal.ValidateHtmlTable is where the source code for the validation exists, as posted on the ranorex code examples, which I try to call but clearly isn't the way to do so. What im trying to do is compare the snapshot to what exists on the webpage, and unless I've misunderstood the code, I believe that's what it is meant to do. Apologies for my lack of knowledge here, and would certainly appreciate more insight on the matter.

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

Re: Using html Table Snapshot for table element validation

Post by odklizec » Wed May 18, 2022 7:20 am

Hi,

The code from my sample pic is just an example ;) You can't use it, because there are parameters, which are useless for you. Just follow the code from Ranorex sample page. it works and it should be enough for you.
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

bthompson
Posts: 6
Joined: Fri Mar 25, 2022 9:00 pm

Re: Using html Table Snapshot for table element validation

Post by bthompson » Wed May 18, 2022 7:24 am

That makes much more sense, as the I was essentially trying to re-create the variables you were using, but as they were out of context, it made no sense to me. Haha, appreciate your time.

As far as the extraction for the snapshot goes, is there a reason why I’m met with errors when trying to do so? Or is that not for the html web table?

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

Re: Using html Table Snapshot for table element validation

Post by odklizec » Wed May 18, 2022 7:37 am

Hi,

The attached snapshot is already extracted, so it does not need any additional extraction. If you open it in notepad or similar editor, you will clearly see its xml structure. So it's already extracted and can be directly used with table validation method.
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