Ask a Question

WaitWindow with Python

SOLVED
IuliaVascan
Occasional Contributor

WaitWindow with Python

Hi,

 

I want the script (python) to wait for a task manager window to close before to go further. I think to use a waitwindow method, but I don't know why it says after running that, also the object is mapped.

"Python runtime error.

RuntimeError: The specified object is not callable."

 

so far the script is this:

 

def Test1():
   TestedApps.ECU_TEST.Run()
   TestedApps.ECU_TEST.Run(1, True)
   ecu_test = Aliases.ECU_TEST2
   ecu_test.dlgECUTEST20204.btnOk.ClickButton()
   ecu_test.dlgTaskManager.Click(242, 19)

   p = Aliases.ECU_TEST2.dlgTaskManager()
   while p.WaitWindow('#32770','Task Manager','-1',5000).Exist:
       pass

 

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
AlexKaras
Community Hero

Re: WaitWindow with Python

Hi,

 

This appears random, in 1-2 sec after the workspace is set.

Probably the main problem with windows like this is that they appear at non-predictable moment of time and it may take unpredictable time to close. I.e., depending on a bunch of different factors like network, memory and CPU performance, volume of work to be done, etc. the window may open, say, within 1-10 seconds time frame from the moment of initial workspace initialization. Depending on the volume of work to be done the window may close almost immediately or remain visible on the desktop for some time. Additionally, the window may not appear at all if the volume of work is too small or is absent.

On the other hand, it takes some noticeable time for TestComplete to detect the new window and to process it.

All the above leads to a problem that if the window was not detected within, for example 1 second, you can not be sure whether this is because all the work was done and the window will not be displayed or you need to wait more because of, say, congested network or overloaded CPU.

 

The best strategy for the situation like this depends on your goal: whether you need to interact with such window or need just to postpone test execution until the window is closed.

 

Probably the best option is if you can talk to developers and they add some property to the main application window that is set to false initially and to true after the window was closed. In this case you will be able reliably wait until the window is closed without spending extra time by just waiting in a loop until this property becomes true.

Check https://support.smartbear.com/testcomplete/docs/app-testing/open-apps/unavailable-members.html help topic if the above is an option.

 

If you need to interact with the window then you should use one of the WaitXXX methods. WaitWindow() or WaitAliasChild(). Use of Aliases is a good practice in TestComplete world but be aware and remember about caching: https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/common-for-all/refres.... Regardless of whether you are using .WaitWindow() or .WaitAliasChild(), you need to work with the window itself, but not with some of its child UI elements. Considering the code that you provided, this is the window with class name '#32770' and 'Task Manager' caption. But you may ask developers to be on the safe side.

In any case, remember, that if window may not appear or appears for too short period of time (consult with developers as for this) then you must consider some timeout in order to prevent endless wait. Selection of timeout is the major tradeoff here - you must wait long enough to let window appear and be detected by TestComplete, but not too long in order not to waste time on wait when it becomes evident that the window (most probably) will not appear.

 

