Optimize speed by freezing UI

This section introduces one of the way to speed up your test script only in complicate situations. For simple selection and operations, you need not to do this optimization at all.

Freezing UI is just to dump the UI hierarchy and store it locally. With current hierarchy data, the position of UIs can be retrieved directly without communicating with game/app which is slow if multiple visits. The only one disadvantage of freezing UI is that the hierarchy data cannot stay in sync with game/app automatically. So you should handle your UI state carefully otherwise you may get wired test results.

Note

In some poco-sdk implementations, freezing and not freezing UI are equivalent. See poco engine specification for more details.

The following 2 examples shows the difference between freezing and not freezing UI.

Freezing UI

import time
from poco.drivers.unity3d import UnityPoco

poco = UnityPoco()
with poco.freeze() as frozen_poco:
    t0 = time.time()
    for item in frozen_poco('Scroll View').offspring(type='Text'):
        print item.get_text()
    t1 = time.time()
    print t1 - t0  # about 6~8ms

No Freezing UI

import time
from poco.drivers.unity3d import UnityPoco

poco = UnityPoco()
t0 = time.time()
for item in poco('Scroll View').offspring(type='Text'):
    print item.get_text()
t1 = time.time()
print t1 - t0  # about 50~60ms

See also: