Best Python code snippet using Airtest
test_android.py
Source:test_android.py
...12 self.android = Android()13 @classmethod14 def tearDownClass(self):15 try_remove('screen.mp4')16 def _install_test_app(self):17 if PKG not in self.android.list_app():18 self.android.install_app(APK)19 def test_serialno(self):20 self.assertIsNotNone(self.android.serialno)21 def test_adb(self):22 self.assertIsInstance(self.android.adb, ADB)23 def test_display_info(self):24 self.assertIs(self.android.display_info, self.android.adb.display_info)25 self.assertIn("width", self.android.display_info)26 self.assertIn("height", self.android.display_info)27 self.assertIn("orientation", self.android.display_info)28 self.assertIn("rotation", self.android.display_info)29 def test_minicap(self):30 minicap = self.android.minicap31 self.assertIsInstance(minicap, Minicap)32 self.assertIs(minicap.adb.display_info, self.android.display_info)33 def test_minitouch(self):34 self.assertIsInstance(self.android.minitouch, Minitouch)35 def test_list_app(self):36 self._install_test_app()37 self.assertIn(PKG, self.android.list_app())38 self.assertIn(PKG, self.android.list_app(third_only=True))39 def test_path_app(self):40 self._install_test_app()41 app_path = self.android.path_app(PKG)42 self.assertIn(PKG, app_path)43 self.assertTrue(app_path.startswith("/"))44 with self.assertRaises(AirtestError):45 self.android.path_app('com.netease.this.is.error')46 def test_check_app(self):47 self._install_test_app()48 self.assertTrue(self.android.check_app(PKG))49 with self.assertRaises(AirtestError):50 self.android.check_app('com.netease.this.is.error')51 def test_snapshot(self):52 self._install_test_app()53 for i in (CAP_METHOD.ADBCAP, CAP_METHOD.MINICAP, CAP_METHOD.MINICAP_STREAM, CAP_METHOD.JAVACAP):54 filename = "./screen.png"55 if os.path.exists(filename):56 os.remove(filename)57 self.android.cap_method = i58 self.android.wake()59 screen = self.android.snapshot(filename=filename)60 self.assertIsInstance(screen, numpy.ndarray)61 self.assertTrue(os.path.exists(filename))62 os.remove(filename)63 def test_shell(self):64 self.assertEqual(self.android.shell('echo nimei').strip(), 'nimei')65 def test_keyevent(self):66 self.android.keyevent("BACK")67 def test_wake(self):68 self.android.wake()69 def test_screenon(self):70 self.assertIn(self.android.is_screenon(), (True, False))71 def test_home(self):72 self.android.home()73 def test_text(self):74 self.android.ime_method = IME_METHOD.ADBIME75 self.android.text('test text')76 self.android.ime_method = IME_METHOD.YOSEMITEIME77 self.android.text(u'ä½ å¥½')78 def test_touch(self):79 for i in (TOUCH_METHOD.ADBTOUCH, TOUCH_METHOD.MINITOUCH):80 self.android.touch_method = i81 self.android.touch((100, 100))82 def test_swipe(self):83 for i in (TOUCH_METHOD.ADBTOUCH, TOUCH_METHOD.MINITOUCH):84 self.android.touch_method = i85 self.android.swipe((100, 100), (300, 300))86 self.android.swipe((100, 100), (300, 300), fingers=1)87 self.android.swipe((100, 100), (300, 300), fingers=2) 88 self.android.touch_method = TOUCH_METHOD.ADBTOUCH89 self.android.swipe((100, 100), (300, 300), fingers=3)90 self.android.touch_method = TOUCH_METHOD.MINITOUCH91 with self.assertRaises(Exception):92 self.android.swipe((100, 100), (300, 300), fingers=3)93 def test_recording(self):94 if self.android.sdk_version >= 19:95 filepath = "screen.mp4"96 if os.path.exists(filepath):97 os.remove(filepath)98 self.android.start_recording(max_time=30, bit_rate=500000, vertical=False)99 time.sleep(3)100 self.android.stop_recording()101 self.assertTrue(os.path.exists("screen.mp4"))102 def test_start_recording_error(self):103 if self.android.sdk_version >= 19:104 with self.assertRaises(AirtestError):105 self.android.start_recording(max_time=30)106 time.sleep(3)107 self.android.start_recording(max_time=30)108 self.android.stop_recording()109 def test_stop_recording_error(self):110 with self.assertRaises(AirtestError):111 self.android.stop_recording()112 def test_interrupt_recording(self):113 filepath = "screen.mp4"114 if os.path.exists(filepath):115 os.remove(filepath)116 self.android.start_recording(max_time=30)117 time.sleep(3)118 self.android.stop_recording(is_interrupted=True)119 self.assertFalse(os.path.exists(filepath))120 def test_get_top_activity(self):121 self._install_test_app()122 self.android.start_app(PKG)123 pkg, activity, pid = self.android.get_top_activity()124 self.assertEqual(pkg, PKG)125 self.assertEqual(activity, 'org.cocos2dx.javascript.AppActivity')126 self.assertIsInstance(int(pid), int)127 def test_is_keyboard_shown(self):128 self.android.is_keyboard_shown()129 def test_is_locked(self):130 self.android.is_locked()131 def test_unlock(self):132 self.android.unlock()133 def test_pinch(self):134 self.android.pinch(in_or_out='in')135 self.android.pinch(in_or_out='out')...
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!!