Janus GridEX cell recognition

Class library usage, coding and language questions.
bsing
Posts: 81
Joined: Tue Feb 07, 2012 5:25 am

Janus GridEX cell recognition

Post by bsing » Thu Mar 08, 2012 12:02 am

Hi,

Our company uses Janus.Windows.GridEX.v3 sporadically throughout its code. However using Ranorex Spy will not detect the cells in the grid.

How can I retrieve the text from a single cell from this GridEX control??

Attached is a snapshot of an example of where we use GridEX control.
Attachments
JanusGridEX.rxsnp
(263.41 KiB) Downloaded 409 times

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

Re: Janus GridEX cell recognition

Post by Support Team » Thu Mar 08, 2012 11:47 am

Hi,

Thanks for the snapshot!
It seems that this container is one of your custom classes, because the type is "Tsd.IncManagement.Workstation.SIMS.Common.UtcGridEx".
Does it derive from a Janus control? Please send us some more information about the specific control.
Aren't you able to identify anything in the specific container? Would it be possible to send us a Ranorex Snapshot file of the entire application?

Regards,
Markus
Ranorex Support Team
.
Image

bsing
Posts: 81
Joined: Tue Feb 07, 2012 5:25 am

Re: Janus GridEX cell recognition

Post by bsing » Thu Mar 08, 2012 11:38 pm

Hi Markus,

Thanks for looking at this.

To answer your questions ... yes "UtcGridEx" derives from "Janus.Windows.GridEX.GridEX".

No I am not able to see anything in this specific container (cannot see rows or cells)

Have attached snapshot of the whole application.

Thanks

Brad.
Attachments
appSnapshot.rxsnp
(155.37 KiB) Downloaded 280 times

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

Re: Janus GridEX cell recognition

Post by Support Team » Fri Mar 09, 2012 3:28 pm

Hi Brad,

The specific grid element is based on WinForms and WinForms uses Microsoft Active Accessibility (MSAA) to create accessible code, so you can check with the AccExplorer/UISpy (the MSAA Accesibility Explorer) if the MSAA implementation is correctly working, just check if the tool is able to identify the specific elements in your grid.
If it is able to identify the elements within the container, it seems that there is a problem with Ranorex, if it is not able it seems that the implementation of MSAA is not correct and
therefore has to be re-implemented. There is also a useful blog about this topic:
http://www.ranorex.com/blog/enabling-au ... s-controls
It is also possible to invoke specific methods of a control, maybe you can create a methods which returns specific elements, but you have to consider that the elements have to be serializable.


Regards,
Markus
Ranorex Support Team
.
Image

bsing
Posts: 81
Joined: Tue Feb 07, 2012 5:25 am

Re: Janus GridEX cell recognition

Post by bsing » Mon Mar 12, 2012 6:37 am

Hi Markus,

I have tried your latter suggestion of using remote invocation.

My code I have attempted is as follows:

Code: Select all

public void CheckData()
        {      	   	
        	
			Ranorex.Control gridcontrol = "/form[@controlname='frmMain']/container[@controlname='cwtcMain']/container[@controlname='TrafficIncidentMainControl']/element/container[@controlname='explNotifications']/container/container/container[@controlname='grxEvents']";
			SOutputData[] outputData = (SOutputData[]) gridcontrol.InvokeRemotely(delegate(System.Windows.Forms.Control control, object input)
			{
				Janus.Windows.GridEX.GridEX currGrid = (Janus.Windows.GridEX.GridEX) control;
				    	
	    		List<SOutputData> remoteOutputData = new List<SOutputData>();   
		
				foreach (GridEXRow currRow in currGrid.GetRows())
				{
					int counter = 0;
					SOutputData data = new SOutputData();
					data.cellText = (string) currRow.Cells[counter].Value;
					remoteOutputData.Add(data);
					
					
					counter++;
					
				}
			
				return remoteOutputData.ToArray();
			
			});
			
			
			
        }
        
        [Serializable]
        private class SOutputData
        {
        	public string cellText;
        }
I am gettting the following error: "Action 'invokeremotely' failed on element '{Container: grxEvents}'. Unable to cast object of type 'System.Int32' to type 'System.String'.

Can you offer any suggestion?

bsing
Posts: 81
Joined: Tue Feb 07, 2012 5:25 am

Re: Janus GridEX cell recognition

Post by bsing » Mon Mar 12, 2012 7:39 am

I also installed UISpy and could only find the control pane for GridEX Control, but there was no structure under it. (eg. no rows or cells)

Also ... how do you re-implement MSAA?

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

Re: Janus GridEX cell recognition

Post by Support Team » Mon Mar 12, 2012 11:44 am

Hi,
bsing wrote:Also ... how do you re-implement MSAA?
To support accessibility of your control, please take a look to following post
http://www.ranorex.com/blog/enabling-au ... s-controls

Regards,
Peter
Ranorex Team
.
Image

bsing
Posts: 81
Joined: Tue Feb 07, 2012 5:25 am

Re: Janus GridEX cell recognition

Post by bsing » Mon Mar 12, 2012 11:34 pm

Can someone look at the code I posted, to see why it doesn't work?? I don't really understand the MSAA stuff.

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

Re: Janus GridEX cell recognition

Post by Support Team » Tue Mar 13, 2012 2:19 pm

Hi,

It is not so easy to point you in the right direction without knowledge of your system, but try to use this code instead of yours:
use:
data.cellText = currRow.Cells[counter].Value.toString();
instead of:
data.cellText = (string) currRow.Cells[counter].Value;
Does this solve the problem?
Maybe your developers can help you with the implementation of accessibility?

Regards,
Markus
Ranorex Support Team
.
Image

bsing
Posts: 81
Joined: Tue Feb 07, 2012 5:25 am

