Best Python code snippet using tempest_python
homemodel_check.py
Source:homemodel_check.py
...95 log_file_out('------lcc产åé¦é¡µ------')96 time.sleep(3)97 driver.switch_to.window(driver.window_handles[0])98 # ç¹å»å¤åè½æé®è¿å
¥é¦é¡µ99 check_home_page().click_more_btn(driver)100 time.sleep(2)101 # åæ¢é¦é¡µ102 check_home_page().click_different_more_btn(driver,[1,homepage_title[0]])103 time.sleep(2)104 # check_home_page().click_message(driver)105 #106 # # æ¶æ¯107 #108 # try:109 # # 设置å¾è¡¨ä¸è½½è·¯å¾ä¸ºpictureä¸é¢çproduce_home_modelçæ¶æ¯ä¸110 # produce_home_model_picture_path = os.path.dirname(111 # __file__) + '\\' + 'picture' + '\\produce_home_model' + '\\' + 'æ¶æ¯'112 #113 # if os.path.isdir(produce_home_model_picture_path) is True:114 # pass115 # else:116 # os.mkdir(produce_home_model_picture_path)117 # driver.save_screenshot(produce_home_model_picture_path + '\\' + 'æ¶æ¯' + '.png')118 # log_file_out('æ¶æ¯é¡µé¢æªå¾æå')119 # except:120 # log_file_out('æ¶æ¯é¡µé¢æªå¾å¤±è´¥')121 #122 # time.sleep(2)123 # # éªè¯æ¶æ¯å é¤124 # if len(driver.find_elements_by_class_name('el-icon-close')) != 0:125 # # åæçæ¡æ°126 # old_num = len(driver.find_elements_by_class_name('el-icon-close'))127 # # ç¹å»å é¤128 # driver.find_elements_by_class_name('el-icon-close')[1].click()129 # time.sleep(1)130 # if len(driver.find_elements_by_class_name('el-icon-close')) == old_num:131 # log_file_out('æ¶æ¯å表ä¸ç¹å»å é¤æé®å¤±æ,éªè¯å¤±è´¥')132 # else:133 # log_file_out('æ¶æ¯å表ä¸ç¹å»å é¤æé®çæ,éªè¯æå')134 # time.sleep(1)135 # # éªè¯æ¸
é¤ææ136 # pass137 # # éªè¯ä¿å模å138 # if len(driver.find_elements_by_xpath('//a[text()="ä¿å模å"]')) == 0:139 # pass140 # else:141 # try:142 # Method(driver).click('xpath', '//a[text()="ä¿å模å"]')143 #144 # WebDriverWait(driver, 3).until(EC.presence_of_element_located(145 # (By.CLASS_NAME, "ivu-message-notice")))146 # error_message = driver.find_element_by_class_name("ivu-message-notice").text147 #148 # if error_message == 'ä¿åæå':149 # # è·ååè½å150 # function_m = driver.find_elements_by_class_name('messageContent')[0].text.split('\n')[0].split('-')[151 # 1]152 # message_model = ''153 # if function_m == 'å¤æ¨¡å对æ¯ç»´åº¦':154 # # 模åå称155 # message_model_L = driver.find_elements_by_class_name('messageContent')[0].text.split('\n')[156 # 0].split('-')157 # compare_model = []158 # for mess_mo in range(3, len(message_model_L)):159 # if mess_mo != len(message_model_L) - 1:160 # message_model += message_model_L[mess_mo] + '-'161 # else:162 # message_model += message_model_L[mess_mo]163 # compare_model.append(message_model_L[mess_mo])164 # else:165 # # è·å模åå称166 # message_model = driver.find_elements_by_class_name('messageContent')[0].text.split('\n')[0].split('-')[-1]167 # # è·åèåå168 # menu_m = driver.find_elements_by_class_name('messageContent')[0].text.split('\n')[0].split('-')[169 # 2]170 #171 # time.sleep(1)172 # try:173 # Method(driver).click('class', 'ivu-icon-ios-close')174 # time.sleep(1)175 #176 # Method(driver).click('class', 'el-icon-close')177 # time.sleep(2)178 # except:179 # log_file_out('ç¹å»éåºç»å½æé®å¤±è´¥')180 # # ç¹å»èå181 # try:182 #183 # driver.find_elements_by_class_name('power-collapse-item')[1].click()184 #185 # time.sleep(1)186 # driver.find_elements_by_xpath('//span[text()=\'{}\']'.format(menu_m))[1].click()187 # except:188 # log_file_out('ç¹å»åè½èå失败')189 # time.sleep(2)190 # # ç¹å»æ´å¤191 # try:192 # Method(driver).click('class', 'icon-btn-more')193 # time.sleep(0.5)194 # # 计ç®ç¶æéæ©æ¡195 # Method(driver).click('class', 'ivu-select-placeholder')196 #197 # time.sleep(0.5)198 # driver.find_element_by_xpath('//li[text()="æªè®¡ç®"]').click()199 # time.sleep(0.5)200 # # ç¹å»æ¥è¯¢æé®201 # driver.find_elements_by_class_name('power-btnOk')[0].click()202 # time.sleep(1)203 # log_file_out('æ¥è¯¢æªè®¡ç®ç模åæå')204 # except:205 # log_file_out('æ¥è¯¢æªè®¡ç®ç模å失败')206 # target = driver.find_element_by_class_name('ivu-page-total')207 # driver.execute_script("arguments[0].scrollIntoView();", target)208 # time.sleep(1)209 # no_cal_num = driver.find_elements_by_class_name('ivu-page-total')[0].text210 # no_cal_num1 = re.findall(r'\d+', no_cal_num)211 # model_L = check_home_page().achieve_model(driver,no_cal_num1,'æªè®¡ç®')212 #213 # if function_m == 'å¤æ¨¡å对æ¯ç»´åº¦':214 # mo = ''215 # for mo_na in model_L:216 # mo += mo_na217 # mo_count = 1218 # for com_mo in compare_model:219 # if com_mo not in mo:220 # mo_count += 1221 # else:222 # pass223 #224 # if mo_count != 1:225 # log_file_out('ä¿å模åéªè¯å¤±è´¥')226 # else:227 # log_file_out('ä¿å模åéªè¯æå')228 #229 # else:230 # if message_model not in model_L:231 # log_file_out('ä¿å模åéªè¯å¤±è´¥')232 # else:233 # log_file_out('ä¿å模åéªè¯æå')234 # # è·å计ç®å®æç模å235 # # ç¹å»éç½®236 # try:237 # time.sleep(1)238 # driver.find_elements_by_class_name('power-btnOk')[1].click()239 #240 # Method(driver).click('class', 'ivu-select-placeholder')241 #242 # time.sleep(0.5)243 # driver.find_element_by_xpath('//li[text()="计ç®å®æ"]').click()244 # time.sleep(0.5)245 # # ç¹å»æ¥è¯¢æé®246 # driver.find_elements_by_class_name('power-btnOk')[0].click()247 # target = driver.find_element_by_class_name('ivu-page-total')248 # driver.execute_script("arguments[0].scrollIntoView();", target)249 # time.sleep(1)250 # success_num = driver.find_elements_by_class_name('ivu-page-total')[0].text251 # success_num1 = re.findall(r'\d+', success_num)252 # success_model =check_home_page().achieve_model(driver,success_num1,'计ç®å®æ')253 # except:254 # log_file_out('è·å计ç®å®æ模åå表失败,éªè¯å¤±è´¥')255 #256 # time.sleep(1)257 #258 # except:259 # log_file_out('æ¶æ¯å表ä¸ä¿å模åéªè¯å¤±è´¥')260 # try:261 # Method(driver).click('xpath', '//span[text()="é¦é¡µ"]')262 # except:263 # log_file_out('ç¹å»é¦é¡µæé®å¤±è´¥')264 #265 # time.sleep(2)266 # # æå¼é¡µé¢267 # check_home_page().click_more_btn(driver)268 # time.sleep(1)269 # check_home_page().click_different_more_btn(driver,[1,homepage_title[0]])270 # time.sleep(2)271 # check_home_page().click_message(driver)272 # time.sleep(1)273 # # éªè¯æå¼æ¨¡å274 # if len(driver.find_elements_by_xpath('//a[text()="æå¼æ¨¡å"]')) != 0:275 # driver.find_element_by_xpath('//a[text()="æå¼æ¨¡å"]').click()276 # time.sleep(5)277 #278 # if function_m == 'å¤æ¨¡å对æ¯ç»´åº¦':279 #280 # try:281 # Method(driver).click('class', 'more-modal-info-title')282 # time.sleep(1)283 # # éªè¯æ¨¡åå称284 #285 # if message_model == driver.find_element_by_class_name('more-modal-info-title').text:286 # log_file_out('æ´æ¢æ¨¡åå,模åå称ä¸éæ©ç模åä¸è´,éªè¯æ£ç¡®')287 # else:288 # log_file_out('æ´æ¢æ¨¡åå,模åå称ä¸éæ©ç模åä¸ä¸è´,éªè¯å¤±è´¥')289 # except:290 # log_file_out('å¤æ¨¡å对æ¯ç»´åº¦æå¼æ¨¡åéªè¯å¤±è´¥')291 # else:292 #293 #294 # try:295 # if len(driver.find_elements_by_xpath('//span[text()="模åæ¡ä»¶"]')) != 0:296 # if message_model in driver.find_elements_by_class_name('power-flex-spaceBtw')[0].text.split(':')[1].split(' ')[0]:297 # log_file_out('æå¼æ¨¡å模åå称ä¸æ¶æ¯å表ä¸å称ä¸è´,éªè¯æå')298 # else:299 # log_file_out('æå¼æ¨¡å模åå称ä¸æ¶æ¯å表ä¸å称ä¸ä¸è´,éªè¯å¤±è´¥')300 # except:301 # log_file_out('å æ¯å±æå¼æ¨¡åéªè¯å¤±è´¥')302 # # éªè¯æå¼æ¨¡åä¸æ¯å¦å¯ä»¥æ´æ¢æ¨¡å303 # check_home_page().click_more_btn(driver)304 # time.sleep(2)305 # check_home_page().click_different_more_btn(driver,[2])306 # # éªè¯æ´æ¢æ¨¡å307 # try:308 # WebDriverWait(driver, 3).until(EC.presence_of_element_located(309 # (By.CLASS_NAME, "ivu-message-notice")))310 # screen_message = driver.find_element_by_class_name("ivu-message-notice").text311 #312 # if screen_message == '临æ¶å±ä¸è½æ´æ¢æ¨¡å':313 # log_file_out('临æ¶å±ä¸ä¸è½æ´æ¢æ¨¡å,éªè¯æå')314 # else:315 # log_file_out('临æ¶å±ä¸ä¸è½æ´æ¢æ¨¡å,éªè¯å¤±è´¥')316 # except:317 # log_file_out('éªè¯ä¸´æ¶å±æ¯å¦å¯ä»¥æ´æ¢æ¨¡å失败')318 # else:319 # log_file_out('æ¶æ¯å表ä¸æ¨¡åæ°é为空')320 # # å
³éæ¶æ¯é¡µé¢321 # Method(driver).click('class','ivu-icon-ios-close')322 # time.sleep(2)323 # # ææ æ¥ç324 # try:325 # Method(driver).click('class', 'imgMore')326 # time.sleep(2)327 # Method(driver).click('xpath', '//span[text()="ææ æ¥ç"]/..')328 # log_file_out('ç¹å»ææ æ¥çæé®æå')329 # except:330 # log_file_out('ç¹å»ææ æ¥çæé®å¤±è´¥')331 # time.sleep(2)332 # try:333 # for car in psi_car:334 # driver.find_element_by_xpath(335 # "//span[@class='train zoomIn' and contains(text(),\'{}\')]".format(car)).click()336 # time.sleep(2)337 # # 设置å¾è¡¨ä¸è½½è·¯å¾ä¸ºpictureä¸é¢çproduce_home_modelçææ æ¥çä¸338 # produce_home_model_picture_path = os.path.dirname(339 # __file__) + '\\' + 'picture' + '\\produce_home_model' + '\\' + 'ææ æ¥ç'340 #341 # if os.path.isdir(produce_home_model_picture_path) is True:342 # pass343 # else:344 # os.mkdir(produce_home_model_picture_path)345 # driver.save_screenshot(produce_home_model_picture_path + '\\' + car + '_' + 'ææ å¼' + '.png')346 # Method(driver).click('class', 'ivu-icon-md-arrow-back')347 # time.sleep(2)348 # # ç¹å»å
³éæé®349 # check_home_page().click_close_but(driver)350 # log_file_out('ææ æ¥çæªå¾æå')351 # except Exception as e:352 # logger.error(e)353 # log_file_out('ææ æ¥çæªå¾å¤±è´¥')354 # time.sleep(2)355 # # ææ è¦æ¥æé®356 # try:357 # Method(driver).click('class', 'imgMore')358 # time.sleep(1)359 # Method(driver).click('xpath', '//span[text()="ææ é¢è¦"]/..')360 # time.sleep(1)361 # log_file_out('ç¹å»ææ é¢è¦æé®æå')362 # except:363 # log_file_out('ææ é¢è¦æé®å¤±è´¥')364 #365 # try:366 # # 设置å¾è¡¨ä¸è½½è·¯å¾ä¸ºpictureä¸é¢çproduce_home_modelçææ é¢è¦ä¸367 # produce_home_model_picture_path = os.path.dirname(368 # __file__) + '\\' + 'picture' + '\\produce_home_model' + '\\' + 'ææ é¢è¦'369 #370 # if os.path.isdir(produce_home_model_picture_path) is True:371 # pass372 # else:373 # os.mkdir(produce_home_model_picture_path)374 # driver.save_screenshot(produce_home_model_picture_path + '\\' + 'ææ é¢è¦' + '.png')375 # time.sleep(2)376 # # ç¹å»å
³éæé®377 # check_home_page().click_close_but(driver)378 # log_file_out('ææ é¢è¦æªå¾æå')379 # except Exception as e:380 # logger.error(e)381 # log_file_out('ææ é¢è¦æªå¾å¤±è´¥')382 # time.sleep(2)383 # ææ½384 jquery_str = ""385 try:386 f = open('{}\\config\\jquery-3.4.1.min.js'.format(path_dir), 'r', encoding='utf-8')387 line = f.readline()388 while line:389 jquery_str += line390 line = f.readline()391 except:392 log_file_out('æå¼jquery失败')393 dnd_str = ""394 try:395 f = open('{}\\config\\test.js'.format(path_dir), 'r', encoding='utf-8')396 line = f.readline()397 while line:398 dnd_str += line399 line = f.readline()400 except:401 log_file_out('æå¼jsæ件失败')402 # åæ¢é¦é¡µ403 check_home_page().click_more_btn(driver)404 time.sleep(1)405 check_home_page().click_different_more_btn(driver, [1,homepage_title[0]])406 time.sleep(2)407 # éªè¯æ´æ¢æ¨¡å408 check_home_page().click_more_btn(driver)409 time.sleep(1)410 check_home_page().click_different_more_btn(driver,[2])411 # éªè¯æ´æ¢æ¨¡åä¸æ¯å¦é½ä¸ºè®¡ç®å®æç模å412 try:413 success_count = 1414 for success_m in range(0, len(driver.find_elements_by_xpath('//tr/td[2]'))):415 if driver.find_elements_by_xpath('//tr/td[2]')[success_m].text not in success_model:416 success_count += 1417 break418 else:419 pass420 if success_count == 1:421 log_file_out('ä¿å模åä¸æ¨¡åé½ä¸ºè®¡ç®å®æ模å,éªè¯æå')422 else:423 log_file_out('ä¿å模åä¸æ¨¡åä¸é½ä¸ºè®¡ç®å®æ模å,éªè¯å¤±è´¥')424 except:425 log_file_out('è·åæ´æ¢æ¨¡åä¸æ¨¡åå表失败')426 # æ´æ¢æ¨¡åçé¢è§427 for model_m in ratio_model:428 time.sleep(2)429 try:430 # 移å¨å°æ¨¡åä½ç½®å¤431 target = driver.find_element_by_xpath('//span[text()=\'{}\']'.format(model_m))432 driver.execute_script("arguments[0].scrollIntoView();", target)433 time.sleep(1)434 Method(driver).click('xpath', '//span[text()=\'{}\']/../../../td[1]/div/div/span'.format(model_m))435 log_file_out('ç¹å»æ´æ¢æ¨¡åä¸æ¨¡åé¢è§æå')436 time.sleep(2)437 check_home_page().check_model_condition(driver, model_m)438 # ç¹å»åéæé®439 try:440 Method(driver).click('class', 'ivu-icon-md-arrow-back')441 log_file_out('ç¹å»æ´æ¢æ¨¡åä¸é¢è§çªå£åéæé®æå')442 except Exception as e:443 logger.error(e)444 log_file_out('ç¹å»æ´æ¢æ¨¡åä¸é¢è§çªå£åéæé®å¤±è´¥')445 except:446 log_file_out('ç¹å»æ´æ¢æ¨¡åä¸æ¨¡åé¢è§æå')447 time.sleep(1)448 # ç¹å»åæ¶æé®449 try:450 Method(driver).click('xpath', '//span[text()="åæ¶"]')451 log_file_out('ç¹å»æ´æ¢æ¨¡å页é¢ä¸åæ¶æé®æå')452 except:453 log_file_out('ç¹å»æ´æ¢æ¨¡å页é¢ä¸åæ¶æé®å¤±è´¥')454 for home_page in homepage_title:455 # åæ¢é¦é¡µ456 check_home_page().click_more_btn(driver)457 time.sleep(2)458 check_home_page().click_different_more_btn(driver,[1,home_page])459 time.sleep(2)460 if len(driver.find_elements_by_xpath('//span[text()="æ·»å "]')) != 0 or len(driver.find_elements_by_xpath('//span[text()="模åæ¡ä»¶"]')) != 0:461 log_file_out(home_page + '页é¢æå¼æå,éªè¯æå')462 # æ´æ¢æ¨¡å463 check_home_page().click_more_btn(driver)464 time.sleep(2)465 check_home_page().click_different_more_btn(driver,[2])466 time.sleep(2)467 if homepage_title.index(home_page) != 4:468 try:469 for model_m in ratio_model:470 Method(driver).click('xpath', '//span[text()=\'{}\']/../../../td[1]'.format(model_m))471 time.sleep(1)472 # å 为页é¢æ¯æ¼æ¥ç æ以ä¸ä¸ªcheckedä¼å¨é¡µé¢åºç°2次473 if len(driver.find_elements_by_class_name('ivu-radio-checked')) != 2:474 log_file_out(home_page + '页é¢æ´æ¢æ¨¡åä¸æ¨¡ååªè½åé,éªè¯å¤±è´¥')475 else:476 log_file_out(home_page + '页é¢æ´æ¢æ¨¡åä¸æ¨¡ååªè½åé,éªè¯æå')477 time.sleep(1)478 Method(driver).click('xpath', '//span[text()="ç¡®å®"]')479 log_file_out(home_page + '页é¢ç¹å»æ´æ¢æ¨¡åä¸ç¡®å®æé®æå')480 except Exception as e:481 logger.error(e)482 log_file_out(home_page + '页é¢ç¹å»æ´æ¢æ¨¡åä¸ç¡®å®æé®å¤±è´¥')483 else:484 try:485 for model_m1 in compare_model:486 # å¤æ模åæ¯å¦è¢«éä¸487 if 'ivu-checkbox-checked' in driver.find_element_by_xpath('//span[text()=\'{}\']/../../../td[1]/div/div/label/span'.format(model_m1)).get_attribute('class'):488 pass489 else:490 Method(driver).click('xpath', '//span[text()=\'{}\']/../../../td[1]'.format(model_m1))491 time.sleep(1)492 Method(driver).click('xpath', '//span[text()="ç¡®å®"]')493 log_file_out(home_page + '页é¢ç¹å»æ´æ¢æ¨¡åéªè¯æå')494 except Exception as e:495 logger.error(e)496 log_file_out(home_page + '页é¢ç¹å»æ´æ¢æ¨¡åéªè¯å¤±è´¥')497 time.sleep(5)498 if len(driver.find_elements_by_xpath('//span[text()="模åæ¡ä»¶"]')) != 0:499 # é置模åæ¡ä»¶500 check_home_page().click_more_btn(driver)501 time.sleep(2)502 check_home_page().click_different_more_btn(driver, [3])503 time.sleep(7)504 if len(driver.find_elements_by_xpath('//span[text()="模åæ¡ä»¶"]')) != 0:505 # 设置å¾è¡¨ä¸è½½è·¯å¾ä¸ºpictureä¸é¢çproduce_home_modelä¸506 produce_home_model_picture_path = os.path.dirname(507 __file__) + '\\' + 'picture' + '\\produce_home_model' + '\\' + home_page508 # å é¤æ件夹ä¸çææpngæ件 ç¡®ä¿æ¯ä¸æ¬¡æªçå¾æ¯ææ°çå¾509 if os.path.isdir(produce_home_model_picture_path) is True:510 picture_list = os.listdir(produce_home_model_picture_path)511 for l in picture_list:512 if l.endswith('.png'):513 os.remove(produce_home_model_picture_path + "\\" + l)514 else:515 os.mkdir(produce_home_model_picture_path)516 time.sleep(1)517 # æªå¾518 try:519 for btn_value in range(0, 3):520 # å¾å°è´¹ç¨æ é¢521 title_index_text = driver.find_elements_by_xpath('//*[@class="power-proDesc-faultTypeIco"]/..')[btn_value].text522 driver.find_elements_by_class_name('power-proDesc-faultTypeIco')[btn_value].click()523 time.sleep(2)524 driver.save_screenshot(525 produce_home_model_picture_path + '\\' + home_page + '_' + title_index_text526 + '.png')527 log_file_out('æªå' + home_page + '\'{}\'å¾è¡¨æå'.format(title_index_text))528 except:529 log_file_out('æªå' + home_page + 'å¾è¡¨å¤±è´¥')530 if homepage_title.index(home_page) == 0:531 # éªè¯æ»è´¹ç¨532 try:533 if float(driver.find_elements_by_class_name('power-proChart-title')[2].text.split(':')[1][:-2]) != 0:534 log_file_out(home_page+'æ»è´¹ç¨å¼ä¸ä¸º0,éªè¯æ£ç¡®')535 else:536 log_file_out(home_page + 'æ»è´¹ç¨å¼ä¸º0,éªè¯å¤±è´¥')537 except:538 log_file_out(home_page + 'æ»è´¹ç¨å¼éªè¯å¤±è´¥')539 try:540 # éªè¯å车æ»æ°541 car_sum = driver.find_element_by_tag_name('strong').text.split(' ')[0].split('ï¼')[-1]542 if float(car_sum) != 0:543 log_file_out('å车æ»æ°ä¸ä¸º0,éªè¯æå')544 else:545 log_file_out('å车æ»æ°ä¸º0,éªè¯å¤±è´¥')546 except:547 log_file_out('å车æ»æ°æ°ééªè¯å¤±è´¥')548 try:549 # éªè¯è¯ä¼°å¯¹è±¡æ°é550 fault_num = driver.find_element_by_tag_name('strong').text.split(' ')[1].split('ï¼')[-1]551 if fault_num != '':552 log_file_out('è¯ä¼°å¯¹è±¡æ°éä¸ä¸º0,éªè¯æå')553 else:554 log_file_out('è¯ä¼°å¯¹è±¡æ°é为0,éªè¯å¤±è´¥')555 except:556 log_file_out('è¯ä¼°å¯¹è±¡æ°ééªè¯å¤±è´¥')557 try:558 # éªè¯ç´¯è®¡è´¹ç¨559 money_num = driver.find_element_by_tag_name('strong').text.split(' ')[2].split('ï¼')[-1]560 if float(money_num) != 0:561 log_file_out('累计费ç¨ä¸ä¸º0,éªè¯æå')562 else:563 log_file_out('累计费ç¨ä¸º0,éªè¯å¤±è´¥')564 except:565 log_file_out('累计费ç¨éªè¯å¤±è´¥')566 #567 elif homepage_title.index(home_page) != 4:568 try:569 if \570 driver.find_element_by_xpath('//span[contains(text(),"模åå称")]/../span[1]').text.split(':')[571 1] != ratio_model[-1]:572 log_file_out(home_page + '页é¢æ´æ¢æ¨¡åå,模åå称æªåçæ¹å,éªè¯å¤±è´¥')573 else:574 log_file_out(home_page + '页é¢æ´æ¢æ¨¡åå,模åå称åçæ¹å,éªè¯æå')575 except:576 log_file_out(home_page + '页é¢æ´æ¢æ¨¡åå,模åå称æªåçæ¹å,éªè¯å¤±è´¥')577 # éªè¯ä¸å¼ å¾æ¯å¦éå¤578 picture_L = []579 for i in range(0, len(driver.find_elements_by_class_name('power-proChart-title'))):580 picture_L.append(driver.find_elements_by_class_name('power-proChart-title')[i].text[:3])581 # å»é582 picture_L = list(set(picture_L))583 if len(picture_L) != 3:584 log_file_out(home_page + 'æªåºç°æéçä¸å¼ å¾è¡¨,éªè¯å¤±è´¥')585 else:586 log_file_out(home_page + 'åºç°æéçä¸å¼ å¾è¡¨,éªè¯æå')587 # éªè¯æ¨¡åæ¡ä»¶588 Method(driver).click('xpath', '//span[text()="模åæ¡ä»¶"]')589 time.sleep(2)590 check_home_page().check_model_condition(driver, '')591 # ç¹å»å
³éæé®592 check_home_page().click_close_but(driver)593 time.sleep(2)594 try:595 Method(driver).click('xpath', '//span[text()="èªå®ä¹è®¡ç®æ¡ä»¶"]')596 except Exception as e:597 log_file_out('ç¹å»èªå®ä¹è®¡ç®æ¡ä»¶æé®å¤±è´¥')598 logger.error(e)599 time.sleep(2)600 # ç¹å»å¤ä½æé®601 if len(driver.find_elements_by_xpath('//span[text()="å¤ä½"]')) != 0:602 Method(driver).click('xpath', '//span[text()="å¤ä½"]')603 else:604 pass605 time.sleep(1)606 try:607 # å®ä½ç¬¬ä¸ä¸ªæå¨çæ¹å608 block = driver.find_elements_by_class_name('el-slider__button')[0]609 # æå¨æ¹å610 move_to_gap(driver, block, get_track(50))611 time.sleep(2)612 # æå¨å®ç¬¬ä¸ä¸ªæ¹åçä½ç½®613 first_block_place = driver.find_elements_by_class_name('showCurMes')[0].text614 except:615 log_file_out('æå¨å¼å§ä½ç½®æ¹å失败')616 try:617 # å®ä½ç¬¬äºä¸ªæå¨çæ¹å618 second_block = driver.find_elements_by_class_name('el-slider__button')[1]619 # æå¨ç¬¬äºä¸ªæ¹å620 move_to_gap(driver, second_block, get_track(50))621 time.sleep(2)622 # æå¨å®ç¬¬äºä¸ªæ¹åçä½ç½®623 second_block_place = driver.find_elements_by_class_name('showCurMes')[1].text624 # ç¹å»è¿ç¨æ¤èå´625 Method(driver).click('xpath', '//span[text()="è¿ç¨æ¤èå´"]')626 except:627 log_file_out('æå¨ç»æä½ç½®æ¹å失败')628 time.sleep(5)629 # è·å页é¢ä¸çå½åéç¨630 try:631 now_start = driver.find_element_by_xpath('//span[contains(text(),"模åå称")]/../span[3]').text.split(':')[1].split('~')[0]632 now_end = driver.find_element_by_xpath('//span[contains(text(),"模åå称")]/../span[3]').text.split(':')[1].split('~')[1]633 if now_start == first_block_place and now_end == second_block_place:634 log_file_out('页é¢ä¸ç模åæ¡ä»¶éçèªå®ä¹æ¡ä»¶ä¸èªå®ä¹èå´çæ¹ååçæ£ç¡®çæ¹å,éªè¯æå')635 else:636 log_file_out('页é¢ä¸ç模åæ¡ä»¶éçèªå®ä¹æ¡ä»¶ä¸èªå®ä¹èå´çæ¹å没æåçæ£ç¡®çæ¹å,éªè¯å¤±è´¥')637 except:638 log_file_out('页é¢ä¸ç模åæ¡ä»¶è·å失败,æ æ³éªè¯æ¹åèå´é¡µé¢ä¸æ¡ä»¶æ¯å¦åçæ¹å')639 # åç¹å»æ¨¡åæ¡ä»¶çæ¯å¦æ¤èå´æ¯å¦å¯¹æ¨¡åæ¡ä»¶äº§çå½±å640 try:641 Method(driver).click('xpath', '//span[text()="模åæ¡ä»¶"]')642 time.sleep(2)643 # 模åæ¡ä»¶644 model_conditon = driver.find_elements_by_class_name('power-preWrapper-title')[0].text645 # è·åéç¨/æ¶é´ä¿¡æ¯646 if driver.find_element_by_xpath('//span[contains(text(),"模åå称")]/../span[3]').text.split(':')[0][-2:] == 'æ¶é´':647 # å¤ææ¯å¦å¤§äº10648 if int(driver.find_element_by_xpath('//p[@class="power-preCase-row"]/span[1]').text[:7].split('-')[1]) >= 10:649 start_condition = driver.find_element_by_xpath(650 '//p[@class="power-preCase-row"]/span[1]').text[:7]651 end_condition = driver.find_element_by_xpath(652 '//p[@class="power-preCase-row"]/span[2]').text[:7]653 else:654 start_condition = driver.find_element_by_xpath(655 '//p[@class="power-preCase-row"]/span[1]').text[:7].split('-')[0] + '-' + \656 driver.find_element_by_xpath(657 '//p[@class="power-preCase-row"]/span[1]').text[:7].split('-')[1][1:2]658 end_condition = driver.find_element_by_xpath(659 '//p[@class="power-preCase-row"]/span[2]').text[:7].split('-')[0] + '-' + \660 driver.find_element_by_xpath(661 '//p[@class="power-preCase-row"]/span[2]').text[:7].split('-')[1][1:2]662 else:663 start_condition = re.findall(r'\d+', driver.find_element_by_xpath(664 '//p[@class="power-preCase-row"]/span[1]').text)665 end_condition = re.findall(r'\d+', driver.find_element_by_xpath(666 '//p[@class="power-preCase-row"]/span[2]').text)667 if first_block_place == start_condition:668 log_file_out('å¼å§æ¡ä»¶å¤,æ¹å{}èå´æ¨¡åæ¡ä»¶ä¸åçæ£ç¡®çæ¹å,éªè¯æå'.format(model_conditon))669 else:670 log_file_out('å¼å§æ¡ä»¶å¤,æ¹å{}èå´æ¨¡åæ¡ä»¶ä¸æªåçæ£ç¡®çæ¹å,éªè¯å¤±è´¥'.format(model_conditon))671 if second_block_place == end_condition:672 log_file_out('ç»ææ¡ä»¶å¤,æ¹å{}èå´æ¨¡åæ¡ä»¶ä¸åçæ£ç¡®çæ¹å,éªè¯æå'.format(model_conditon))673 else:674 log_file_out('ç»ææ¡ä»¶å¤,æ¹å{}èå´æ¨¡åæ¡ä»¶ä¸æªåçæ£ç¡®çæ¹å,éªè¯å¤±è´¥'.format(model_conditon))675 except:676 log_file_out('è·å\'{}\'页é¢æ¨¡åæ¡ä»¶ä¸éç¨/æ¥æä¿¡æ¯å¤±è´¥,æ æ³éªè¯æ¹åèå´æ¯å¦ä¼å½±å模åæ¡ä»¶'.format(home_page))677 check_home_page().click_close_but(driver)678 time.sleep(2)679 if homepage_title.index(home_page) == 4:680 Method(driver).click('class', 'more-modal-info-title')681 time.sleep(1)682 # éªè¯æ¨¡åå称683 compare_count = 1684 for compare_model_name in range(0,len(driver.find_elements_by_xpath('//span[contains(text(),"èµ·æ¢")]/..'))):685 com_model_name = driver.find_elements_by_xpath('//span[contains(text(),"èµ·æ¢")]/..')[compare_model_name].text.split(' ')[0]686 if com_model_name not in compare_model:687 compare_count += 1688 break689 else:690 pass691 if compare_count == 1:692 log_file_out('æ´æ¢æ¨¡åå,模åå称ä¸éæ©ç模åä¸è´,éªè¯æ£ç¡®')693 else:694 log_file_out('æ´æ¢æ¨¡åå,模åå称ä¸éæ©ç模åä¸ä¸è´,éªè¯å¤±è´¥')695 # æ¶èµ·æ¨¡åå称ä¸ææ¡696 Method(driver).click('class', 'more-modal-info-title')697 # ç¹å¼è´¹ç¨æé®698 try:699 Method(driver).click('id','div1')700 time.sleep(1)701 except:702 log_file_out('ç¹å»è´¹ç¨æé®å¤±è´¥')703 # éªè¯ææ½704 try:705 for cost_classify in range(0,len(driver.find_elements_by_id('div'))):706 # ææ½åå称707 drop_name = driver.find_elements_by_id('div')[cost_classify].text708 try:709 driver.execute_script(jquery_str + dnd_str + "$('.%s').simulateDragDrop({ dropTarget: '#%s'});" % ('box > div:nth-child({})'.format(cost_classify+1), 'ondrop > div:nth-child(2)'))710 log_file_out('ææ½\'{}\'æå'.format(drop_name))711 except:712 log_file_out('ææ½\'{}\'失败'.format(drop_name))713 # driver.save_screenshot(produce_home_model_picture_path + '\\' + home_page + '_' + drop_name714 # + '.png')715 time.sleep(2)716 try:717 # ç¹å»å
³é718 driver.find_element_by_xpath('//span[text()=\'{}\']/i'.format(drop_name)).click()719 log_file_out('å
³é\'{}\'æå'.format(drop_name))720 except:721 log_file_out('å
³é\'{}\'失败'.format(drop_name))722 time.sleep(1)723 except:724 log_file_out('ææ½è´¹ç¨ææ½å¤±è´¥,éªè¯å¤±è´¥')725 # ç¹å¼å
³éè´¹ç¨æé®726 check_home_page().click_close_but(driver)727 try:728 # 对æ¯æ¨¡åç模åæ¡ä»¶729 Method(driver).click('xpath', '//span[text()="模åæ¡ä»¶"]')730 time.sleep(2)731 except:732 log_file_out(home_page+'ç¹å»æ¨¡åæ¡ä»¶æé®å¤±è´¥')733 # æ¶é´/éç¨734 try:735 for compare_con in range(0, len(driver.find_elements_by_class_name('power-multi-tr')[736 1].find_elements_by_class_name(737 'power-multi-child'))):738 if \739 driver.find_elements_by_class_name('power-multi-tr')[1].find_elements_by_class_name(740 'power-multi-child')[compare_con].text != '':741 log_file_out('对æ¯åè½ç¬¬{}个模åæ¶é´/éç¨æ¡ä»¶ä¸ä¸ºç©º,éªè¯æå'.format(compare_con))742 else:743 log_file_out('对æ¯åè½ç¬¬{}个模åæ¶é´/éç¨æ¡ä»¶ä¸ºç©º,éªè¯å¤±è´¥'.format(compare_con))744 except:745 log_file_out('对æ¯åè½ç¬¬æ¶é´/éç¨æ¡ä»¶éªè¯å¤±è´¥')746 try:747 # ç¹å»è½¦å748 driver.find_elements_by_class_name('power-multi-icoMore')[0].click()749 time.sleep(1)750 for compare_car in range(0, len(driver.find_elements_by_class_name('power-multi-trainTypeTag'))):751 driver.find_elements_by_class_name('power-multi-trainTypeTag')[compare_car].click()752 time.sleep(1)753 if driver.find_elements_by_class_name('power-multi-trainNoRow')[754 compare_car].text != '':755 log_file_out('对æ¯åè½ç¬¬{}个模å车åæ¡ä»¶ä¸ä¸ºç©º,éªè¯æå'.format(compare_car+1))756 else:757 log_file_out('对æ¯åè½ç¬¬{}个模å车åæ¡ä»¶ä¸ºç©º,éªè¯å¤±è´¥'.format(compare_car+1))758 time.sleep(1)759 driver.find_elements_by_class_name('power-multi-trainTypeTag')[compare_car].click()760 except:761 log_file_out('对æ¯æ¨¡å车å车å·éªè¯å¤±è´¥')762 try:763 # ç¹å»é¨ä»¶764 driver.find_elements_by_class_name('power-multi-icoMore')[2].click()765 time.sleep(1)766 for compare_fault in range(0,767 len(driver.find_elements_by_class_name('ivu-tree-arrow'))):768 driver.find_elements_by_class_name('ivu-tree-arrow')[compare_fault].click()769 time.sleep(1)770 if driver.find_elements_by_class_name('power-preFault-col')[compare_fault] != '':771 log_file_out('对æ¯åè½ç¬¬{}个模åæåæ¡ä»¶ä¸ä¸ºç©º,éªè¯æå'.format(compare_fault+1))772 else:773 log_file_out('对æ¯åè½ç¬¬{}个模åæåæ¡ä»¶ä¸ºç©º,éªè¯å¤±è´¥'.format(compare_fault+1))774 time.sleep(1)775 driver.find_elements_by_class_name('ivu-tree-arrow')[compare_fault].click()776 except:777 log_file_out('å¤æ¨¡åæåéªè¯å¤±è´¥')778 try:779 # éªè¯æ¨¡åå
±åæ¡ä»¶780 Method(driver).click('xpath', '//span[contains(text(),"模åå
±åæ¡ä»¶")]')781 time.sleep(2)782 # å
±åæ¡ä»¶783 compare_common = driver.find_elements_by_class_name('power-pre-wrapper')[0].text784 log_file_out('对æ¯æ¨¡å,å
±å模åæ¡ä»¶ä¸º' + compare_common)785 except:786 log_file_out('对æ¯æ¨¡å,å
±å模åæ¡ä»¶éªè¯å¤±è´¥')787 # ç¹å»åéæé®788 try:789 Method(driver).click('class','ivu-icon-md-arrow-back')790 time.sleep(1)791 except:792 pass793 # ç¹å»å
³éæé®794 check_home_page().click_close_but(driver)795 else:796 log_file_out('\'{}\'éæ°è®¡ç®æ¨¡å失败,页é¢æªæå¼,éªè¯å¤±è´¥'.format(home_page))797 pass798 else:799 log_file_out(home_page + '页é¢æ´æ¢æ¨¡åå,模å计ç®å¤±è´¥,éªè¯å¤±è´¥')...
blog_tests.py
Source:blog_tests.py
...15 test["test"]()16 except:17 e = sys.exc_info()[0]18 print("ERROR: " + e.__name__ + " at " + test["name"])19 def check_home_page(self):20 self.browser.get(self.base_url)21 assert "John Roach" in self.browser.title22 def check_pages(self):23 self.browser.get(self.base_url)...
setup.py
Source:setup.py
2import logging3from helpers.seleniumHelper import selenium_click4def setup_function():5 logging.info("setup function , check test init state")6 check_home_page()7def teardown_function():8 logging.info("end test, go to site initial state ")9 selenium_click(pytest.locator_config.get('Locators', 'ebay.logo.link'))10 check_home_page()11def check_home_page():12 url = pytest.driver.current_url13 logging.info("current url is " + url)14 try:15 assert url == pytest.config_file.get("system", "url")16 except:17 logging.error("url should be : " + pytest.config_file.get("system", "url") + " instead we have " + url)18"""19def teardown_session():20 logging.info("end tests")...
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!!