Get background color for Ranorex.Cell objects

Ask general questions here.
symfony
Posts: 14
Joined: Tue Mar 11, 2014 9:19 am

Get background color for Ranorex.Cell objects

Post by symfony » Wed Sep 17, 2014 4:24 pm

Hello,

I have a DevExpress grid which contains some Ranorex.Row elements. Each Ranorex.Row contains some cells (Ranorex.Cell). I need to get the Background color for these cells. I am very surprised to realize that Ranorex.Cell does not provide any means to get the background color. Therefore, if anybody has a clue how to get the background color for a Cell object, please let me know. As this unexpected problem appeared close to the delivery deadline (as the problems always do :( ), I would greatly appreciate any quick hint or clue.


Thank you

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

Re: Get background color for Ranorex.Cell objects

Post by Support Team » Fri Sep 19, 2014 12:00 pm

Hi Symfony,

Is this a WPF DevExpress grid or a WPF one?
In case this is a WPF one please take a look at the following links: WPF custom properties on user controls and Best way to verify special characters, bold and italic text?.
There you find the information on how to identify the background color of a WPF control.

Regards,
Markus
.
Image

symfony
Posts: 14
Joined: Tue Mar 11, 2014 9:19 am

Re: Get background color for Ranorex.Cell objects

Post by symfony » Mon Sep 22, 2014 1:21 pm

Hello Markus,

Thank you for information. My grid is a WinForms DevExpress control: https://www.devexpress.com/Products/NET ... orms/Grid/ . We solved the problem by adding a special method to our AUT which returns the background color of a certain grid cell and call this method in our automated test cases. Nevertheless, It would be nice to be possible to retrieve the grid cell background color without modifying the AUT (which is not always possible unfortunately).

Best regards

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

Re: Get background color for Ranorex.Cell objects

Post by Support Team » Tue Sep 23, 2014 3:50 pm

Hi Symfony,

Thanks for letting us know that you found a solution :)!

It should normally be possible to get the background color of a standard WinForms control with Ranorex Spy without the need to modify the code of your application.
May I ask you to send me a Ranorex snapshot file of the control where you cannot identify the background color?
The following link will show you how to generate a snapshot file: Creating Ranorex Snapshot Files.

Thanks,
Markus
.
Image

symfony
Posts: 14
Joined: Tue Mar 11, 2014 9:19 am

Re: Get background color for Ranorex.Cell objects

Post by symfony » Wed Oct 01, 2014 12:53 pm

Hi Markus,

Thanks for reply. As I said before, I need to retrieve the background color for a Ranorex.Cell and not a Ranorex.Control object. Please provide a code snippet how to do this, as long as Ranorex.Cell does not provide a method similar with GetPropertyValue of the Ranorex.Control object.
I tried to convert Ranorex.Cell to Ranorex.Control or use the Element.GetAttributeValue() for the cell but without any luck :( .

Thank you

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

Re: Get background color for Ranorex.Cell objects

Post by Support Team » Fri Oct 03, 2014 2:44 pm

Hi Symfony,

I am afraid that there is nothing Ranorex can make to get the background color of your cell controls.
The problem is that the MSAA representation of such a WinForms cell doesn't provide the background color and therefore Ranorex can also not identify it.

In order to get the background color of a cell you can modify the accessible implementation for such cells or you could also use the InvokeRemotely method to inject code in your AUT.
I created a samll sample with a normal WinForms grid, this grid control can be used to access each cell and to get the background color of the same:
Ranorex.Table table = "/form[@controlname='Form1']/table[@controlname='dataGridView1']";
			
			Ranorex.Control myCtrl = (Ranorex.Control) table.Element;
			
			// Invoke Remotely
			string colorOfCell = (string)myCtrl.InvokeRemotely(	delegate(System.Windows.Forms.Control control, object input)
			    {
			                                   	System.Windows.Forms.DataGridView dataGrid = (System.Windows.Forms.DataGridView) control;
			                                   	
			                                   	// There you can access each cell:
			                                   	Color color = dataGrid.Rows[1].Cells[2].Style.BackColor;
			                                   	Console.WriteLine("Color: "+color);
			                                   	return color.ToString();
			     }
			     );
			
			Report.Info("Color of Cell: "+colorOfCell);
To get more information of the InvokeRemotely method please take a look at the following blog: Transfering data to and from a .NET control.
I hope this will help you to get a suitable solution!

Regards,
Markus
.
Image