标签:from consul 按钮 pass \n sre firefox 退出 截图
# coding:utf-8 ‘‘‘
dinghanhua
客服按钮验证脚本 ‘‘‘ from selenium import webdriver import time test_domain = ‘http://testurl‘ #测试域名 product_domain = ‘http://producturl‘ #线上域名 domain = product_domain #方便切换环境
url = domain+‘/testurl‘ #测试地址
consult_url = ‘http://consulturl‘ #客服按钮跳转地址 dr = webdriver.Chrome() #dr = webdriver.Firefox() #兼容性测试 #dr = webdriver.Ie() #兼容性测试 dr.get(domain) #先访问域名,写入cookie dr.add_cookie({‘name‘:‘loginstring‘,‘value‘: ‘loginvalue‘}) time.sleep(2) dr.get(url) #再访问测试地址 time.sleep(2) try: popconsult = dr.find_element_by_id(‘popconsult‘) #验证客服按钮是否显示 if popconsult.is_displayed(): print(domain,‘显示有咨询按钮,pass‘) else: print(domain,‘未显示咨询按钮,fail‘) dr.get_screenshot_as_file(‘D:/未显示咨询按钮.png‘) #下拉滚动条仍显示在页面 js = ‘document.documentElement.scrollTop=1000‘ dr.execute_script(js) time.sleep(1) popconsult = dr.find_element_by_id(‘popconsult‘) if popconsult.is_displayed(): print(‘滚动之后显示正常 pass‘) else: print(‘滚动之后未显示在页面范围内 fail。‘) dr.get_screenshot_as_file(‘D:/滚动之后未显示在页面范围内.png‘) #验证客服按钮点击跳转地址是否正确
js = ‘document.documentElement.scrollTop = 0‘
dr.execute_script(js)
time.sleep(1)
popconsult = dr.find_element_by_id(‘popconsult‘) popconsult.click() time.sleep(2)
current_window = dr.current_window_handle handles = dr.window_handles for handle in handles: if handle != current_window: dr.switch_to.window(handle) if dr.current_url == consult_url: print(‘地址正确,pass‘) else: print(‘地址错误,fail.当前地址:‘,dr.current_url) except Exception as e: print(‘发生异常,截图:D:/客服按钮异常.png。\n‘,e) dr.get_screenshot_as_file(‘D:/客服按钮异常.png‘) finally: #退出 dr.quit()
标签:from consul 按钮 pass \n sre firefox 退出 截图
原文地址:https://www.cnblogs.com/dinghanhua/p/10009135.html