If the window we are talking about is of modal type you may consider to use the OnUnexpectedWindow event provided by TestComplete (https://support.smartbear.com/testcomplete/docs/reference/events/onunexpectedwindow.html). In the case of using events, you should not wait for the window but just proceed with test flow. If the event is triggered, then you should check if the event was triggered by the window you are interested in (Task Manager) and either wait until it closes or interact with it if needed.

 

P.S. I understand that all the above might look too abstract for the one who just started to use TestComplete. Feel free to ask here if something is not clear enough.

 

P.P.S. May 26 SmartBear holds TestComplete Introductory Training (https://smartbear.zoom.us/webinar/register/8616153693294/WN_gwJbYsBcQU2HNC_8_iWQjw) which might appear to be useful.

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================

View solution in original post

3 REPLIES 3
AlexKaras
Community Hero

Re: WaitWindow with Python

Hi,

 

It is my guess that the error is thrown on this line:

while p.WaitWindow('#32770','Task Manager','-1',5000).Exist:

isn't it?

 

If my guess is correct, then does

Aliases.ECU_TEST2.dlgTaskManager()

object exist at this moment?

If it does not, then obviously you cannot call .WaitWindow() method of the object that does not exist.

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
IuliaVascan
Occasional Contributor

Re: WaitWindow with Python

@AlexKaras 

First of all thank you,

 

Well the object doesn't exists at that moment.

For a big picture, I'm trying to open a tool, choose the workspace and after that a task manager window appears. And I am trying to make the script to wait for that window to appear and wait until this window is closing. Is about a few seconds, I can use a Delay but I need this kind of function (I don't know which is the correct term) also in the near future, when the tool opens another tools and I want to wait for them to be open and then close after a period of time when their jobs are finished. 

 

I attached the task manager window. This appears random, in 1-2 sec after the workspace is set. It's uploading some stuff than is closing (all by itself). I want to specify that the picture is changing, I don't know if it's mapped like the first picture after is changing in second the script will recognize the object? Sorry for all of this newbie stuff, but it's my first week with this tool. 

Again Thank you!

AlexKaras
Community Hero

Re: WaitWindow with Python

Hi,

 

This appears random, in 1-2 sec after the workspace is set.

Probably the main problem with windows like this is that they appear at non-predictable moment of time and it may take unpredictable time to close. I.e., depending on a bunch of different factors like network, memory and CPU performance, volume of work to be done, etc. the window may open, say, within 1-10 seconds time frame from the moment of initial workspace initialization. Depending on the volume of work to be done the window may close almost immediately or remain visible on the desktop for some time. Additionally, the window may not appear at all if the volume of work is too small or is absent.

On the other hand, it takes some noticeable time for TestComplete to detect the new window and to process it.

All the above leads to a problem that if the window was not detected within, for example 1 second, you can not be sure whether this is because all the work was done and the window will not be displayed or you need to wait more because of, say, congested network or overloaded CPU.

 

The best strategy for the situation like this depends on your goal: whether you need to interact with such window or need just to postpone test execution until the window is closed.

 

Probably the best option is if you can talk to developers and they add some property to the main application window that is set to false initially and to true after the window was closed. In this case you will be able reliably wait until the window is closed without spending extra time by just waiting in a loop until this property becomes true.

Check https://support.smartbear.com/testcomplete/docs/app-testing/open-apps/unavailable-members.html help topic if the above is an option.

 

If you need to interact with the window then you should use one of the WaitXXX methods. WaitWindow() or WaitAliasChild(). Use of Aliases is a good practice in TestComplete world but be aware and remember about caching: https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/common-for-all/refres.... Regardless of whether you are using .WaitWindow() or .WaitAliasChild(), you need to work with the window itself, but not with some of its child UI elements. Considering the code that you provided, this is the window with class name '#32770' and 'Task Manager' caption. But you may ask developers to be on the safe side.

In any case, remember, that if window may not appear or appears for too short period of time (consult with developers as for this) then you must consider some timeout in order to prevent endless wait. Selection of timeout is the major tradeoff here - you must wait long enough to let window appear and be detected by TestComplete, but not too long in order not to waste time on wait when it becomes evident that the window (most probably) will not appear.

 

If the window we are talking about is of modal type you may consider to use the OnUnexpectedWindow event provided by TestComplete (https://support.smartbear.com/testcomplete/docs/reference/events/onunexpectedwindow.html). In the case of using events, you should not wait for the window but just proceed with test flow. If the event is triggered, then you should check if the event was triggered by the window you are interested in (Task Manager) and either wait until it closes or interact with it if needed.

 

P.S. I understand that all the above might look too abstract for the one who just started to use TestComplete. Feel free to ask here if something is not clear enough.

 

P.P.S. May 26 SmartBear holds TestComplete Introductory Training (https://smartbear.zoom.us/webinar/register/8616153693294/WN_gwJbYsBcQU2HNC_8_iWQjw) which might appear to be useful.

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================

View solution in original post

cancel
Showing results for 
Search instead for 
Did you mean: