Best Python code snippet using Airtest
mark_page.py
Source:mark_page.py
...6 """7 设置æ 注形ç¶ä¸ºç©å½¢8 :return:9 """10 def test_wait(x):11 self._params['condition_val'] = condition_val12 element_len = self.steps("page/mark_page.yaml", "click_play_condition")13 if element_len == 'False':14 a = self.steps("page/mark_page.yaml", "click_play_condition")15 return element_len > 016 self.wait_for_condition(test_wait)17 self.steps("page/mark_page.yaml", "set_mark_rectangle")18 def set_mark_polygon(self, condition_val):19 """20 设置æ 注形ç¶ä¸ºå¤è¾¹å½¢21 :return:22 """23 def test_wait(x):24 self._params['condition_val'] = condition_val25 element_len = self.steps("page/mark_page.yaml", "click_play_condition")26 if element_len == 'False':27 a = self.steps("page/mark_page.yaml", "click_play_condition")28 return element_len > 029 self.wait_for_condition(test_wait)30 self.steps("page/mark_page.yaml", "set_mark_polygon")31 def set_mark_parallelogram(self, condition_val):32 """33 设置æ 注形ç¶ä¸ºå¹³è¡å边形34 :return:35 """36 def test_wait(x):37 self._params['condition_val'] = condition_val38 element_len = self.steps("page/mark_page.yaml", "click_play_condition")39 if element_len == 'False':40 a = self.steps("page/mark_page.yaml", "click_play_condition")41 return element_len > 042 self.wait_for_condition(test_wait)43 self.steps("page/mark_page.yaml", "set_mark_parallelogram")44 def set_mark_ordered_parallelogram(self):45 """46 设置æ 注形ç¶ä¸ºæåºå¹³è¡å边形47 :return:48 """49 self.steps("page/mark_page.yaml", "set_mark_ordered_parallelogram")50 def mark_rectangle(self, position):51 """52 ç»ä¸ä¸ªé¢å®ä¹çç©å½¢53 :return:54 """55 self._params["start_position"] = str(position['start_position'])56 self._params["end_position"] = str(position['end_position'])57 self.steps("page/mark_page.yaml", "mark_rectangle")58 def mark_polygon(self, position):59 """60 ç»ä¸ä¸ªé¢å®ä¹çå¤è¾¹å½¢61 :return:62 """63 self._params["position1"] = str(position['position1'])64 self._params["position2"] = str(position['position2'])65 self._params["position3"] = str(position['position3'])66 self._params["position4"] = str(position['position4'])67 self._params["position5"] = str(position['position5'])68 self.steps("page/mark_page.yaml", "mark_polygon")69 def mark_parallelogram(self, position):70 """71 ç»ä¸ä¸ªé¢å®ä¹çå¹³è¡å边形72 :return:73 """74 self._params["position1"] = str(position['position1'])75 self._params["position2"] = str(position['position2'])76 self._params["position3"] = str(position['position3'])77 self.steps("page/mark_page.yaml", "mark_parallelogram")78 def mark_ordered_parallelogram(self, position):79 """80 ç»ä¸ä¸ªé¢å®ä¹çæåºå¹³è¡å边形81 :return:82 """83 self._params["position1"] = str(position['position1'])84 self._params["position2"] = str(position['position2'])85 self._params["position3"] = str(position['position3'])86 self.steps("page/mark_page.yaml", "mark_ordered_parallelogram")87 def select_predefined(self):88 """89 æ°å¢ä¸ä¸ªæ¡åï¼éæ©æ ç¾ä¸ºé¢å®ä¹æ ç¾90 :return:91 """92 self.steps("page/mark_page.yaml", "select_predefined")93 def select_customize(self):94 """95 æ°å¢ä¸ä¸ªæ¡åï¼éæ©æ ç¾ä¸ºå®æ¶æ ç¾96 :return:97 """98 self.steps("page/mark_page.yaml", "select_customize")99 def select_predefined_val(self):100 """101 éæ©é¢å®ä¹æ ç¾å±æ§102 :return:103 """104 pass105 def add_customize_val(self, add_value):106 """107 æ·»å å®æ¶æ ç¾çå¼108 :return:109 """110 self._params["add_customize_val"] = str(add_value['add_value'])111 self.steps("page/mark_page.yaml", "add_customize_val")112 def select_ignore(self):113 """114 éæ©å¯å±æ§éæ©å¿½ç¥115 :return:116 """117 self.steps("page/mark_page.yaml", "select_ignore")118 def select_crowd(self):119 """120 éæ©å¯å±æ§å¯é121 :return:122 """123 self.steps("page/mark_page.yaml", "select_crowd")124 def click_cancel(self):125 """126 æ°å¢æ¡æä¿®æ¹æ¡æ¶ç¹å»åæ¶127 :return:128 """129 self.steps("page/mark_page.yaml", "click_cancel")130 def click_submit(self, img_name):131 """132 æ°å¢æ¡æä¿®æ¹æ¡æ¶ç¹å»ç¡®å®133 :return:134 """135 self.steps("page/mark_page.yaml", "click_submit")136 self.driver.save_screenshot(f'result/{img_name}.png')137 def double_click(self, double_click):138 """139 åå»140 :return:141 """142 self._params["double_click"] = double_click143 self.steps("page/mark_page.yaml", "double_click")144 def update_object_id(self, update_value):145 """146 ä¿®æ¹æ¡ç对象ID147 :return:148 """149 self._params["update_object_id_val"] = str(update_value["updata_value"])150 self.steps("page/mark_page.yaml", "update_object_id")151 def update_mark_position(self, position):152 """153 ä¿®æ¹æ¡çä½ç½®154 :return:155 """156 self._params["start_position"] = str(position['start_position'])157 self._params["end_position"] = str(position['end_position'])158 self.steps("page/mark_page.yaml", "mark_rectangle")159 def click_all_cancel(self):160 """161 å
¨é¨åæ¶162 :return:163 """164 self.steps("page/mark_page.yaml", "click_all_cancel")165 def click_all_submit(self):166 """167 ç¹å»å
¨é¨ä¿å168 :return:169 """170 self.steps("page/mark_page.yaml", "click_all_submit")171 self.driver.save_screenshot('result/shortcut_key.png')172 def set_show_predefined_mark(self):173 """174 设置æ¾ç¤ºé¢å®ä¹æ ç¾çæ¡175 :return:176 """177 self.steps("page/mark_page.yaml", "set_show_predefined_mark")178 def set_show_customize_mark(self, condition_val):179 """180 设置æ¾ç¤ºå®æ¶æ ç¾çæ¡181 :return:182 """183 def test_wait(x):184 self._params['condition_val'] = condition_val185 element_len = self.steps("page/mark_page.yaml", "click_play_condition")186 if element_len == 'False':187 a = self.steps("page/mark_page.yaml", "click_play_condition")188 return element_len > 0189 self.wait_for_condition(test_wait)190 self.steps("page/mark_page.yaml", "set_show_customize_mark")191 def click_add_btn(self, condition_val):192 """193 ç¹å»æ°å¢æé®Q194 :return:195 """196 def test_wait(x):197 self._params['condition_val'] = condition_val198 element_len = self.steps("page/mark_page.yaml", "click_play_condition")199 if element_len == 'False':200 a = self.steps("page/mark_page.yaml", "click_play_condition")201 return element_len > 0202 self.wait_for_condition(test_wait)203 self.steps("page/mark_page.yaml", "click_add_btn")204 def select_del_mark(self, position, condition_val):205 """206 éæ©éè¦å é¤çæ¡207 :return:208 """209 def test_wait(x):210 self._params['condition_val'] = condition_val211 element_len = self.steps("page/mark_page.yaml", "click_play_condition")212 if element_len == 'False':213 a = self.steps("page/mark_page.yaml", "click_play_condition")214 return element_len > 0215 self.wait_for_condition(test_wait)216 self._params["start_position"] = str(position['start_position'])217 self.steps("page/mark_page.yaml", "select_del_mark")218 def click_del_btn(self, condition_val):219 """220 ç¹å»å é¤æé®221 :return:222 """223 def test_wait(x):224 self._params['condition_val'] = condition_val225 element_len = self.steps("page/mark_page.yaml", "click_play_condition")226 if element_len == 'False':227 a = self.steps("page/mark_page.yaml", "click_play_condition")228 return element_len > 0229 self.wait_for_condition(test_wait)230 self.steps("page/mark_page.yaml", "click_del_btn")231 def click_previous_img_btn(self):232 """233 ç¹å»ä¸ä¸å¼ 234 :return:235 """236 self.wait_for_click((By.XPATH, "//*[@class='quick-btn-list']//button[3]"))237 self.steps("page/mark_page.yaml", "click_previous_img_btn")238 def click_next_img_btn(self):239 """240 ç¹å»ä¸ä¸å¼ 241 :return:242 """243 self.steps("page/mark_page.yaml", "click_next_img_btn")244 def click_hide_btn(self):245 """246 ç¹å»ä¸ä¸å¼ 247 :return:248 """249 self.wait_for_click((By.XPATH, "//*[@class='quick-btn-list']//button[5]"))250 self.steps("page/mark_page.yaml", "click_hide_btn")251 def click_reset_img_btn(self):252 """253 ç¹å»éç½®254 :return:255 """256 self.steps("page/mark_page.yaml", "click_reset_img_btn")257 def click_not_mark_btn(self):258 """259 å¨å¾çæ 注页ï¼ç¹å»æ æ³æ 注æé®260 :return:261 """262 self.wait_for_click((By.XPATH, "//*[@class='quick-btn-list']//button[7]"))263 self.steps("page/mark_page.yaml", "click_not_mark_btn")264 def moved_right(self):265 """266 é¼ æ 移å¨è³å³ä¾§ï¼è°åºæ 注索å¼é¡µ267 :return:268 """269 self.steps("page/mark_page.yaml", "moved_right")270 def click_enter_not_mark_pic(self):271 """272 ç¹å»è¿å
¥æ²¡ææ 注çå¾ç273 :return:274 """275 self.steps("page/mark_page.yaml", "click_enter_not_mark_pic")276 def click_previous_page(self):277 """278 ç¹å»ä¸ä¸é¡µ279 :return:280 """281 self.steps("page/mark_page.yaml", "click_previous_page")282 def click_next_page(self):283 """284 ç¹å»ä¸ä¸é¡µ285 :return:286 """287 self.steps("page/mark_page.yaml", "click_next_page")288 def click_object_id(self):289 """290 ç¹å»å¯¹è±¡IDï¼éè¦ä¼ å
¥å¯¹è±¡IDçxpath291 :return:292 """293 self.steps("page/mark_page.yaml", "click_object_id")294 def click_attribute(self):295 """296 ç¹å»å±æ§ï¼éè¦ä¼ å
¥å±æ§çXpath297 :return:298 """299 self.steps("page/mark_page.yaml", "click_attribute")300 def click_play(self, condition_val):301 """302 ç¹å»ææ¾303 :return:304 """305 def test_wait(x):306 self._params['condition_val'] = condition_val307 element_len = self.steps("page/mark_page.yaml", "click_play_condition")308 if element_len == 'False':309 a = self.steps("page/mark_page.yaml", "click_play_condition")310 return element_len > 0311 self.wait_for_condition(test_wait)312 self.steps("page/mark_page.yaml", "click_play")313 def click_begin_or_end(self):314 """315 ç¹å»å¼å§æç»ææ è®°316 :return:317 """318 self.steps("page/mark_page.yaml", "click_begin_or_end")319 def click_previous_video(self, condition_val):320 """321 ç¹å»ä¸ä¸ä¸ªè§é¢322 :return:323 """324 def test_wait(x):325 self._params['condition_val'] = condition_val326 element_len = self.steps("page/mark_page.yaml", "click_play_condition")327 if element_len == 'False':328 a = self.steps("page/mark_page.yaml", "click_play_condition")329 return element_len > 0330 self.wait_for_condition(test_wait)331 self.steps("page/mark_page.yaml", "click_previous_video")332 def click_next_video(self):333 """334 ç¹å»ä¸ä¸ä¸ªè§é¢335 :return:336 """337 self.steps("page/mark_page.yaml", "click_next_video")338 def click_return(self):339 """340 ç¹å»å¿«é341 :return:342 """343 self.steps("page/mark_page.yaml", "click_return")344 def click_forward(self):345 """346 ç¹å»å¿«è¿347 :return: 348 """349 self.steps("page/mark_page.yaml", "click_forward")350 def click_not_mark_btn_video(self):351 """352 å¨è§é¢æ 注页ï¼ç¹å»æ æ³æ 注æé®353 :return:354 """355 self.wait_for_click((By.XPATH, '//*[@class="quick-btn-list"]/button[7]'))356 self.steps("page/mark_page.yaml", "click_not_mark_btn_video")357 def update_video_label(self, condition_val):358 """359 æ´æ°è§é¢çæ ç¾360 :return:361 """362 def test_wait(x):363 self._params['condition_val'] = condition_val364 element_len = self.steps("page/mark_page.yaml", "click_update_video_label")365 if element_len == 'False':366 a = self.steps("page/mark_page.yaml", "click_update_video_label")367 return element_len > 0368 self.wait_for_condition(test_wait)369 self.steps("page/mark_page.yaml", "update_video_label")370 def click_del_label(self, condition_val):371 """372 ç¹å»å é¤æ 注ç»æ373 :return:374 """375 def test_wait(x):376 self._params['condition_val'] = condition_val377 element_len = self.steps("page/mark_page.yaml", "click_play_condition")378 if element_len == 'False':379 a = self.steps("page/mark_page.yaml", "click_play_condition")380 return element_len > 0381 self.wait_for_condition(test_wait)382 self.set_implicitly_wait(3)383 self.steps("page/mark_page.yaml", "click_del_label")384 def click_del_label_submit(self, condition_val):385 """386 ç¹å»å é¤æ 注ç»æ确认æé®387 :return:388 """389 def test_wait(x):390 self._params['condition_val'] = condition_val391 element_len = self.steps("page/mark_page.yaml", "click_play_condition")392 if element_len == 'False':393 a = self.steps("page/mark_page.yaml", "click_play_condition")394 return element_len > 0395 self.wait_for_condition(test_wait)396 self.steps("page/mark_page.yaml", "click_del_label_submit")397 self.driver.save_screenshot('result/task_video.png')398 def click_add_step_len(self):399 """400 ç¹å»æ°å¢æ¥é¿401 :return:402 """403 self.steps("page/mark_page.yaml", "click_add_step_len")
helper.py
Source:helper.py
...21 global _failedNum, _testNum22 setcp1()23 if EUDIf()(condition):24 f_simpleprint("\x07 - [ OK ]\x04", testname)25 test_wait(0)26 if EUDElse()():27 f_simpleprint("\x08 - [FAIL]", testname)28 failedTestDb = DBString(testname)29 _failedTest[_failedNum] = failedTestDb30 _testFailed << 131 test_wait(24)32 EUDEndIf()33 resetcp()34 _testNum += 135 test_wait(0)36def test_equality(testname, real, expt):37 global _failedNum, _testNum38 real = Assignable2List(real)39 expt = Assignable2List(expt)40 setcp1()41 if EUDIf()([r == e for r, e in zip(real, expt)]):42 f_simpleprint("\x07 - [ OK ]\x04", testname)43 test_wait(0)44 if EUDElse()():45 f_simpleprint("\x08 - [FAIL]", testname)46 f_simpleprint(" \x03 - \x04 Output : ", *real)47 f_simpleprint(" \x03 - \x04 Expected : ", *expt)48 failedTestDb = DBString(testname)49 _failedTest[_failedNum] = failedTestDb50 _failedNum += 151 test_wait(24)52 EUDEndIf()53 resetcp()54 f_setcurpl(origcp)55 _testNum += 156def test_operator(testname, realf, exptf=None):57 if exptf is None:58 exptf = realf59 try:60 f = realf._bodyfunc61 except AttributeError:62 f = realf63 argcount = f.__code__.co_argcount64 @TestInstance65 def test_operator():66 inputs = [EUDVariable() for _ in range(argcount)]67 expt, real = [], []68 for i in range(20):69 rnums = [_random.randint(0, 0xFFFFFFFF) for _ in range(argcount)]70 SetVariables(inputs, rnums)71 real.append(realf(*inputs))72 expt.append(exptf(*rnums) & 0xFFFFFFFF)73 test_assert(74 "Operator test : %s" % testname, [r == e for r, e in zip(real, expt)]75 )76class expect_eperror:77 def __enter__(self):78 PushTriggerScope()79 def __exit__(self, type, e, traceback):80 PopTriggerScope()81 if isinstance(e, EPError):82 print(" - Error as expected : %s" % e)83 return True84 else:85 raise RuntimeError("EPError not thrown")86###############################################################87# Performance testing helper88###############################################################89perf_basecount = 20000090def test_perf(testname, func, count):91 starttm = f_dwread_epd(EPD(0x51CE8C))92 if EUDLoopN()(count):93 func()94 EUDEndLoopN()95 test_wait(0)96 endtm = f_dwread_epd(EPD(0x51CE8C))97 elapsedTime = starttm - endtm98 averageTime = elapsedTime // count99 setcp1()100 f_simpleprint(101 "\x03" * 150 + "[PERF] \x04%s \x03* %d \x05" % (testname, count),102 averageTime,103 "/",104 elapsedTime,105 spaced=False,106 )107 resetcp()108 test_wait(12)109###############################################################110def test_complete():111 setcp1()112 f_simpleprint("\x03" + "=" * 40)113 succNum = _testNum - _failedNum114 f_simpleprint("\x04 Test result : ", succNum, "/", _testNum, spaced=False)115 resetcp()116_testList = []117def TestInstance(func):118 print(" - Adding test instance %s" % func.__name__)119 _testList.append((func, func.__name__))120 return func121@EUDFunc122def _testmain():123 for testfunc, testname in _testList:124 _testFailed << 0125 f_simpleprint("\x03[TEST] í
ì¤í¸ë¥¼ ì§íí©ëë¤:", testname)126 testfunc()127 Trigger(_testFailed == 1, _failedNum.AddNumber(1))128 test_complete()129def test_runall(testname):130 LoadMap("outputmap/basemap/basemap_strx.scx")131 SaveMap("outputmap/test_%s.scx" % testname, _testmain)132def test_wait(time):133 DoActions(SetMemory(0x6509A0, SetTo, time))...
test.py
Source:test.py
...52 place.updateSunTimes()53 scheme = murklanScheme(place)54 lamp = Lamp(1)55 lamp.update(datetime.time(12, 10, 5, 0, tz), scheme[1][1][1])56 test_wait("Lamp expected to be OFF. Press enter to continue.")57 58 lamp.update(datetime.time(5, 50, 5, 0, tz), scheme[1][1][1])59 test_wait("Lamp expected to be OFF. Press enter to continue.")60 61 lamp.update(datetime.time(6, 30, 5, 0, tz), scheme[1][1][1])62 test_wait("Lamp expected to be ON. Press enter to continue.")63 64 lamp.update(datetime.time(8, 30, 5, 0, tz), scheme[1][1][1])65 test_wait("Lamp expected to be ON. Press enter to continue.")66 67 lamp.update(datetime.time(9, 10, 5, 0, tz), scheme[1][1][1])68 test_wait("Lamp expected to be OFF. Press enter to continue.")69 70 lamp.update(datetime.time(18, 40, 5, 0, tz), scheme[1][1][1]) # after sunset but within offset71 test_wait("Lamp expected to be OFF. Press enter to continue.")72 73 lamp.update(datetime.time(18, 59, 5, 0, tz), scheme[1][1][1])74 test_wait("Lamp expected to be ON. Press enter to continue.")75 76 lamp.update(datetime.time(22, 29, 5, 0, tz), scheme[1][1][1])77 test_wait("Lamp expected to be ON. Press enter to continue.")78 79 lamp.update(datetime.time(22, 30, 5, 0, tz), scheme[1][1][1])80 test_wait("Lamp expected to be OFF. Press enter to continue.")81def test_wait(s) :82 input(s)83 84 85def test_update() :86 nkp = Place(nkpCoord())87 nkp.updateSunTimes()88 myscheme = murklanScheme(nkp)89 update(myscheme)...
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!!