jarmo / RAutomation

RAutomation
MIT License
100 stars 33 forks source link

MsUia::TextField - ControlType.Edit or ControlType.Document? #51

Closed leviwilson closed 11 years ago

leviwilson commented 11 years ago

I've been running into an issue where sometimes a multi-line System.Windows.Forms.TextBox will return UIA_DocumentControlTypeId (50030) vs UIA_EditControlTypeId (50004). In the MsUia::TextField class it has the following:

  def exist?
    super && matches_type?(Constants::UIA_EDIT_CONTROL_TYPE)
  end

I believe that this should also include Constants::UIA_DOCUMENT_CONTROL_TYPE (does not exist yet) as well. I would have added this, but I cannot for the life of me get the WindowsForms app that is used in the specs to return 50030 rather than 50004. I'm happy to add this to the test suite as long as you're cool with me not being able to reproduce a failing test. I am, however, seeing this in the app I'm working with. I cannot figure out the difference.

jarmo commented 11 years ago

Strange that you're getting it. Are you saying that you're getting it sometimes in your app, and not always? Even if trying to locate the same text field more than one time in the row? That's really strange behavior. Of course i'm not against having 100% test coverage (it's not probably 100% at the moment either), but if you can't create a test case for it and it will fix the issue you're having then we can make an exception :) Maybe at some later time you or someone else can figure it out just by accident.

leviwilson commented 11 years ago

Morally I would be averse to that, but I might make an exception :wink: I have a couple of idea that I am working on to see if I can reproduce it before then though. I do know that the method used to get the control type uses the straight COM API rather than going through the .NET framework. I will keep poking around though and let you know what I find.

leviwilson commented 11 years ago

Reproducing

I figured out what the difference is. As soon as you call something within RAutomation::Adapter::MsUia that causes it to load in the .NET framework (to go through the managed AutomationElement), the next time that MsUia::Control#get_current_control_type is called it returns 50030 rather than 50004.

Theory

My theory is that we get a separate COM interface the next time we go through getGlobalIUIAutomation we get a different COM interface for CUIAutomation (the one that the .NET framework has) and we get a different result.

The Fix

Two things. 1) I think that the 50030 result is the proper control type for a multi-line TextEdit control. It's what UiSpy reports as well. 2) I still need to play around with a fix for this. Ideally I think we need to be consistent about how we interface with UI Automation (either the C++ COM version or the .NET framework. The latter is more consistent). I will mull over what might be the best approach to fix this and see if I can come up with something. Let me know your thoughts.

leviwilson commented 11 years ago

Closing in lieu of pull #52