Lock the device. No changes are made if the device is already unlocked. Args: seconds: The duration to lock the device, in seconds. The device is going to be locked forever until `unlock` is called if it equals or is less than zero, otherwise this
(self, seconds: Optional[int] = None)
| 26 | |
| 27 | class HardwareActions(CanExecuteCommands, CanExecuteScripts, CanRememberExtensionPresence): |
| 28 | def lock(self, seconds: Optional[int] = None) -> Self: |
| 29 | """Lock the device. No changes are made if the device is already unlocked. |
| 30 | |
| 31 | Args: |
| 32 | seconds: The duration to lock the device, in seconds. |
| 33 | The device is going to be locked forever until `unlock` is called |
| 34 | if it equals or is less than zero, otherwise this call blocks until |
| 35 | the timeout expires and unlocks the screen automatically. |
| 36 | |
| 37 | Returns: |
| 38 | Union['WebDriver', 'HardwareActions']: Self instance |
| 39 | """ |
| 40 | ext_name = 'mobile: lock' |
| 41 | args = {'seconds': seconds or 0} |
| 42 | try: |
| 43 | self.assert_extension_exists(ext_name).execute_script(ext_name, args) |
| 44 | except UnknownMethodException: |
| 45 | # TODO: Remove the fallback |
| 46 | self.mark_extension_absence(ext_name).execute(Command.LOCK, args) |
| 47 | return self |
| 48 | |
| 49 | def unlock(self) -> Self: |
| 50 | """Unlock the device. No changes are made if the device is already locked. |