(UIAElementArray) elements() is slow - ios-ui-automation

It takes 4 sec to execute. Is it normal?
I'm developing a search method, that crawls trough the element tree, but in each iteration when I call an element's elements() method, it holds for 4 sec. Having 15 nodes in the tree, it takes a minute!
Any idea on how to find an element?

Use the methods on UIATarget to decrease the default timeout (5 seconds), for example pushTimeout(0.5).

Related

Questions about implicit waits in Selenium Webdriver

I'm reading the docs on Implicit Waiting with Webdriver but I'm not sure I totally understand.
As I understand it,
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
This will put in place a timeout of 10 seconds whenever looking up any element.
What, exactly, does this do?
Does it mean that when looking up any element, I will wait 10 seconds every time, even if the element is present? Or, when looking up any element, will the driver give the browser a 10-second grace period to load the element before deciding the element missing?
Since this is applied to every element, am I correct in supposing that this is just executed only once for each instance of Webdriver?
This will look for the element up to 10 seconds, trying to locate it every 500 milliseconds (default timeout).
From the docs
Specifies the amount of time the driver should wait when searching for
an element if it is not immediately present.
When searching for a
single element, the driver should poll the page until the element has
been found, or this timeout expires before throwing a
NoSuchElementException. When searching for multiple elements, the
driver should poll the page until at least one element has been found
or this timeout has expired.
The locating algorithm is described in W3C specifications
The Find Element, Find Elements, Find Element From Element, and Find
Elements From Element commands allow lookup of individual elements and
collections of elements. Element retrieval searches are performed
using pre-order traversal of the document’s nodes that match the
provided selector’s expression. Elements are serialized and returned
as web elements.
When required to find with arguments start node, using and value, a
remote end must run the following steps:
Let end time be the current time plus the session implicit wait
timeout.
Let location strategy be equal to using.
Let selector be equal to value.
Let elements returned be the result of trying to call the relevant
element location strategy with arguments start node, and selector.
If a DOMException, SyntaxError, XPathException, or other error occurs
during the execution of the element location strategy, return error
invalid selector.
If elements returned is empty and the current time
is less than end time return to step 4. Otherwise, continue to the
next step.
Let result be an empty JSON List.
For each element in elements returned, append the serialization of
element to result.
Return success with data result.
implicitlyWait is defined once for the WebDriver and last its lifetime.
Defines a wait time globally in your project. Your telling your driver to wait for n number of seconds before selenium throws an exception. If element is found earlier then the n number of seconds you mentioned, webdriver will click it once its available and dont wait for the maximum n number of seconds. It does have to wait before it throws an exception.

What if my implicit wait is 10 secs and explicit wait is 5 secs, will it wait for 15 seconds in expected conditions

When i write some implicit wait like 10 sec and then for a element i give 5 seconds time in explicit wait...then will the implicit wait become zero and only wait for 5 sec or it will add the implicit wait time as well means will it wait for 15 secs
Let me answer you one by one:
Whenever you put an ImplicitlyWait Selenium will perform that wait after each action. So it becomes contagious.
When you put an Explicit Wait, those are defined as per certain conditions like "visibility of an element" within until block.
So each type of wait behaves in their own fashion just by the way you implement them.
Once you assign timeunits for each type of wait, they are followed in execution. They never gets added or substructed.
ImplicitlyWait is mentioned only once within​ your code. This instruction is for the Webdriver to follow. ImplicitlyWait have no effect on any element in particular.
Where as Explicit Wait is assigned to ask the Webdriver to wait for a defined time period (e.g. 5 seconds) with a until condition which specifies the state of an element (e.g. element_to_be_visible) the Webdriver should look for.
Now answering your question: 10 seconds ImplicitlyWait for a element is not a valid statement. Explicit Wait of 5 second you have to put for a certain state/behavior of the element (e.g. element_to_be_clickable). If the element doesn't shows that behavior within the defined time slot Selenium will throw an exception.
Let me know if this answers your question.

AddRange ObservableCollection Issue

Hi I'm using this link to implement Fastest Observable Collection
Best performance for ObservableCollection.AddRange
ObservableCollection Doesn't support AddRange method, so I get notified for each item added, besides what about INotifyCollectionChanging?
But on Calling AddRange() or ReplaceRange() methods multiple times, the performance gets slow, for example
AddRange() executed first time in 0.5 sec.
AddRange() executed 2nd Time in 1 sec.
AddRange() executed 3rd Time in 2.5 sec.
And it keep taking more time to execute methods even with same data.
For Better understanding, here is a code
For Each serie In SeriesList
serie.SeriesDisplayName = "New Series " + newSeriesCounter.ToString()
If newSeriesCounter = 1 Then
serie.Items(1).Number = 500
End If
newSeriesCounter += 1
Next
Series.Clear()
Series.AddRange(SeriesList)

Static timed loop in objective-c cocos2d?

Looking for some ideas on how to implement this, don't necessarily need the exact code.
Let's say I have a game where the player's hit points are displayed in a label, say 100HP. When he takes damage, say 30 damage, I want that label to count down from 99, 98 , 97 ... 70. It should take 2 seconds to perform the countdown whether you take 30 damage or 3000 damage.
I'm wondering what's the most efficient way to get this loop to count down "smoothly" over 2 seconds no matter what the damage taken is.
I'd probably extend a CCLabelSomething to do that, embedding the desired behaviour. Suggest a fixed width font, otherwise nothing smooth will happen (visually). Figure out what is 'smooth for you', ie how many updates in the 2 second period. in the assumed 'setScore' public method, start a scheduled update cycle with appropriate delay. In the schedule callback, change the text of the label.
say 20 updates, ie 10 per seconds. Schedule with .1f delay between intervals. Upon setScore, compute the 'delta' per update (currentScore - newScore)/20. Decrement currentScore down to newScore by this delta. In the schedule callBack, stop your scheduled update if the displayed score is equal to the newScore.

How to stop a function call if its take more than 3 secs in Object c

i have a function it will take 3 to 30 secs time for execution depends on some calculations.
i want to stop if my function call takes more than 5 secs.
how to do this in Objective C.
You have to execute command in a separate thread (with performSelectorInBackground or with NSThread, for example), wait for 5 seconds (again, with unix sleep or NSThread methods) and then (depending on what is being done in the execution thread):
set some field in a class to "terminate", and check this field often in a "long" function
cancel IO operation, if there is a block
cancel a thread (you can read about it here: how to stop nsthread)
You can use a timer and put a condition like if the timer exceeds 5 seconds, do nothing.