Automating 3rd party ComboBox

Class library usage, coding and language questions.
Munro89
Posts: 17
Joined: Thu Feb 18, 2010 10:06 pm

Automating 3rd party ComboBox

Post by Munro89 » Tue Aug 31, 2010 9:47 pm

Hello

We use in our application the Janus UI Controls suite. I can interact with most controls just fine. However, there are a few issues with the Combobox control. I can't see the number of items it has, neither the selected value.
I have found a workaround for the selected value using the Window text of the panel the control is in. It's not always working quite well.

I started this to get the properties : http://www.ranorex.com/blog/enabling-au ... s-controls.

I don't see how to get the number of items the ComboBox actually have. I have my value I want to return, but I don't know what method from the AccessibleObject ranorex is using to get this info.


Thanks in advance :)

User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Automating 3rd party ComboBox

Post by Ciege » Tue Aug 31, 2010 10:25 pm

You could probably use InvokeRemotely to use the methods of the control itself to return that information directly to you.
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

Munro89
Posts: 17
Joined: Thu Feb 18, 2010 10:06 pm

Re: Automating 3rd party ComboBox

Post by Munro89 » Wed Sep 01, 2010 1:21 pm

What I would like to do is use the ComboBox as if it was a standard Win32 combobox.

The Janus combobox currently doesn't have methods I can invoke remotely to select items, get list of items, etc. They're all properties. What I could probably do is creating a new control that is deriving from the Janus ComboBox and create methods for what I need. However, I would prefer to use the ComboBox directly with Mouse/Keyboard and see the properties from my automation project.

What is used to recognize standard ComboBoxes? I'm fairly sure I could do the same with a 3rd party..

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Automating 3rd party ComboBox

Post by Support Team » Wed Sep 01, 2010 1:51 pm

Hi,

We've tried the Janus Controls and it seems that their developers don't take much attention to implement accessibility to their controls. We observed that always an element named "a" will be generated where the accessible value for automation is nested. So the best way to automate their controls is to use the InvokeRemotely functionality (as proposed by ciege). To use the InvokeRemotely function correctly, please take a look to following post http://www.ranorex.com/forum/invokeremo ... t1002.html

Regards,
Peter
Ranorex Team

Munro89
Posts: 17
Joined: Thu Feb 18, 2010 10:06 pm

Re: Automating 3rd party ComboBox

Post by Munro89 » Wed Sep 01, 2010 3:02 pm

I will try the InvokeRemotely method. As I said, the methods of the Janus control will not return what I need. I'll need to create a few methods for what I want.

Can I create the custom implementation of the control in my automation solution and use InvokeRemotely with this custom implementation? That is assuming that the control is not the custom implementation in the application I test. That would simplify things for me.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Automating 3rd party ComboBox

Post by Support Team » Wed Sep 01, 2010 3:17 pm

Munro89 wrote:Can I create the custom implementation of the control in my automation solution and use InvokeRemotely with this custom implementation?
With InvokeRemotely you can just access the properties and return all the information you need. See the following blog and forum posts for more information:
http://www.ranorex.com/blog/transfering ... et-control
http://www.ranorex.com/forum/invokeremo ... t1002.html

Regards,
Alex
Ranorex Team

Munro89
Posts: 17
Joined: Thu Feb 18, 2010 10:06 pm

Re: Automating 3rd party ComboBox

Post by Munro89 » Wed Sep 01, 2010 4:44 pm

Everything seems to work using InvokeRemotely. It even works with delegates in my code, so I won't have to change the code for our product, which is a plus.

I had to do a custom implementation of the control to be able to cast it as a Ranorex.Control (from Ranorex.ComboBox).

For those who might need it, here's the code I used :
Custom implementation

Code: Select all

/// <summary>
    /// Janus combobox overrided for detection with Ranorex
    /// </summary>
    public class CustomUiComboBox : UIComboBox
    {
        protected override AccessibleObject CreateAccessibilityInstance()
        {
            return new AccessibleUiComboBox(this);
        }
    }


public class AccessibleUiComboBox : AccessibleObject
    {
        private CustomUiComboBox _comboBox;
        
        public override AccessibleRole Role
        {
            get
            {
                return AccessibleRole.ComboBox;
            }
        }
    }
I had a few more Accessibility overrides, but from what I understand it's the Role that allowed me to convert it as a Control.

Code: Select all

   
public static class ComboBoxTools
    {
        private static readonly RepoMainWindow Repo = RepoMainWindow.Instance;

        public static int GetNumberOfItems(RxPath cboPath)
        {
            var control = (Control)Repo.HOST.HOST.FindSingle(cboPath);
            var test = control.InvokeRemotely(GetNumberOfItemsDelegate);

            return (int) test;
        }

        public static object GetNumberOfItemsDelegate(System.Windows.Forms.Control control, object input)
        {
            return ((UIComboBox) control).Items.Count;
        }
    }

If only I knew earlier this was possible :( Back to refactoring!


Thanks a lot for the support (Both Ciege and the team).

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Automating 3rd party ComboBox

Post by Support Team » Wed Sep 01, 2010 5:11 pm

Munro89 wrote:I had a few more Accessibility overrides, but from what I understand it's the Role that allowed me to convert it as a Control.
Accessibility is not needed at all in order to use the Ranorex.Control adapter (and its InvokeRemotely method) for an element. The only requirement is that the element supports the Control capability (see this section in the Ranorex User Guide), i.e. it needs to actually correspond to a Windows Forms Control. In other words, as long as an RxPath points to a Windows Forms Control, you can create a Ranorex.Control adapter for the element got for the RxPath.

However, there are other advantages in implementing accessibility to your custom controls as outlined by this blog:
http://www.ranorex.com/blog/enabling-au ... s-controls

Regards,
Alex
Ranorex Team