Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Take SnapShot with TimeOutException #309

Closed
answerhua96 opened this issue Oct 12, 2022 · 15 comments
Closed

Take SnapShot with TimeOutException #309

answerhua96 opened this issue Oct 12, 2022 · 15 comments

Comments

@answerhua96
Copy link

answerhua96 commented Oct 12, 2022

Hey first that all, thanks for the amazing tool.

I'm trying to take snapshot for some of my app with method
device.takeSnapShot(reconnect = true)
but it some times show me some error likes

File "/usr/local/lib/python3.6/site-packages/com/dtmilano/android/adb/adbclient.py", line 820, in takeSnapshot
   received = self.__receive(1 * 4 + 12 * 4)
 File "/usr/local/lib/python3.6/site-packages/com/dtmilano/android/adb/adbclient.py", line 339, in __receive
   raise Timer.TimeoutException('%d EXPIRED' % timerId)
com.dtmilano.android.adb.adbclient.Timer.TimeoutException: 413 EXPIRED

What should I do to avoid this error? Thanks very much

@dtmilano
Copy link
Owner

What's the device you are using? What's the screen resolution?

@answerhua96
Copy link
Author

I am using emulator to run my code. If this error occurs, there will be no screen resolution. I think it might be something error with adb connect.

@answerhua96
Copy link
Author

The timing of this error is rather random

@dtmilano
Copy link
Owner

dtmilano commented Oct 13, 2022

Can you show a minimal reproducible example?
Are you running takeSnapshot() in a loop?
Multithreding?
etc.

Also, CulebraTester2-public as a backend tends to be more stable than adb in the long term and will be able to capture screenshots faster.

@answerhua96
Copy link
Author

answerhua96 commented Oct 13, 2022

I am running takeSnapshot() in a loop and running with multithreading, but one thread corresponds to one emulator.
The code just like

if __name__ == '__main__':
    thread_pool = ThreadPoolExecutor(max_workers=4)
    for i in range(0, 4):
        try:
            r = thread_pool.submit(sub_thread, host_list[i], int(port_list[i]))
        except:
            pass

def sub_thread(host, port):
    while True:
        device, serialno = ViewClient.connectToDeviceOrExit(serialno=host + ':' + str(port),timeout=120)
        ##do_some_thing
        img = device.takeSnapshot(reconnect=True)
        img.save(path)
        ##do_some_thing

@answerhua96
Copy link
Author

Should I use CulebraTester2-public instead of takeSnapshot()

@dtmilano
Copy link
Owner

Definitely, something you can try.
Notice that ViewClient.writeImagetoFile() uses self.uiAutomatorHelper.ui_device.take_screenshot() if useuiautomatorhelper=True is specified when you create a ViewClient object.

See
https://github.com/dtmilano/AndroidViewClient/blob/master/src/com/dtmilano/android/viewclient.py#L4305

This will also help you: https://stackoverflow.com/questions/72300306/how-to-start-culebratester2-server-on-more-than-one-device

@answerhua96
Copy link
Author

I will try to use ViewClient.writeImagetoFile() instead of

img = device.takeSnapshot(reconnect=True)
img.save(path)

Thanks very much

@dtmilano
Copy link
Owner

Don't forget you need useuiautomatorhelper=True when creating ViewClient, otherwise it will use the same device.takeSnapshot(reconnect=True), and the service up and running as described here.

@answerhua96
Copy link
Author

answerhua96 commented Oct 13, 2022

When I use ViewClient(device=self.device, serialno=self.SERIALNO) to create a ViewClient, it shows me dump() Error.

ValueError: received does not contain valid XML: ERROR: null root node returned by UiTestAutomationBridge

@dtmilano
Copy link
Owner

ViewClient(device=self.device, serialno=self.SERIALNO, useuiautomatorhelper=True)

check (and possibly run as a test too) the examples in https://github.com/dtmilano/AndroidViewClient/tree/master/examples/helper

@answerhua96
Copy link
Author

Thanks a lot. I will try this method.

@answerhua96
Copy link
Author

Thanks a lot, the new method works.
By the way I have another question.I have a plenty of App to takeSnapShot.Some of these apps should be displayed in landscape(such as some games), others should be displayed vertically.Can ViewClient judge whether an APP should be displayed on a landscape screen or a vertical screen? Now, all of my app are displayed vertically.

@dtmilano
Copy link
Owner

CulebraTester2-public API supports a bunch of orientation and rotation methods like

  • /uiDevice/displayRotation
  • /uiDevice/freezeRotation
  • /uiDevice/isNaturalOrientation
  • /uiDevice/unfreezeRotation
  • etc.
    That would be handy in your case. Anyways, you can close this issue and open a new one providing more details, minimal reproducible examples, screenshots, etc.

@answerhua96
Copy link
Author

Thanks very much, I will close this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants