How to use check_home_page method in tempest

Best Python code snippet using tempest_python

homemodel_check.py

Source:homemodel_check.py Github

copy

Full Screen

...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 + '页面更换模型后,模型计算失败,验证失败')...

Full Screen

Full Screen

blog_tests.py

Source:blog_tests.py Github

copy

Full Screen

...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)...

Full Screen

Full Screen

setup.py

Source:setup.py Github

copy

Full Screen

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")...

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 tempest 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