How to wait for Windows to disappear or get active

Class library usage, coding and language questions.
gkring
Posts: 5
Joined: Tue Sep 04, 2007 4:06 pm

How to wait for Windows to disappear or get active

Post by gkring » Tue Sep 04, 2007 5:45 pm

I want to use Ranorex Python to automate testing of E-Mail clients.
I am starting with Outlook Express.
One important point for this seems to be a method to wait for windows to disappear (e.g. if I send an E-Mail I have to wait until the Message window goes away...)
I tried to use the ControlGetState() API for this, but this seems not to work
correctly. Although I can see that the 'New Message' Window is still there,
the state for this seems to be 'CONTROL_UNAVAILABLE'.
Here is the code snippet for this:

Code: Select all

className = 'ATH_Note'
self.messageForm = Ranorex.FormFindClassName(className)
if self.messageForm == 0:
    raise RanorexError, 'New message Form not found'
#Fill some fields in message form
#Press Send button
#In our test case message will not be sent yet 
#  e.g.because of errors
for i in range(NUMBER_OF_RETRIES):
    Ranorex.Sleep(100)    
    messageState = Ranorex.ControlGetState(self.messageForm)
    print 'state:' + hex(messageState)
    if messageState & Ranorex.CONTROL_UNAVAILABLE:
         print 'message Form unavailable'
    else:
         print 'message Form still existing'
The output is:
state:-0x1
message Form unavailable
repeatedly...

In what cases will the state be -1?


Are there any known issues with this or how would you check for the existence or non existence of Controls/Windows which existed before?

I have tried AutoIt before, which had some 'waitXXX' functions.
But I like the Ranorex strategy of not inventing an own scripting language,
but using a powerful existing one like Python much more...

admin
Site Admin
Site Admin
Posts: 350
Joined: Wed Jul 05, 2006 7:44 pm

Post by admin » Tue Sep 04, 2007 7:40 pm

It seems to be a problem with ControlGetState() if the control is a top level window.
Please use the function with a child control of the form:

Code: Select all

button=Ranorex.FormFindChildControlName(form,'button1')
for i in range(NUMBER_OF_RETRIES): 
    Ranorex.Sleep(100)    
    messageState = Ranorex.ControlGetState(button) 
    print 'state:' + hex(messageState) 
    if messageState & Ranorex.CONTROL_UNAVAILABLE: 
         print 'message Form unavailable' 
    else: 
         print 'message Form still existing'
or use the position property of the form:

Code: Select all

for i in range(NUMBER_OF_RETRIES): 
    Ranorex.Sleep(100)    
    location = Ranorex.ControlGetPosition(form)
    if location == None: 
         print 'message Form unavailable' 
    else: 
         print 'message Form still existing'
Jenö
Ranorex Team

gkring
Posts: 5
Joined: Tue Sep 04, 2007 4:06 pm

Post by gkring » Wed Sep 05, 2007 9:17 am

Thank you!
I have tried it with your 2nd proposal and this works.