Python+selenium
来源:互联网 发布:祖龙娱乐 知乎 编辑:程序博客网 时间:2024/05/23 19:20
#coding=utf-8import csv #导入scv库,可以读取csv文件from selenium import webdriverimport unittestfrom time import sleepimport timeimport osimport sysimport MySQLdbmy_file=''dr=webdriver.Chrome()class test(unittest.TestCase): def test_login(self): data=csv.reader(open(my_file,'r')) for user in data: dr.get('https://passport.cnblogs.com/user/signin') dr.find_element_by_id('input1').clear() dr.find_element_by_id('input1').send_keys(user[0]) dr.find_element_by_id('input2').clear() dr.find_element_by_id('input2').send_keys(user[1]) dr.find_element_by_id('signin').click() sleep(1) print ('\n'+'测试项:'+user[2]) dr.get_screenshot_as_file('D:/report/'+user[3]+".jpg") try: assert dr.find_element_by_id(user[4]).text try: error_message = dr.find_element_by_id(user[4]).text self.assertEqual(error_message,user[5]) print('提示信息正确!预期值与实际值一致:') print('预期值:'+user[5]) print('实际值:'+error_message) except: print ('提示信息错误!预期值与实际值不符:') print ('预期值:'+user[5]) print('实际值:'+error_message) except: print ('提示信息类型错误,请确认元素名称是否正确!') def tearDown(self): dr.quit()def run(): from HTMLTestRunner import HTMLTestRunner import time flag=True report_title = u'登陆模块测试报告' desc = u'登陆模块测试报告详情:' date=time.strftime("%Y%m%d") time=time.strftime("%Y%m%d%H%M%S") path= 'D:/report/'+time+"/" report_path = path+"report.html" if not os.path.exists(path): os.makedirs(path) else: pass #定义一个测试容器 testsuite = unittest.TestSuite() #将测试用例添加到容器 testsuite.addTest(test("test_login")) fp=open(report_path,'wb') runner = HTMLTestRunner(stream=fp, title=report_title, description=desc) try: runner.run(testsuite) except Exception: flag==False return flag,report_path report.close() dr.quit()if __name__=='__main__': conn=MySQLdb.connect(host="x.x.x.x",user="xxxx",passwd="xxxx",db="test",charset="utf8") cursor=conn.cursor() cursor.execute("select attachment from datapool_manage where id="+sys.argv[-1]) result=cursor.fetchone() cursor.execute("insert into table sit_script values(26,"yanzhengjiaoben","ceshifuwuqi","logpath","ceshi","ceshi",1,2,0,)") my_file=result[0] print(run())
阅读全文
0 0
- Selenium python
- python selenium
- python+selenium
- python + selenium
- Python Selenium
- python selenium
- Python selenium
- python+selenium
- selenium-python
- Python selenium
- Python+selenium
- Python+selenium
- python+selenium
- Python selenium
- python selenium
- Python+selenium
- python中使用selenium
- Python + Selenium环境搭建
- Java技术常用的设计模式(一)--- 策略模式
- 键盘码、ASCII码表
- 多线程交替打印ABC的多种实现方法
- memcache的介绍,应用场景,优缺点和常见问题
- YOLO的安装与学习
- Python+selenium
- 对象、对象引用、实例
- 【理论实践】用alignas代替#pragma pack
- PHP根据经纬度获取地址信息
- 实用插件(五)弹出操作提示框artdialog
- x86汇编语言(五)
- Celery任务队列
- android——Glide框架总结笔记
- 【DL--18】Windows下基于Anaconda的Tensorflow环境配置