Accessing DataGridView Cells via White
Asked Answered
O

1

7

So I'm doing some C# automation/UI testing with White and am having trouble with something. I have a DataGridView in the app and I set the background cell colors differently depending on application state. I want to check these colors during tests using White, but am having trouble doing so.

Here's what I'm trying to make work. I can get the grid view, but only as a table. Then, I have problems later on because I end up with plain TableCells instead of DataGridViewCells.

var Table = MainWindow.Window.Get<Table>("DataGridViewName");
var Row = Table.Rows[0];
var Cell = Row.Cells[0];
//invalid
//var Color = Cell.Style.BackColor;

Has anybody run into this before or have any suggestions?

Ostia answered 31/8, 2012 at 18:9 Comment(5)
Why cant You do it like this : MainWindow.Window.Get<DataGridView> ?Aspect
Hmmm, maybe I'm on an older version of white, but I can't find a white DataGridView component. Does that compile for you?Ostia
If the application is yours, you can enhance its UI Automation support/capabilities to have a better integration with White (which I believe uses UI Automation to do most of its job)Virginavirginal
Is mine. Certainly trying to do as you suggest, but having trouble getting it to work. The white documentation is too sparse : /Ostia
You can enhance your visibility to White, without knowing anything about it. Just add extra UI Automation capabilities to your program (see here for more: devx.com/dotnet/Article/21755/0/page/3) PS:don't forget to prepend your SO messages with the user's SO name otherwise we don't know you sent one.Virginavirginal
C
1

Are you sure backcolor is exposed through UI Automation? From the low-level UI Automation coding I've done, I have never seen such a property. I just opened Inspect (similar to UISpy) and pointed it at a DataGridView in a C# WinForms app, and no such property is exposed.

So since it doesn't seem to be exposed, there is no way to figure it out through automation, short of capturing an image and comparing it to some baseline with some threshold (sounds like a mess).

Unless you can somehow embed the information in some other automation property (which would require changing the app under test), I don't see any way to do it. :(

Compagnie answered 15/9, 2012 at 3:45 Comment(2)
Yeah, that's kind of the conclusion I came to as well. I ended up grabbing the visible image from the area defined by the element and looking at its actual pixels (basically as you suggested).Ostia
You can always write an AutomationPeer to read background peerRevolution

© 2022 - 2024 — McMap. All rights reserved.