How to pass Ranorex snapshot to validate table
-
- Posts: 6
- Joined: Fri Sep 12, 2014 4:26 pm
How to pass Ranorex snapshot to validate table
Hi,
I used this code to validate table
const string NullString = "(null)";
public void Validate_TableContentEqual(Ranorex.Adapter repoItem, string filename_ReferenceTableSnapshot, string customLogMessage)
{
// cast repoItem to Table
Ranorex.Table table = repoItem.As <Ranorex.Table>();
// check if snapshot file exists
const string fileNotExists = "The given file does not exist: {0}";
if (!System.IO.File.Exists(filename_ReferenceTableSnapshot))
{
throw new Ranorex.RanorexException(string.Format(fileNotExists, filename_ReferenceTableSnapshot));
}
// restore table from snapshot
var snap = Ranorex.Core.ElementSnapshot.DeserializeXml(System.IO.File.ReadAllText(filename_ReferenceTableSnapshot));
Ranorex.Table refTable = null;
try
{
refTable = snap.Element;
}
catch
{
throw new Ranorex.RanorexException("Table could not be created from snapshot");
}
var tableAdapter = table.As<Ranorex.Table>();
if (tableAdapter==null)
{
throw new Ranorex.RanorexException("Table could not be restored from Snapshot");
}
// check if rowcount is identical
if (tableAdapter.Rows.Count != refTable.Rows.Count)
{
throw new Ranorex.RanorexException(String.Format ("Tables do not have same number of rows ({0} vs. {1})", tableAdapter.Rows.Count, refTable.Rows.Count));
}
// run through table-rows
for (int iRow = 0; iRow <= tableAdapter.Rows.Count - 1; iRow++)
{
int cellCountCur = tableAdapter.Rows[iRow].Cells.Count;
int cellCountRef = refTable.Rows[iRow].Cells.Count;
// check if number of cells is identical in current row
if (cellCountCur != cellCountRef)
{
throw new Ranorex.RanorexException(String.Format("Table-Row do not have same number of cells ({0} vs. {1})", cellCountCur, cellCountRef));
}
// run through cells in current row
for (int iCol = 0; iCol <= cellCountCur - 1; iCol++)
{
string aCurText = tableAdapter.Rows[iRow].Cells[iCol].As<Ranorex.Cell>().Text;
string aRefText = refTable.Rows[iRow].Cells[iCol].As<Ranorex.Cell>().Text;
if (customLogMessage.Trim().Equals(string.Empty) || customLogMessage.Trim().Equals (NullString) )
{
customLogMessage = "Comparing cells: actual value = {0}, expected value = {1}";
}
// validate whether current text and expected text are identical
Ranorex.Validate.AreEqual (aCurText, aRefText, customLogMessage);
}
}
// Log success
Ranorex.Report.Log (ReportLevel.Success, customLogMessage);
}
and passed the path of Ranorex snapshot in the user code but while running it is giving error as "Document must not contain #text nodes as children( on the line which is in bold) . " i have attached the Ranorex Snapshot also. Please help
I used this code to validate table
const string NullString = "(null)";
public void Validate_TableContentEqual(Ranorex.Adapter repoItem, string filename_ReferenceTableSnapshot, string customLogMessage)
{
// cast repoItem to Table
Ranorex.Table table = repoItem.As <Ranorex.Table>();
// check if snapshot file exists
const string fileNotExists = "The given file does not exist: {0}";
if (!System.IO.File.Exists(filename_ReferenceTableSnapshot))
{
throw new Ranorex.RanorexException(string.Format(fileNotExists, filename_ReferenceTableSnapshot));
}
// restore table from snapshot
var snap = Ranorex.Core.ElementSnapshot.DeserializeXml(System.IO.File.ReadAllText(filename_ReferenceTableSnapshot));
Ranorex.Table refTable = null;
try
{
refTable = snap.Element;
}
catch
{
throw new Ranorex.RanorexException("Table could not be created from snapshot");
}
var tableAdapter = table.As<Ranorex.Table>();
if (tableAdapter==null)
{
throw new Ranorex.RanorexException("Table could not be restored from Snapshot");
}
// check if rowcount is identical
if (tableAdapter.Rows.Count != refTable.Rows.Count)
{
throw new Ranorex.RanorexException(String.Format ("Tables do not have same number of rows ({0} vs. {1})", tableAdapter.Rows.Count, refTable.Rows.Count));
}
// run through table-rows
for (int iRow = 0; iRow <= tableAdapter.Rows.Count - 1; iRow++)
{
int cellCountCur = tableAdapter.Rows[iRow].Cells.Count;
int cellCountRef = refTable.Rows[iRow].Cells.Count;
// check if number of cells is identical in current row
if (cellCountCur != cellCountRef)
{
throw new Ranorex.RanorexException(String.Format("Table-Row do not have same number of cells ({0} vs. {1})", cellCountCur, cellCountRef));
}
// run through cells in current row
for (int iCol = 0; iCol <= cellCountCur - 1; iCol++)
{
string aCurText = tableAdapter.Rows[iRow].Cells[iCol].As<Ranorex.Cell>().Text;
string aRefText = refTable.Rows[iRow].Cells[iCol].As<Ranorex.Cell>().Text;
if (customLogMessage.Trim().Equals(string.Empty) || customLogMessage.Trim().Equals (NullString) )
{
customLogMessage = "Comparing cells: actual value = {0}, expected value = {1}";
}
// validate whether current text and expected text are identical
Ranorex.Validate.AreEqual (aCurText, aRefText, customLogMessage);
}
}
// Log success
Ranorex.Report.Log (ReportLevel.Success, customLogMessage);
}
and passed the path of Ranorex snapshot in the user code but while running it is giving error as "Document must not contain #text nodes as children( on the line which is in bold) . " i have attached the Ranorex Snapshot also. Please help
You do not have the required permissions to view the files attached to this post.
Re: How to pass Ranorex snapshot to validate table
Hi,
I would suggest you to check this code sample (table validation using snapshot):
http://www.ranorex.com/support/user-gui ... html#c7781
I would suggest you to check this code sample (table validation using snapshot):
http://www.ranorex.com/support/user-gui ... html#c7781
Pavel Kudrys
Ranorex explorer at Descartes Systems
Please add these details to your questions:
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
-
- Posts: 6
- Joined: Fri Sep 12, 2014 4:26 pm
Re: How to pass Ranorex snapshot to validate table
Hi,
I already tried with the example and mentioned the failure message from the report in the post.
i want to know why it is giving failure message.
I already tried with the example and mentioned the failure message from the report in the post.
i want to know why it is giving failure message.
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: How to pass Ranorex snapshot to validate table
Hello Mayank,
in the code examples - where your code snippet is taken from - there is a note that should be read carefully. It points out that Ranorex Snapshot files are compressed (zip archive) and need to be extracted first in order to use it in the validation. It seems that using the uncompressed snapshot file causes the mentioned error message ("Document must not contain #text nodes as children")!
Furthermore, this code example is intended to test against "common tables" and not against tables in web. Tables in web are structured differently (THead, TBody, TR, TD, ...) than tables in common desktop applications (Table, Row, Cell).
I've created a new code example to validate against web tables. This sample is quite similar to the one linked above but takes account of the different table structure.
Kind regards
Roland (E)
Ranorex Team
in the code examples - where your code snippet is taken from - there is a note that should be read carefully. It points out that Ranorex Snapshot files are compressed (zip archive) and need to be extracted first in order to use it in the validation. It seems that using the uncompressed snapshot file causes the mentioned error message ("Document must not contain #text nodes as children")!
Furthermore, this code example is intended to test against "common tables" and not against tables in web. Tables in web are structured differently (THead, TBody, TR, TD, ...) than tables in common desktop applications (Table, Row, Cell).
I've created a new code example to validate against web tables. This sample is quite similar to the one linked above but takes account of the different table structure.
Kind regards
Roland (E)
Ranorex Team
-
- Posts: 6
- Joined: Fri Sep 12, 2014 4:26 pm
Re: How to pass Ranorex snapshot to validate table
Hi Roland,
My snapshot is in the form of "*.rxsnp". How should i extract it because it not giving any option to extract.
Please check my attached Ranorex snapshot the earlier post.
Furthermore, I am not able to see your new solution as it is not showing in the examples.
Can you attach the solution with reply.
My snapshot is in the form of "*.rxsnp". How should i extract it because it not giving any option to extract.
Please check my attached Ranorex snapshot the earlier post.
Furthermore, I am not able to see your new solution as it is not showing in the examples.
Can you attach the solution with reply.
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: How to pass Ranorex snapshot to validate table
Hi,
The archive contains a file with the same file name – so during extraction please provide another file name or path.
Kind regards,
Roland (E)
Ranorex Team
Even rxsnp files can be extracted. I use 7-Zip but I’m pretty sure, other tools are able to do so as well.My snapshot is in the form of "*.rxsnp". How should i extract it because it not giving any option to extract.
The archive contains a file with the same file name – so during extraction please provide another file name or path.
Please refresh your browser, clear cache, restart your browser or use another browser. Here's the link again: LinkFurthermore, I am not able to see your new solution as it is not showing in the examples.
Kind regards,
Roland (E)
Ranorex Team
Re: How to pass Ranorex snapshot to validate table
Hi Roland,Support Team wrote: I've created a new code example to validate against web tables. This sample is quite similar to the one linked above but takes account of the different table structure.
Kind regards
Roland (E)
Ranorex Team
I'm just in a need to validate whole HTML table and I thought it would be good to use the snapshot comparison approach. So far, I validated the HTML tables row by row, using CVS reference files, but it seems to be impractical for larger tables. So I wanted to try your sample, but it seems to be gone? Any chance to have it back? Thanks in advance.
Pavel Kudrys
Ranorex explorer at Descartes Systems
Please add these details to your questions:
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
-
- Certified Professional
- Posts: 74
- Joined: Mon Aug 14, 2006 7:17 pm
- Location: CH
Re: How to pass Ranorex snapshot to validate table
Hi all,
I have a question, why are you validating a repository file against the actual table? Why are you not saving the actual table with its row, columns, values and attributes into a an xml file.
Then you can use XPathNavigator and you can validate the table with XPath.
Regards
Dan
I have a question, why are you validating a repository file against the actual table? Why are you not saving the actual table with its row, columns, values and attributes into a an xml file.
Then you can use XPathNavigator and you can validate the table with XPath.
Regards
Dan
Re: How to pass Ranorex snapshot to validate table
Hi Dan,
We are not trying to compare repository file but Ranorex Snapshot file, which holds the structure of GUI in XML file. This file can be created either manually (from spy) or calling a method from code. So it's very easy to create GUI reference files. I think it's a great idea to use snapshots for validation. I personally don't have a clue how to use XPathNavigator and to be quite honest, I would prefer to use Ranorex own tools and methods wherever possible. This is why I would like to see the code sample mentioned in Roland's post and which seems to be gone now
We are not trying to compare repository file but Ranorex Snapshot file, which holds the structure of GUI in XML file. This file can be created either manually (from spy) or calling a method from code. So it's very easy to create GUI reference files. I think it's a great idea to use snapshots for validation. I personally don't have a clue how to use XPathNavigator and to be quite honest, I would prefer to use Ranorex own tools and methods wherever possible. This is why I would like to see the code sample mentioned in Roland's post and which seems to be gone now
Pavel Kudrys
Ranorex explorer at Descartes Systems
Please add these details to your questions:
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
Re: How to pass Ranorex snapshot to validate table
OK, I think I figured it out myself I was able to adapt the existing "common table" validation sample for HTML tables. Here is the code (just in case anyone needs this too):
const string NullString = "(null)"; public void Validate_TableContentEqual(Ranorex.Adapter repoItem, string filename_ReferenceTableSnapshot, string customLogMessage) { // cast repoItem to Table Ranorex.TableTag table = repoItem.As <Ranorex.TableTag>(); // check if snapshot file exists // don't forget the snapshot needs to be extracted (unzipped) before being used!!! const string fileNotExists = "The given file does not exist: {0}"; if (!System.IO.File.Exists(filename_ReferenceTableSnapshot)) { throw new Ranorex.RanorexException(string.Format(fileNotExists, filename_ReferenceTableSnapshot)); } // restore table from snapshot var snap = Ranorex.Core.ElementSnapshot.DeserializeXml(System.IO.File.ReadAllText(filename_ReferenceTableSnapshot)); Ranorex.TableTag refTable = null; try { refTable = snap.Element; } catch { throw new Ranorex.RanorexException("Table could not be created from snapshot"); } var tableAdapter = table.As<Ranorex.TableTag>(); if (tableAdapter==null) { throw new Ranorex.RanorexException("Table could not be restored from Snapshot"); } // check if rowcount is identical IList<TrTag> iListCurRows = tableAdapter.FindDescendants<TrTag>(); IList<TrTag> iListRefRows = refTable.FindDescendants<TrTag>(); int rowCountCur = iListCurRows.Count; int rowCountRef = iListRefRows.Count; if (rowCountCur != rowCountRef) { throw new Ranorex.RanorexException(String.Format ("Tables do not have same number of rows ({0} vs. {1})", rowCountCur, rowCountRef)); } // run through table-rows foreach (TrTag curRow in iListCurRows) { IList<TdTag> iListCurRowCells = curRow.FindDescendants<TdTag>(); TrTag rowRef = iListRefRows[iListCurRows.IndexOf(curRow)]; IList<TdTag> iListRefRowCells = rowRef.FindDescendants<TdTag>(); int cellCountCur = iListCurRowCells.Count; int cellCountRef = iListRefRowCells.Count; // check if number of cells is identical in current row if (cellCountCur != cellCountRef) { throw new Ranorex.RanorexException(String.Format("Table-Rows do not have same number of cells ({0} vs. {1})", cellCountCur, cellCountRef)); } // run through cells in current row foreach (TdTag curCell in iListCurRowCells) { string cellInnerTextCur = curCell.InnerText; string cellInnerTextRef = iListRefRowCells[iListCurRowCells.IndexOf(curCell)].InnerText; if (customLogMessage.Trim().Equals(string.Empty) || customLogMessage.Trim().Equals(NullString) ) { customLogMessage = "Comparing cells: actual value = {0}, expected value = {1}"; } // validate whether current text and expected text are identical Ranorex.Validate.AreEqual(cellInnerTextCur, cellInnerTextRef, customLogMessage); } } // Log success Ranorex.Report.Log (ReportLevel.Success, "OK"); }I'm not quite sure my adapted code is the best way, but it seems it works for my tables Feel free to make changes you think would make the code more efficient.
Pavel Kudrys
Ranorex explorer at Descartes Systems
Please add these details to your questions:
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
Compilation errors in "Advance validation- whole table" code
I'm tring to validate the validate a whole table in Ranorex.
Copy pasted the "Advance validation -whole table" code in a usercode module. keep getting 2 compilation errors when playing the "user code".Below are the error messages.when googled,it shows a parentheses is expected.checked all the loops,everything is right.I don't understand the reason for the errors.
Errors:
Type or namespace definition, or end-of-file expected (CS1022)
} expected (CS1513)
attached snapshot and required screenshot
You do not have the required permissions to view the files attached to this post.
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: How to pass Ranorex snapshot to validate table
Hi nisha,
We have updated the code in these examples and it should now work as expected. May I ask you if you can try the latest example?
Please also note that the snapshot file needs to be extracted first. Therefore, you could use 7-Zip or any other tool, which can extract archives. The archive itself contains a file with the same name - so please extract it to another location.
Please let me know if you were able to overcome the problem. Otherwise, I'd need your whole solution to analyze the issue on my machine.
Regards,
Markus (S)
We have updated the code in these examples and it should now work as expected. May I ask you if you can try the latest example?
Please also note that the snapshot file needs to be extracted first. Therefore, you could use 7-Zip or any other tool, which can extract archives. The archive itself contains a file with the same name - so please extract it to another location.
Please let me know if you were able to overcome the problem. Otherwise, I'd need your whole solution to analyze the issue on my machine.
Regards,
Markus (S)
Re: How to pass Ranorex snapshot to validate table
Hi Markus,
Thank you for your response.
I extracted the snapshot using 7-zip and stored the extracted filename in different name(open archive->extract->auto rename).Even after extracting the file extension is .rxsnp
In the Ranorex snapshot ,the grid is recognized as "unknown" element. Ranorex not able to identify it as "Table".
Our application under test is built on Delphi and tables layout are based on Devexpress grid. I've got reply from Georg Kapeller(Ranorex support team) that Ranorex doesn't provide much support on Delphi application.
we want to use Ranorex mainly for Regression testing of our application and it includes mainly of comparing whole table values for every release.
Regards,
Nisha.
Thank you for your response.
I extracted the snapshot using 7-zip and stored the extracted filename in different name(open archive->extract->auto rename).Even after extracting the file extension is .rxsnp
In the Ranorex snapshot ,the grid is recognized as "unknown" element. Ranorex not able to identify it as "Table".
Our application under test is built on Delphi and tables layout are based on Devexpress grid. I've got reply from Georg Kapeller(Ranorex support team) that Ranorex doesn't provide much support on Delphi application.
we want to use Ranorex mainly for Regression testing of our application and it includes mainly of comparing whole table values for every release.
Regards,
Nisha.
Re: How to pass Ranorex snapshot to validate table
hi Markus,
I tried with the new code in the code examples.
Extracted zip file using 7 zip and saved it in the same folder with same name(and renamed the original file).But only error message "The given file doesn't exists".
In the "filename_ReferenceTableSnapshot" , Do I need to send the full path or just a file name ?I tried both, but no luck.
e.g. If my extracted snapshot filename is "Hardflagimpact.rxsnp" and saved in the Ranorex\Snapshots" folder. what is the value for "filename_ReferenceSnapshot" variable.
1.Hardflagimpact.rxsnp
2.Hardflagimpact
3.C:\Users\nsiv\Documents\Ranorex\Snapshots
4.C:\Users\nsiv\Documents\Ranorex\Snapshots\Hardflagimpact.rxsnp
5.C:\Users\nsiv\Documents\Ranorex\Snapshots\Hardflagimpact
I tried all possible combinations, but receiving same error. With the previous code it was working fine but received error message "Table could not be created from snapshot" which is actually a limitation in Ranorex on Devexpress grid.
I tried with the new code in the code examples.
Extracted zip file using 7 zip and saved it in the same folder with same name(and renamed the original file).But only error message "The given file doesn't exists".
In the "filename_ReferenceTableSnapshot" , Do I need to send the full path or just a file name ?I tried both, but no luck.
e.g. If my extracted snapshot filename is "Hardflagimpact.rxsnp" and saved in the Ranorex\Snapshots" folder. what is the value for "filename_ReferenceSnapshot" variable.
1.Hardflagimpact.rxsnp
2.Hardflagimpact
3.C:\Users\nsiv\Documents\Ranorex\Snapshots
4.C:\Users\nsiv\Documents\Ranorex\Snapshots\Hardflagimpact.rxsnp
5.C:\Users\nsiv\Documents\Ranorex\Snapshots\Hardflagimpact
I tried all possible combinations, but receiving same error. With the previous code it was working fine but received error message "Table could not be created from snapshot" which is actually a limitation in Ranorex on Devexpress grid.
Re: How to pass Ranorex snapshot to validate table
Hi Markus,
With new code, able to send the file path name in the "filename_ReferenceSnapshot"(C:\Users\nsiv\Documents\Ranorex\Snapshots\Hardflagimpact.rxsnp),but it ended up in the error "Table could not be created from snapshot".
With new code, able to send the file path name in the "filename_ReferenceSnapshot"(C:\Users\nsiv\Documents\Ranorex\Snapshots\Hardflagimpact.rxsnp),but it ended up in the error "Table could not be created from snapshot".