Forum Discussion
- rraghvaniChampion Level 3
Is there any reasons for not wanting to use Waiting for an Object, Process or Window Activation?
You can create a function that accepts an object, within the function have a while statement that checks the state of the object. You can also include a time out period too.
There's also a few examples on the forum.
- ashutosh01Contributor
to many places i had to put wait so looking for custom function.
- tristaanogreEsteemed Contributor
You're still going to have to put that custom function in just as many places.
- tristaanogreEsteemed Contributor
Not being very familiar with Selenium, what do you mean by "different waits"? Waits for what?
In TestComplete there are a variety of ways of waiting for an object, page, component, etc., all built in to the various parts of the tool. If you can describe a bit more as to what you're looking for in the way of examples, scenarios, someone can probably give you at least a start f what you're looking for. Most likely, such a thing will utilize one or more of those existing waits in TestComplete.- ashutosh01Contributor
I am looking to put dynamic wait in multiple places until an object is let's say visible or enabled to perform actions.
Suppose wait time is 10sec but if object loaded in 3sec then it will move on not wait further 7 sec
and I want to have a custom function where I just pass the object and time, then call this function from wherever i needed for whichever object.
- tristaanogreEsteemed Contributor
Almost all the built in Wait functions that rraghvani linked to already do that. WaitAliasChild, WaitChild, WaitProcess, etc, all operate as a "timeout" where you set a value (10 seconds in your example) but it only waits as long as necessary.
I'd start looking there, rather than building an extra custom function.
- rraghvaniChampion Level 3
If in your scipt, you want to wait for 10 objects to appear, then you'll use one of appropriate WaitNNN Methods, 10 times for each object.
Or you could spend time, writing your own custom function, then call it 10 times for each object.
- eykxasRegular Contributor
I have created this kind of method. I've called it "fluentWait". (I use javascript)
this method wait dynamically for an object to be exists in the object tree. (100ms interval, up to 10sec)
function fluentWait(){ let stopTime = GetTickCount() + 10000; //wait 10s at max do { var obj = Aliases.your.main.container.WaitNamedChild(MappedChildName, 100); } while(! obj.Exists && GetTickCount() < stopTime); }
- tristaanogreEsteemed Contributor
That works. However, two things:
1) I'd make the stop time be calculated based upon an input parameter. Instead of hardcoding 10 seconds, make that the input parameter for the user to enter the number of milliseconds to wait.2) MappedChildName needs to be an input parameter as well. Somehow, you need to indicate the name that you want to wait for.
3) The problem is that the named child, in the indicated code, must be an immediate child of the your.main.container object. What if it's not? Somehow you need to indicate the parent that you want to search under
4) WaitNamedChild cannot take alias names, only mapped names. If you want to search based upon Alias, you should use WaitAliasChild but then, again, you need to designate the parent.
Here's how I'd re-write it:function fluentWait(parentObject, childName, waitTime){ let stopTime = GetTickCount() + waitTime; //wait 10s at max do { var obj = parentObject.WaitAliasChild(childName, 100); } while(! obj.Exists && GetTickCount() < stopTime); }
- rraghvaniChampion Level 3
Using WaitNamedChild Method achieves the same - "Use the WaitNamedChild method to delay the test execution until the specified mapped child object appears in the child list of the given mapped object or the specified time limit is reached". I.e.
Aliases.your.main.container.WaitNamedChild(MappedChildName, 10000);
- eykxasRegular Contributor
But you have no control on the timing interval (only timeout), and you can't use as is in keyword test.
- eykxasRegular Contributor
My real method is not like this. I tried here to simplify it. (I haven't tested this code)
my real fluentWait call two others method, "waitPageFullyLoaded" and "waitSpinner". Both use the tick count loop, but with an object via xpath not mapped name. (my entire project use xpath).
Related Content
Recent Discussions
- 3 days ago