This project is read-only.
1
Vote

How to prevent "Cached:, Current:, ..." object data?

description

Hi

How to suppress these multiple outputs of object data?

When I run my UIA automation, for what seems like every control, I get this "paragraph" or "stanza" of object data for every object accessed. Here is an example:
Cached         : UIAutomation.UiElementInformation
Current        : UIAutomation.UiElementInformation
CachedParent   :
CachedChildren :
Descendants    : Castle.Proxies.UiExtendedModelHolderProxy
Children       : Castle.Proxies.UiExtendedModelHolderProxy
Control        : Castle.Proxies.UiControlInputHolderProxy
Mouse          : Castle.Proxies.UiMouseInputHolderProxy
Keyboard       : Castle.Proxies.UiKeyboardInputHolderProxy
__interceptors : {UIAutomation.MethodSelectorAspect, UIAutomation.ErrorHandling
                 Aspect}
This output might seem useful at times, but it's overload. Too much. How to prevent it? (Or at least turn on or off on demand? I couldn't find any
   __[UIAutomation.Preferences]::__
that seemed related to it.
I usually really want to only see my own output or "real" error messages.

Thanks
Joe

comments

apetrovskiy wrote Mar 11, 2014 at 8:44 PM

Hi Joe,
these outputs are not only verbose, they also consume time, as dotTrace (a .NET profiler) says.

I can make all of them optional, of course, however Current, Control, Mouse and Keyboard contain properties and methods that are useful. And blocking all of them by default is not good (I'm thinking about cutting their number in half by default).

There are already two flags that turn off the latest functionality:
1)
[UIAutomation.Preferences]::UseElementsSearchObjectModel = $false
hides Children and Descendants
2)
[UIAutomation.Preferences]::UseElementsPatternObjectModel = $false
hides Control, Keyboard, Mouse, and works as the first flag (hides Children and Descendants)
After the seconds flag being set to $false, output is as Microsoft's native.

Which style of coding do you use? Usually, there are three:
1) 'single commands'
Get-Window
Get-Button Next
Get-Edit
Get-Button OK | Invoke-UiaButtonClick
2) 'one-liners'
Get-UiaWindow | Get-UiaPane | Get-UiaButton | Invoke-UiaButtonClick
3) 'via object model'
$wnd = Get-UiaWindow
$wnd.Descendants.Buttons['OK'][0].Invoke()
($wnd | Get-UiaEdit 'aaa').Value = 'bbb'
In addition to parametrized hiding (that I could inplement even for every single property), there are also traditional ways to eliminate output. I know three:
$null = Get-UiaButton ... | Invoke-UiaButtonClick;
Get-UiaButton ... | Invoke-UiaButtonClick | Out-Null;
[void](Get-UiaButton ... | Invoke-UiaButtonClick);
If you want to turn off the whole output, some cmdlets (pattern cmdlets, for example) support the -PassThru:$false parameter.

In practice, I use cmds that run powershell:
cd c:\testfolder
powershell.exe -sta -noninteractive -executionpolicy bypass -command "& { ... some settings... a script to start tests.ps1; }" > c:\testfolder\regular_output.txt >> c:\testfolder\error_output.txt
My test engine creates a cmd for every host in the current test step with common and individual settings, and pushes cmds to hosts. All output (except logging) is in these two files per host per test step.

Regarding parameters to hide output, what's about such:
[UIAutomation.Preferences]::HideCurrent
[UIAutomation.Preferences]::HideCached
[UIAutomation.Preferences]::HideCachedParent
[UIAutomation.Preferences]::HideCachedChildren
[UIAutomation.Preferences]::HideControl # in parrallel with the existing flag
[UIAutomation.Preferences]::HideKeyboard # in parrallel with the existing flag
[UIAutomation.Preferences]::HideMouse # in parrallel with the existing flag
[UIAutomation.Preferences]::HideChildren # in parrallel with the existing flag
[UIAutomation.Preferences]::HideDescendands # in parrallel with the existing flag

joespr wrote Mar 11, 2014 at 10:40 PM

To answer your question, I generally use styles 2 and 3, one-liners and object-model. I haven't settled on any one method yet. Maybe I won't ever ;)

I agree that blocking their output by default is likely not a good idea. But now that you have detailed how to do it, I will turnoff until I need to troubleshoot.

Thanks
Joe