dataGrid Values validation

Ask general questions here.
rj-nora
Posts: 38
Joined: Thu Mar 11, 2010 3:56 pm

dataGrid Values validation

Post by rj-nora » Wed Apr 07, 2010 6:47 pm

Good afternoon i'm testing Ranorex Studio 2.2 Trial version and at this moment i need to validate if a dataGridValues has 24 lines and 3 columms in a .NET application.

I'm in an internship to complete my graduation on Computer Engineering, and i´ll have to create an automation test platform to automate Manual Test Cases for new releases on Critical Manufacturing company.

´With the validate button on record mode, Ranorex doesn't provide me the contents of a dataGridValues.
It is because i´m using the Trial version?

I need to validate the values of that DataGridValues one by one or exist any other option to do that?

I can validate that if the DataGrid has a certain number of lines and columms without using scripts?If not can you provide me an possible library to do that?



I have a litle hurry because at this time i need to choose which tool i'll use to the internship.


Best regards

email: [email protected] or [email protected]

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: dataGrid Values validation

Post by Ciege » Wed Apr 07, 2010 7:07 pm

Use Ranorex Spy to see how the grid is recognized. From there you can write a little code to get the Grid object then you can use Grid.Rows or Grid.Columns to determine the number of rows and columns.
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

rj-nora
Posts: 38
Joined: Thu Mar 11, 2010 3:56 pm

Re: dataGrid Values validation

Post by rj-nora » Thu Apr 08, 2010 10:46 am

Ciege can you show me an script example for validate if the dataGridValues has 24 rows and 2 columns please? I haved already read the User Guide chapter Code Actions, I know where i have to do the script but i'm having some problems to do that validation because i don't know how can i get the object named Table_datGridValues and validate the columns or rows.
i have this on UserCode

public static void Validate_Table_dataGridValues1()
{
//Your code here. Code inside this method will not be changed by the code generator.
Report.Info("Validating Exists on item 'FormTact_Chart_4_2_0_0.Table_dataGridValues'.");
//Validate.Exists(repo.FormTact_Chart_4_2_0_0.Table_dataGridValuesInfo);
for(_table_datagridvaluesInfo.Rows

}



Thanck you very much

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: dataGrid Values validation

Post by Ciege » Thu Apr 08, 2010 4:11 pm

Here is a very brief example. With this example and with a valid table object you can iterate through the rows and output their data to the log. This should get you on the right path.

Code: Select all

try
{
 foreach (Ranorex.Row row in RanorexTable.Rows)
 {
  Report.Info("Found row: " + row.Element.GetAttributeValue("AccessibleValue").ToString());
 }
}
catch (Exception e)
{
 Report.Error(e.ToString());
}
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

rj-nora
Posts: 38
Joined: Thu Mar 11, 2010 3:56 pm

Re: dataGrid Values validation

Post by rj-nora » Thu Apr 08, 2010 11:46 pm

ciege ranorex launched a error when i implement that code, saying that RanorexTable doesn't exist

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: dataGrid Values validation

Post by Ciege » Thu Apr 08, 2010 11:52 pm

Like I said you need a valid table object.
RanorexTable happens to be the variable name that I used for the table object.
Set RanorexTable to a valid table object using FindSingle or your preferred method of setting the object.

In the code below RanorexFormName is a valid form object that the table lives on. Make sure that is set or use Host.Local.FindSingle instead to search from the desktop.

Code: Select all

Ranorex.Table RanorexTable = RanorexFormName.FindSingle(".//table[@controlname='" + strTableName + "' or @accessiblename='" + strTableName + "' ]", 60000);
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

rj-nora
Posts: 38
Joined: Thu Mar 11, 2010 3:56 pm

Re: dataGrid Values validation

Post by rj-nora » Fri Apr 09, 2010 11:20 am

Ciege i've tried several scritps for example "Code Examples"--> General and using the script above(working with 64bit win7)
// Call explorer.exe
System.Diagnostics.Process.Start("explorer.exe");

then i tried first with:
Form fileExplorer = Host.Local.FindChild<Ranorex.Form>("My Computer");
fileExplorer.Activate();
Button closeButton = fileExplorer.FindDescendant<Ranorex.Button>("Close");
closeButton.Click();

and second:
Form fileExplorer = "/form[@title='My Computer']";
fileExplorer.Activate();
Button closeButton = fileExplorer.FindSingle<Ranorex.Button>
("titlebar/button[@accessiblename='Close']");
closeButton.Click();

and the results were 5 errors on the first scritp(Cannot implicitly convert type 'Ranorex.Form' to 'System.Windows.Forms.Form' (CS0029),'Form' is an ambiguous reference between 'System.Windows.Forms.Form' and 'Ranorex.Form' (CS0104),'System.Windows.Forms.Form' does not contain a definition for 'FindDescendant' and no extension method 'FindDescendant' accepting a first argument of type 'System.Windows.Forms.Form' could be found (are you missing a using directive or an assembly reference?) (CS1061)....

on the second script others 5 errors,between (CS0029),(CS0104),CS1061,CS0069 and

Every time i tried to find a form those errors are showed. Can you explain to me whats the problem? I used the Ranorex Spy to find the title or the class name of the form i´m testing this moment and nothing solves the problem.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: dataGrid Values validation

Post by Support Team » Fri Apr 09, 2010 12:14 pm

There are Form objects both in the System.Windows.Forms and the Ranorex namespace, and obviously you have "using" statements for both namespaces in your script. To correct the compiler error, you can either remove one of the "using" statements or qualify every usage of Form, e.g.:
Ranorex.Form fileExplorer = "/form[@title='My Computer']";
Regards,
Alex
Ranorex Support Team
.
Image

rj-nora
Posts: 38
Joined: Thu Mar 11, 2010 3:56 pm

Re: dataGrid Values validation

Post by rj-nora » Fri Apr 09, 2010 3:01 pm

Thank you very much ciege and support team help i finally get this result!

2010/04/09 14:46:24.806 INFO User Found row: 0:00
2010/04/09 14:46:24.816 INFO User Found row: 1:00
2010/04/09 14:46:24.836 INFO User Found row: 2:00
2010/04/09 14:46:24.836 INFO User Found row: 3:00
2010/04/09 14:46:24.856 INFO User Found row: 4:00
2010/04/09 14:46:24.876 INFO User Found row: 5:00
2010/04/09 14:46:24.896 INFO User Found row: 6:00
2010/04/09 14:46:24.906 INFO User Found row: 7:00

whith that script :

Report.Info("Validating columns and rows in datagrid'.");

Ranorex.Form tactform = ("/form[@controlname='TactChart']");
Ranorex.Table RanorexTable = tactform.FindSingle("/form[@controlname='TactChart']/container/container[@controlname='_togglePanel']/tabpagelist/tabpage[@controlname='_tabPageValues']/table[@controlname='_dataGridValues']");

try
{
foreach (Ranorex.Row row in RanorexTable.Rows)
{
Report.Info("Found row: " + row.Element.GetAttributeValue("AccessibleValue").ToString());
}
Report
}
catch (Exception e)
{
Report.Error(e.ToString());
}

Now i want to make the same to the columns count...but i´m using the same script to columns but the programm doesn't counting them...i only change rows to columns,i´m not seeing none error but the program shows Total Columns:0...can you say me why?

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: dataGrid Values validation

Post by Ciege » Fri Apr 09, 2010 7:02 pm

rj-nora wrote:Now i want to make the same to the columns count...but i´m using the same script to columns but the programm doesn't counting them...i only change rows to columns,i´m not seeing none error but the program shows Total Columns:0...can you say me why?
So based on what you have leared so far (i.e. Table.Rows) think you can figure out the *Columns* part of it on your own?

Another hint. Check the installed Ranorex API Documentation for Table.Rows and then check for Table.??? :)
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

rj-nora
Posts: 38
Joined: Thu Mar 11, 2010 3:56 pm

Re: dataGrid Values validation

Post by rj-nora » Mon Apr 12, 2010 12:26 pm

Ciege wrote:
rj-nora wrote:Now i want to make the same to the columns count...but i´m using the same script to columns but the programm doesn't counting them...i only change rows to columns,i´m not seeing none error but the program shows Total Columns:0...can you say me why?
So based on what you have leared so far (i.e. Table.Rows) think you can figure out the *Columns* part of it on your own?

Another hint. Check the installed Ranorex API Documentation for Table.Rows and then check for Table.??? :)
Ciege i didn't understand your question i don't know the word "leared", at this moment i want to count Columns of my DataGrid like i did to count rows with your help,but nothing happens.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: dataGrid Values validation