Re: Janus GridEX cell recognition

Post by bsing » Wed Mar 14, 2012 5:06 am

Thanks Markus, yes it solves that error message.

My code now looks like this

Code: Select all

        [Serializable]
        private class SOutputData
        {
        	public string cellText;
        }
           
        
        public void CheckData()
        {      	   	
        	
			Ranorex.Control gridcontrol = "/form[@controlname='frmMain']/container[@controlname='cwtcMain']/container[@controlname='TrafficIncidentMainControl']/element/container[@controlname='explNotifications']/container/container/container[@controlname='grxEvents']";
			
			SOutputData[] outputData = (SOutputData[]) gridcontrol.InvokeRemotely(delegate(System.Windows.Forms.Control control, object input)
			{
				Janus.Windows.GridEX.GridEX currGrid = (Janus.Windows.GridEX.GridEX) control;
				    	
	    		List<SOutputData> remoteOutputData = new List<SOutputData>();   
		
				foreach (GridEXRow currRow in currGrid.GetRows())
				{
					for (int counter = 0; counter < currRow.Cells.Count; counter++)
					{
						SOutputData data = new SOutputData();
						data.cellText = currRow.Cells[counter].Value.ToString();
						Report.Info("test", data.cellText);
						remoteOutputData.Add(data);
					}
				}
			
				return remoteOutputData.ToArray();
			
			});
				
			
        }
Now I am getting error message "Action 'invokeremotely' failed on element '{Container.grxEvents}'. Object reference not set to an instance of an object."

I have tried to debug this but Ranorex will not step through the delegate. Do you have any suggestions which will fix the object instance error?

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

Re: Janus GridEX cell recognition

Post by Support Team » Thu Mar 15, 2012 2:40 pm

Hi,

You're welcome!

It is very hard for us to find the error without knowledge of your Control, so would it be possible that you send us a small sample application which includes that control and some test data?
This would help us solving the issue.
You can also send it to [email protected].

Regards,
Markus
Ranorex Support Team
.
Image

bsing
Posts: 81
Joined: Tue Feb 07, 2012 5:25 am

Re: Janus GridEX cell recognition

Post by bsing » Mon Mar 26, 2012 12:24 am

Hi Markus,

I would prefer not to send an application ... you could just get a trial version of the control.


Cheers,

Brad.

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

Re: Janus GridEX cell recognition

Post by Support Team » Wed Mar 28, 2012 12:40 pm

Hello

I just downloaded the trial Version from Janus GridEx and worked with GridExTutorial1.
Ranorex is able to spy all cell data perfectly.
It seems that your derived version from Janus GridEx does not care about Accessibility (MSAA).
The recommended way is to implement Accessibility functionality as described in the article (cited more times above).

Using the workaround to retrieve the cell contents with the use of InvokeRemotely-Function within Ranorex does work as well. Your code snippet was quite correct with the exception of your Ranorex-Report-Call within the Invoke-Remotely-Call. It is not possible to access the Report-Method within the Remote Call !

Please have a look at my example, where I extended your code snippet with Data-Type-Definition:

Extend your uses-clause

Code: Select all

using Janus.Windows.GridEX;
using Janus.Windows.Common;
Serializable Output-Data with Type-Definition

Code: Select all

[Serializable]
[Serializable]
private class SOutputData
{
	public ColumnType ColType;
	public string cellString;
	public bool cellBool;
}
Invoke-Remotely

Code: Select all

// Create Control Adapter
Control tableGridEX1 = "/form[@controlname='Form1']/container[@controlname='gridEX1']";
// Invoke Remotely
SOutputData[] outputData = (SOutputData[])  tableGridEX1.InvokeRemotely (delegate(System.Windows.Forms.Control control, object input)
{
        // Get Grid Access
        Janus.Windows.GridEX.GridEX currGrid = (Janus.Windows.GridEX.GridEX) control;
        List<SOutputData> remoteOutputData = new List<SOutputData>();   
  		// Iterate through Rows and Cells
        foreach (GridEXRow currRow in currGrid.GetRows())
        {
           for (int counter = 0; counter < currRow.Cells.Count; counter++)
           {
              SOutputData data = new SOutputData();
              // Specify Data-Type of Cell
              data.ColType = currRow.Cells[counter].CellDisplayType;
			  // Save Value DataTypeSpecific
              switch (data.ColType){
              		case ColumnType.CheckBox : data.cellBool = (bool)currRow.Cells[counter].Value; break;
              		case ColumnType.Text : data.cellString = currRow.Cells[counter].Text; break;
              		default: break;
              }
              remoteOutputData.Add(data); // AddToList
           }
        }
        return remoteOutputData.ToArray(); // Return Data
});
Handle the output-data

Code: Select all

// Handle output
foreach (SOutputData MyOutPut in outputData){
	switch (MyOutPut.ColType){
			case ColumnType.Text: Report.Info("TextValue: " + MyOutPut.cellString); break;
			case ColumnType.CheckBox: Report.Info("BoolValue: " + MyOutPut.cellBool.ToString());  break;
			default: break;
			}
}
Hope that helps !

Regards
Roland (E),
Ranorex Support Team
.
Image

bsing
Posts: 81
Joined: Tue Feb 07, 2012 5:25 am

Re: Janus GridEX cell recognition

Post by bsing » Fri Mar 30, 2012 12:45 am

Thanks Roland ... this is brilliant!

The only changes I had to make to your code to get it working was:

Code: Select all

Control tableGridEX1 .. changed to Ranorex.Control
and

Code: Select all

data.ColType = currRow.Cells[counter].CellDisplayType; ... changed to data.ColType = currRow.Cells[counter].Column.ColumnType;
Thanks heaps

Brad.