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=''
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())
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值