Best Python code snippet using Airtest
nircmd_receiver.py
Source:nircmd_receiver.py  
...67    def __init__(self):68        self.width = str(GetSystemMetrics(0))69        self.height = str(GetSystemMetrics(1))70        self.resolution = ["width", "height"]71    def get_current_resolution(self):72        self.resolution[0] = self.width73        self.resolution[1] = self.height74        return "_".join(self.resolution)75if __name__ == "__main__":76    resolution_path = "C:\\cygwin\\home\\cyg_server\\sqa_at\\resolution\\"77    while 1:78        resolution = os.listdir(resolution_path)79        if len(resolution) == 1:80            TV = NirAction(resolution[0])81            TV.setdisplay()82            time.sleep(1)83            os.rmdir(resolution_path + resolution[0])84            monitor = ResolutionMethod()85            if resolution[0][:-6] == monitor.get_current_resolution():86                os.mkdir(resolution_path + monitor.get_current_resolution())87            else:88                os.system("taskkill/f /im nircmd.exe")89            time.sleep(2)90            for i in resolution:91                if os.path.exists(resolution_path + i):92                    os.rmdir(resolution_path + i)93        else:...test_monkey.py
Source:test_monkey.py  
...6import time7import unittest8class Monkey(unittest.TestCase):9	def test1(self):10		resolution = G.DEVICE.get_current_resolution()11		old = time.time()12		while True:13			pos1 = random.uniform(0, resolution[0])14			pos2 = random.uniform(0, resolution[1])15			G.DEVICE.touch((pos1, pos2))16			new = time.time()17			if (new - old) > 60.0:18				break19	def test2(self):20		stop_app('com.tencent.TsumTsumAndroid')21		sleep(3.0)22		start_app('com.tencent.TsumTsumAndroid')23		wait(Template(r"D:\\workspace\\UITest_TsumTsum\\Case\\photo\\tpl1568629745795.png", record_pos=(-0.01, 0.91), resolution=(720, 1496)))24		poco = UnityPoco()25		sleep(1.0)26		poco("btn_start_level").click()27		sleep(2.0)28		poco(29			absoluteName="UI Root/ChapterPopupPanel/ChapterContainer/list_chapter/scrollView/table/0002/btn_content/chapter_1/tex_chapter").click()30		sleep(1.0)31		poco("level_2").click()32		sleep(1.0)33		poco("btn_start").click()34		resolution = G.DEVICE.get_current_resolution()35		old = time.time()36		while True:37			pos1 = random.uniform(0, resolution[0])38			pos2 = random.uniform(400, resolution[1] - 400)39			pos3 = random.uniform(0, resolution[0])40			pos4 = random.uniform(400, resolution[1] - 400)41			G.DEVICE.swipe((pos1, pos2), (pos3, pos4))42			new = time.time()43			if (new - old) > 65.0:44				break45if __name__ == "__main__":...screen.py
Source:screen.py  
...7class LinuxScreenComponent(ScreenComponent):8    def __init__(self, name):9        self._name = name10    def snapshot(self, filename="tmp.png"):11        w, h = self.get_current_resolution()12        dsp = display.Display()13        root = dsp.screen().root14        raw = root.get_image(0, 0, w, h, X.ZPixmap, 0xffffffff)15        image = Image.frombytes("RGB", (w, h), raw.data, "raw", "BGRX")16        image = pil_2_cv2(image)17        if filename:18            imwrite(filename, image)19        return image20    def get_current_resolution(self):21        d = display.Display()22        screen = d.screen()23        w, h = (screen["width_in_pixels"], screen["height_in_pixels"])24        return w, h25    @property26    def name(self):27        return self._name28    29    @name.setter30    def name(self, value):...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!!