Post by Support Team » Mon Apr 12, 2010 1:52 pm

rj-nora wrote: at this moment i want to count Columns of my DataGrid like i did to count rows with your help,but nothing happens.
Maybe because there are no columns? Did you check if there are elements for the columns in Ranorex Spy? Ranorex tables do not support columns in all technologies, however, you can get the number of columns by counting the number of cells in the header row or first data row!

Regards,
Alex
Ranorex Support Team
.
Image

rj-nora
Posts: 38
Joined: Thu Mar 11, 2010 3:56 pm

Re: dataGrid Values validation

Post by rj-nora » Mon Apr 12, 2010 2:20 pm

Support Team wrote:
rj-nora wrote: at this moment i want to count Columns of my DataGrid like i did to count rows with your help,but nothing happens.
Maybe because there are no columns? Did you check if there are elements for the columns in Ranorex Spy? Ranorex tables do not support columns in all technologies, however, you can get the number of columns by counting the number of cells in the header row or first data row!

Regards,
Alex
Ranorex Support Team
Yes each row has 2 cells!i attached the screen shot of the datagrid..How can i use the loop foreach to count them? Using this methodthe Report info is Total Columns is :0. I need to see how many columns and rows exists..

Ranorex.Form tactform = ("/form[@controlname='TactChart']");
Ranorex.Table RanorexTable = tactform.FindSingle("/form[@controlname='TactChart']/container/container[@controlname='_togglePanel']/tabpagelist/tabpage[@controlname='_tabPageValues']/table[@controlname='_dataGridValues']");

try
{
foreach (Ranorex.Row row in RanorexTable.Rows)
{
Report.Info("Found row: " + row.Element.GetAttributeValue("AccessibleValue").ToString());
}
Report
}
catch (Exception e)
{
Report.Error(e.ToString());
}
Last edited by rj-nora on Thu Apr 15, 2010 12:20 pm, edited 1 time in total.

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: dataGrid Values validation

Post by Ciege » Mon Apr 12, 2010 4:17 pm

rj-nora wrote:Ciege i didn't understand your question i don't know the word "leared", at this moment i want to count Columns of my DataGrid like i did to count rows with your help,but nothing happens.
Sorry, typo... Learned is what I meant to say...
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: dataGrid Values validation

Post by Ciege » Mon Apr 12, 2010 4:21 pm

rj-nora wrote: Yes each row has 2 cells!i attached the screen shot of the datagrid..How can i use the loop foreach to count them? Using this methodthe Report info is Total Columns is :0. I need to see how many columns and rows exists..
Try doing somthing like this....

Code: Select all

foreach (Ranorex.Cell cell in row.Cells)
{
Report.Info("Found cell: " + cell.Element.GetAttributeValue("AccessibleValue").ToString());
}
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...