Python+selenium

#coding=utf-8

import csv   #导入scv库,可以读取csv文件
from selenium import webdriver
import unittest
from time import sleep
import time
import os
import sys
import MySQLdb

my_file=' '
driver=webdriver.Chrome()

class test(unittest.TestCase):
    def test_login(self):
    
        data=csv.reader(open(my_file,'r'))
       
        for user in data:
            driver.get('https://login.bce.baidu.com/')
     
            driver.find_element_by_id('TANGRAM__PSP_4__userName').send_keys(user[0])
           
            driver.find_element_by_id('TANGRAM__PSP_4__password').send_keys(user[1])
            
            driver.find_element_by_id('TANGRAM__PSP_4__submit').click()
            
                
    def tearDown(self):
        driver.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,脚本结束
    report.close()
    
    #关闭浏览器
    driver.quit()

if __name__=='__main__':
    conn=MySQLdb.connect(host="x.x.x.x",user="xxx",passwd="xxxx",db="test",charset="utf8")
    cursor=conn.cursor()
    
    
    cursor.execute("select attachment from datapool_manage where id="+sys.argv[-1])
    

    result=cursor.fetchone()
    my_file=result[0]


  

    cursor.close()
    print(run())

猜你喜欢

转载自blog.csdn.net/xjtlzl/article/details/77332147