Closed answerhua96 closed 2 years ago
What's the device you are using? What's the screen resolution?
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.
The timing of this error is rather random
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.
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
Should I use CulebraTester2-public instead of takeSnapshot()
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.
This will also help you: https://stackoverflow.com/questions/72300306/how-to-start-culebratester2-server-on-more-than-one-device
I will try to use ViewClient.writeImagetoFile()
instead of
img = device.takeSnapshot(reconnect=True)
img.save(path)
Thanks very much
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.
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
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
Thanks a lot. I will try this method.
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.
CulebraTester2-public API supports a bunch of orientation and rotation methods like
/uiDevice/displayRotation
/uiDevice/freezeRotation
/uiDevice/isNaturalOrientation
/uiDevice/unfreezeRotation
Thanks very much, I will close this issue
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 likesWhat should I do to avoid this error? Thanks very much