Dumps the window content. Sleep is useful to wait some time before obtaining the new content when something in the window has changed. @type window: int or str @param window: the window id or name of the window to dump. The B{name} is the package na
(self, window=-1, sleep=1)
| 3477 | ViewClient.__traverse(ch, indent=indent + " ", transform=transform, stream=stream) |
| 3478 | |
| 3479 | def dump(self, window=-1, sleep=1): |
| 3480 | """ |
| 3481 | Dumps the window content. |
| 3482 | |
| 3483 | Sleep is useful to wait some time before obtaining the new content when something in the |
| 3484 | window has changed. |
| 3485 | |
| 3486 | @type window: int or str |
| 3487 | @param window: the window id or name of the window to dump. |
| 3488 | The B{name} is the package name or the window name (i.e. StatusBar) for |
| 3489 | system windows. |
| 3490 | The window id can be provided as C{int} or C{str}. The C{str} should represent |
| 3491 | and C{int} in either base 10 or 16. |
| 3492 | Use -1 to dump all windows. |
| 3493 | This parameter only is used when the backend is B{ViewServer} and it's |
| 3494 | ignored for B{UiAutomator}. |
| 3495 | @type sleep: int |
| 3496 | @param sleep: sleep in seconds before proceeding to dump the content |
| 3497 | |
| 3498 | @return: the list of Views as C{str} received from the server after being split into lines |
| 3499 | """ |
| 3500 | if sleep > 0: |
| 3501 | time.sleep(sleep) |
| 3502 | |
| 3503 | if self.useUiAutomator: |
| 3504 | if self.uiAutomatorHelper: |
| 3505 | received = self.uiAutomatorHelper.ui_device.dump_window_hierarchy() |
| 3506 | self.ui_automator_helper_dump = received |
| 3507 | else: |
| 3508 | api = self.getSdkVersion() |
| 3509 | if api >= 24: |
| 3510 | # In API 23 the process' stdout,in and err are connected to the socket not to the pts as in |
| 3511 | # previous versions, so we can't redirect to /dev/tty |
| 3512 | # Also, if we want to write to /sdcard/something it fails event though /sdcard is a symlink |
| 3513 | # Also, 'primary' storage was added. |
| 3514 | if self.serialno.startswith('emulator'): |
| 3515 | pathname = '/storage/self/primary' |
| 3516 | else: |
| 3517 | pathname = '/sdcard' |
| 3518 | filename = 'window_dump.xml' |
| 3519 | cmd = 'cp /dev/null {pathname}/{filename} && uiautomator dump {compressed} {pathname}/{filename} >/dev/null && cat {pathname}/{filename}'.format( |
| 3520 | pathname=pathname, filename=filename, |
| 3521 | compressed='--compressed' if self.compressedDump else '') |
| 3522 | elif api == 23: |
| 3523 | # In API 23 the process' stdout,in and err are connected to the socket not to the pts as in |
| 3524 | # previous versions, so we can't redirect to /dev/tty |
| 3525 | # Also, if we want to write to /sdcard/something it fails event though /sdcard is a symlink |
| 3526 | if self.serialno.startswith('emulator'): |
| 3527 | pathname = '/storage/self' |
| 3528 | filename = 'window_dump.xml' |
| 3529 | cmd = 'uiautomator dump %s %s/%s >/dev/null && cat %s/%s' % ( |
| 3530 | '--compressed' if self.compressedDump else '', pathname, filename, pathname, filename) |
| 3531 | elif self.ro['product.board'] in ['msd838', 'msd938_STB', 'msd938', 'msm8916']: |
| 3532 | cmd = 'uiautomator dump %s /dev/tty >/dev/null' % ( |
| 3533 | '--compressed' if self.compressedDump else '') |
| 3534 | else: |
| 3535 | pathname = '/sdcard' |
| 3536 | filename = 'window_dump.xml' |