How to use test_device method in Airtest

Best Python code snippet using Airtest

test_MotionDev.py

Source:test_MotionDev.py Github

copy

Full Screen

...13import insteon_mqtt.message as Msg14# import insteon_mqtt.util as util15import helpers as H16@pytest.fixture17def test_device(tmpdir):18 '''19 Returns a generically configured iolinc for testing20 '''21 protocol = H.main.MockProtocol()22 modem = H.main.MockModem(tmpdir)23 addr = IM.Address(0x01, 0x02, 0x03)24 device = Motion(protocol, modem, addr)25 return device26class Test_Base_Config():27 def test_pair(self, test_device):28 with mock.patch.object(IM.CommandSeq, 'add'):29 test_device.pair()30 calls = [31 call(test_device.refresh),...

Full Screen

Full Screen

run_tests.py

Source:run_tests.py Github

copy

Full Screen

1#! /usr/bin/python2import serial, time3import subprocess4from subprocess import call, Popen5from argparse import ArgumentParser6import re7import unittest8import os9def do_test(port, baudrate, test_name):10 databits = serial.EIGHTBITS11 stopbits = serial.STOPBITS_ONE12 parity = serial.PARITY_NONE13 ser = serial.Serial(port, baudrate, databits, parity, stopbits, timeout=10)14 ser.write('\n\n')15 finished = 016 success = False17 timeout = 10 # 10 seconds18 timeout_start = time.time()19 while finished == 0:20 serial_line = ser.readline()21 print(serial_line.replace('\n',''))22 if "nsh>" in serial_line:23 finished = 124 if time.time() > timeout_start + timeout:25 print("Error, timeout")26 finished = 127 break28 # run test29 ser.write('tests ' + test_name + '\n')30 time.sleep(0.05)31 finished = 032 timeout = 300 # 5 minutes33 timeout_start = time.time()34 timeout_newline = time.time()35 while finished == 0:36 serial_line = ser.readline()37 print(serial_line.replace('\n',''))38 if test_name + " PASSED" in serial_line:39 finished = 140 success = True41 elif test_name + " FAILED" in serial_line:42 finished = 143 success = False44 if time.time() > timeout_start + timeout:45 print("Error, timeout")46 print(test_name + " FAILED")47 finished = 148 success = False49 break50 # newline every 30 seconds if still running51 if time.time() - timeout_newline > 30:52 ser.write('\n')53 timeout_newline = time.time()54 ser.close()55 return success56class TestHadrwareMethods(unittest.TestCase):57 TEST_DEVICE = 058 TEST_BAUDRATE = 059 def test_bezier(self):60 self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "bezier"))61 def test_bson(self):62 self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "bson"))63 def test_commander(self):64 self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "commander"))65 def test_controllib(self):66 self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "controllib"))67# def test_dataman(self):68# self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "dataman"))69 def floattest_float(self):70 self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "float"))71 def hrttest_hrt(self):72 self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "hrt"))73 def test_hrt(self):74 self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "hrt"))75 def test_IntrusiveQueue(self):76 self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "IntrusiveQueue"))77 def test_List(self):78 self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "List"))79 def test_mathlib(self):80 self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "mathlib"))81 def test_matrix(self):82 self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "matrix"))83 def test_microbench_atomic(self):84 self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "microbench_atomic"))85 def test_microbench_hrt(self):86 self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "microbench_hrt"))87 def test_microbench_math(self):88 self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "microbench_math"))89 def test_microbench_matrix(self):90 self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "microbench_matrix"))91 def test_microbench_uorb(self):92 self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "microbench_uorb"))93# def test_mixer(self):94# self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "mixer"))95 def test_param(self):96 self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "param"))97 def test_parameters(self):98 self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "parameters"))99 def test_perf(self):100 self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "perf"))101 def search_mintest_xxx(self):102 self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "search_min"))103 def test_sleep(self):104 self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "sleep"))105 def test_smoothz(self):106 self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "smoothz"))107 def test_time(self):108 self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "time"))109 #def test_uorb(self):110 # self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "uorb"))111 def test_versioning(self):112 self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "versioning"))113def main():114 parser = ArgumentParser(description=__doc__)115 parser.add_argument('--device', "-d", nargs='?', default = None, help='')116 parser.add_argument("--baudrate", "-b", dest="baudrate", type=int, help="Mavlink port baud rate (default=57600)", default=57600)117 args = parser.parse_args()118 TestHadrwareMethods.TEST_DEVICE = args.device119 TestHadrwareMethods.TEST_BAUDRATE = args.baudrate120 unittest.main(__name__, argv=['main'])121if __name__ == "__main__":...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Airtest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful