Best Python code snippet using Airtest
__init__.py
Source:__init__.py
...12 self.current_orientation = None13 self._t = None14 self.ow_callback = []15 def start(self):16 def _refresh_by_adb():17 ori = self.device.getDisplayOrientation()18 return ori19 def _run(kill_event):20 while not kill_event.is_set():21 ori = _refresh_by_adb()22 if self.current_orientation == ori:23 time.sleep(2)24 continue25 if ori is None:26 continue27 logger.info('update orientation {}->{}'.format(self.current_orientation, ori))28 self.current_orientation = ori29 for callback in self.ow_callback:30 try:31 callback(ori)32 except Exception:33 logger.error('callback: {} error'.format(callback))34 traceback.print_exc()35 self.current_orientation = _refresh_by_adb()36 self._t = threading.Thread(target=_run, args=(self._kill_event,), name='rotationwatcher')37 self._t.daemon = True38 self._t.start()39 return self.current_orientation40 def reg_callback(self, ow_callback):41 """42 Args:43 ow_callback:44 Returns:45 """46 """æ¹åååçæ¶åçåè°å½æ°ï¼åæ°ä¸å®æ¯ori"""...
rotation.py
Source:rotation.py
...13 self.current_orientation = None14 self._t = None15 self.ow_callback = []16 def start(self):17 def _refresh_by_adb():18 ori = self.adb.getDisplayOrientation()19 return ori20 def _run(kill_event):21 while not kill_event.is_set():22 ori = _refresh_by_adb()23 if self.current_orientation == ori:24 time.sleep(2)25 continue26 if ori is None:27 continue28 logger.info('update orientation {}->{}'.format(self.current_orientation, ori))29 self.current_orientation = ori30 for callback in self.ow_callback:31 try:32 callback(ori)33 except:34 logger.error('callback: {} error'.format(callback))35 traceback.print_exc()36 self.current_orientation = _refresh_by_adb()37 self._t = threading.Thread(target=_run, args=(self._kill_event,), name='rotationwatcher')38 self._t.start()39 return self.current_orientation40 def reg_callback(self, ow_callback):41 """42 Args:43 ow_callback:44 Returns:45 """46 """æ¹åååçæ¶åçåè°å½æ°ï¼åæ°ä¸å®æ¯ori"""...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!