How to map a NumberTextBlock item to a White UIItem

Feb 12, 2012 at 6:50 AM

I have an Item in the UI with its ClassName "NuMberTextBlock" it look like a regular TextBox but it contain number and it is not editable, I tried to acces it as a TextBox but that is not possible, I just need to be able to access it and read its value

Feb 13, 2012 at 9:50 AM

Hi

what is the ControlType? has the element an automationID?

you can get the element from the parent if UISpy or UIAVerify see it.

 

 

UIItem item = parent.Get<UIItem>(SearchCriteria.ByNativeProperty(AutomationElement.ClassNameProperty, "NuMberTextBlock"));

 

 

Throndorin

Feb 13, 2012 at 10:30 AM

thanks Throndorin, but if I access it as just a UIItem how I will be able to get the data from it??

I need to use somthing like:

Assert.AreEqual(numberTextBlock.Text, "12345");

Feb 14, 2012 at 7:59 AM

Hi if there is no no other control inside, and it is not ControlType.Edit. you had to implement a get text yourself.

 

Or does any other info contains the needed information (name for example). post all informations about the control UIAVerify shows. Which Pattern are implemented and so on.

 

Throndorin

Feb 14, 2012 at 11:20 AM

ok:

it has an AutomationId , ClassName is NmberTextBlock, CotrolType is ControlType.Custom, name es empty, Patterns are all empty.

and I didn't get you do you mean to write a get method for the class NumberTextBox in the source code of the program I am testing or what??

Feb 14, 2012 at 1:00 PM

no AutomationElements (Basics of UIAutomation) can implement patterns (scroll, text, select, and so on). UIItems of white gives you easy access to these patterns with for example Text of  labels.

ControlType.Custom means that the developer generates his own Control and if these control don't implement the needed patterns  for UIAutomation or inherit it from an other Control it is difficult to get access to information you need.

If the developer implement these patterns for Custom controls you had to implement your own method or property to get access to the information.

 

has the element childs in UIAverify?

 

Throndorin

 

 

Feb 15, 2012 at 7:04 AM

"no AutomationElements (Basics of UIAutomation) can implement patterns (scroll, text, select, and so on)" do you mean by this that they has to be implemented in the source code of the program I am testing?
how to implement them or inherit them???
then how to implement the get properaties and it is also in the source code of the program not part of the test code right???

and yes it has childs of controlType edit, class name TextBox, and they implement some paterns but have no Automation ID

 

 

 

Feb 16, 2012 at 7:14 AM

this that they has to be implemented in the source code of the program I am testing?

=> yes

how to implement them or inherit them???

if the Control for example inherits a TextBox it inherits all patterns from it

to implement AutomationPeer look here

 

in your case it is very easy :)

 

you have the control where ClassName is NmberTextBlock.

 

 

UIItem classNameIsNmberTextBlock = parent.Get<UIItem>(SearchCriteria.ByNativeProperty(AutomationElement.ClassNameProperty, "NuMberTextBlock"));

TextBox box = classNameIsNmberTextBlock.Get<TextBox>(SearchCriteria.ByControlType(ControlType.Edit));

Assert.AreEqual(box.Text, "12345");

 

 

Throndorin

 

Feb 19, 2012 at 6:51 AM

I tried this code but it produce to errors that:

the name "AutomationElement" does not exist in the current conext

the name "ControlType" does not exist in the current context

 

Feb 20, 2012 at 7:09 AM

Hi

it seems your project has not all references:

 

UIAutomationClient
UIAutomationTypes

UIAutomationClientsideProviders

UIAutomationProvider

 

Usages:

using System.Windows.Automation;

Feb 20, 2012 at 9:19 AM

Hi,

Where to find this dlls there are not exist in my machine from where can I download them?

and they are not part of the White project.

 

Feb 20, 2012 at 10:13 AM

Hi

 

the dlls are part of .Net and you can find them in the GAC (Global Assembly Cache). C:\Windows\Microsoft.NET\Framework\v4.0.30319\WPF you can find the dlls.

 

if you use Visual Studio: =>

 

Add Reference, select Assembly on the left side and select the dlls from the list.

 

Throndorin

Feb 20, 2012 at 11:19 AM
Edited Feb 20, 2012 at 11:26 AM

Thanks I add them now another error is produced the error is:

'White.Core.UIItems.UIItem' does not contain a definition for 'Get' and no extension method 'Get' accepting a first argument of type 'White.Core.UIItems.UIItem' could be found (are you missing a using directive or an assembly reference?)

 

the lines after I changed them a litile bit (I had to because I have many UIItems with the the same class name:

//UIItem temp = thisWindow.Get<UIItem>(SearchCriteria.ByNativeProperty(AutomationElement.ClassNameProperty, "NumberTextBox"));

 

UIItem temp = host.GetControl(thisWindow, "txtBalanceFrom"

);

txtBalanceFrom = temp.Get<

TextBox>(SearchCriteria.ByControlType(ControlType

.Edit));

 

 

 

 the second line I used instead of yours it just get the UIItem by it's Automation Id so it almost as the same as yours,

 the third line line is what producing the error above that the Get method is not in UIItem class, what to do?

 

 

 

Feb 22, 2012 at 12:22 PM

any help??

Feb 22, 2012 at 12:30 PM

Hi

you need

using White.Core.UIItems.WPFUIItems;


Throndorin
Feb 23, 2012 at 5:10 AM
Edited Feb 23, 2012 at 5:12 AM

Thanks, How do you know which Assemly or usinage I need?
the old error disappered but still I can't have a referrence to the control and it produces a null exception. 


Feb 23, 2012 at 6:45 AM

Hi

most is experience. And Visuals Studio with Resharper helps to find missing usages if the references exist.

can you post complete code here?

 

Throndorin

Feb 23, 2012 at 8:39 AM

this are the two lines:

UIItem temp = host.GetControl(thisWindow, "txtBalanceFrom");
TextBox txtBalanceFrom = temp.Get<TextBox>(SearchCriteria.ByControlType(ControlType.Edit));

 

Feb 24, 2012 at 6:50 AM

Hi

can you  try this:

UIItem temp = host.GetControl(thisWindow, "txtBalanceFrom");
AutomationElement txtBalanceFromAE = temp.GetElement(SearchCriteria.ByControlType(ControlType.Edit)); // gets the AutomationElement using white
TextBox txtBalanceFrom = new TextBox(txtBalanceFromAE, temp.ActionListener);


or
UIItem temp = host.GetControl(thisWindow, "txtBalanceFrom");
AutomationElement txtBalanceFromAE = temp.AutomationElement.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.ControlTypePropterty,ControlType.Edit); // gets the AutomationElement using UIAutomation
TextBox txtBalanceFrom = new TextBox(txtBalanceFromAE, temp.ActionListener);
Throndorin
Feb 26, 2012 at 5:06 AM

I need to be able to access it as a TextBox so I can access it, and use the same way with other controls so that I can not just access the text but also alter it.