Page 1 of 1

ToolBarSendCommand doesn't return when command opens dialog

Posted: Fri Nov 16, 2007 5:45 pm
by domperez
When I use ToolBarSendCommand for a command that will cause a new dialog to open, the dialog opens as expected but the method does not return until I manually close the dialog. After I manually close the dialog it will return 0.

I would guess that Ranorex is waiting on something before returning, but what and is there a way to bypass this check?

Thanks,
-Dom

Posted: Fri Nov 16, 2007 7:15 pm
by Support Team
Can you please try the following code with wordpad:

Code: Select all

__version__ = 1, 0, 0

import sys, optparse, imp

# RanorexPython will be loaded dynamically from Ranorex\Bin\Net2.0
# sys.path[0] is the directory containing this script (Ranorex\Scripts)
# Please copy the correct RanorexPython version into the Ranorex\Bin\Net2.0
# directory if you use another Python version than Python2.4
index = sys.path[0].rfind('\\')
RANOREX_BINPATH = sys.path[0][0:index] + '\\Bin\\Net2.0-Pro\\'
print RANOREX_BINPATH
Ranorex = imp.load_dynamic('RanorexPython', RANOREX_BINPATH + 'RanorexPython.dll')

TESTED_APPLICATION = 'Wordpad.exe'
TESTED_APPLICATION_TITLE = 'Document - WordPad'

def printerror(*args):
    msg = ' '.join(args)
    sys.stderr.write(msg)
    sys.stderr.write("\n")

def main():
    sleeptime = 10
    application = TESTED_APPLICATION   

    print '---------------------------------------------------------------------'
    print ' Activating Form: ' + TESTED_APPLICATION_TITLE
    print '---------------------------------------------------------------------'
    form = Ranorex.FormFindTitle(TESTED_APPLICATION_TITLE)
    if form == 0:
        print '   Form not found, starting application...' + application
        ret=Ranorex.ApplicationStart("C:\\Program Files\\Windows NT\\Accessories\\wordpad.exe")
        if ret != 0:
            print '\nERROR: Cannot start application: ' + application
            return 3
        print '   Activating test application...'
        form=Ranorex.FormFindTitle(TESTED_APPLICATION_TITLE,Ranorex.MATCH_EXACT,1,5000)
        if form == 0:
            print 'Error: Form not found'        
            return 4
    print '   Form found, form=' + hex(form)

    print '--------------------------------------------------------------------'
    print ' Searching and testing a toolbar'
    print '---------------------------------------------------------------------'
    print '   searching tool bar by control id'
    toolbar=Ranorex.FormFindChildControlId(form, 59392)
    if toolbar == 0:
        print 'ERROR: toolbar not found'
        return 5
    print '      toolbar=' + hex(toolbar)

    print '   moving the mouse to the control'
    Ranorex.MouseMoveToControl(toolbar)

    itemCount = Ranorex.ToolBarGetItemCount(toolbar)

    print '  ItemCount=' + str(itemCount)
    for i in range(itemCount):
        commandId = Ranorex.ToolBarGetItemCommandId(toolbar, i);
        print '    commandId= ' + str(commandId)

    if Ranorex.ToolBarClickItem(toolbar, 57603) != 0:
        print 'ERROR: clicking toolbar item'
        return 5

    # Dialog open needs a little bit time
    Ranorex.Sleep(1000)
            
    saveas = Ranorex.FormFindTitle("Save As")
    if saveas == 0:
        print 'ERROR: cannot find save as dialog'
        return 6

    cancel = Ranorex.FormFindChildText(saveas, 'Cancel')
    if cancel != 0:
        Ranorex.MouseClickControl(cancel)     

    Ranorex.Sleep(2000)
    print '--------------------------------------------------------------------'
    print ' Closing application: ' + TESTED_APPLICATION_TITLE
    print '---------------------------------------------------------------------'
    Ranorex.FormClose(form)
    print 'End'
    return 0

if __name__ == "__main__":
    ret = main()
    sys.exit(ret)
Does this work for you?

Jenö
Ranorex Support Team

Posted: Fri Nov 16, 2007 8:31 pm
by domperez
No, that doesn't work for me.

The reason I want to use ToolBarSendCommand is the the command I want to send is hidden in a menu. I've tried clicking the parent menu item and then the item I want but the menu that opens is no longer part of the toolbar. For toolbar items that are visible I can use ToolBarClickItem and it works fine.

Thanks,
-Dom

Code: Select all

H:\>wordpad.py
C:\Program Files\Ranorex 1.3\Bin\Python2.5\
---------------------------------------------------------------------
 Activating Form: Document - WordPad
---------------------------------------------------------------------
   Form not found, starting application...Wordpad.exe
   Activating test application...
   Form found, form=0x8070c
--------------------------------------------------------------------
 Searching and testing a toolbar
---------------------------------------------------------------------
   searching tool bar by control id
      toolbar=0x70706
   moving the mouse to the control
  ItemCount=15
    commandId= 57600
    commandId= 57601
    commandId= 57603
    commandId= 0
    commandId= 57608
    commandId= 57609
    commandId= 0
    commandId= 57636
    commandId= 0
    commandId= 57635
    commandId= 57634
    commandId= 57637
    commandId= 57643
    commandId= 0
    commandId= 32778
ERROR: cannot find save as dialog

Posted: Sat Nov 17, 2007 12:22 am
by Support Team
I've tried clicking the parent menu item and then the item I want but the menu that opens is no longer part of the toolbar.
Yes, that's right it's normally a popup menu.
Please check the class name of this popup menu with RanorexSpy (you should enable the HotTracker).
If it's #32768 (like in Wordpad if you open the color popup) then you can use the function PopupMenuSelectItem() for selecting an item in the popup menu.

Jenö
Ranorex Support Team