python selenium 测试报告怎么写,python+selenium 生成测试报告

python+selenium 做web自动化测试,生成测试报告

需要用到的selenium webdriver,HTMLTestRunner,unittest

例如:

from selenium import webdriver

import unittest

import time

import HTMLTestRunner

class test_class(unittest.TestCase):

def setUp(self):

self.verificationErrors=[]

self.test=webdriver.Ie()

self.url="http://go.rritw.com/192.168.0.39"

def test_login(self):

pa=self.test

pa.get(self.url)

user=pa.find_element_by_id('username')

user.send_keys('system')

passwd=pa.find_element_by_id('password')

passwd.send_keys('123456')

pa.execute_script('loginsubmit()')

time.sleep(10)

def tearDown(self):

pass

if __name__=="__main__":

testsuite=unittest.TestSuite()

testsuite.addTest(test_class("test_login"))

filename="e:\\result.html"

fp=file(filename,'wb')

runner=HTMLTestRunner.HTMLTestRunner(stream=fp,title='Result',description='Test_Report')

runner.run(testsuite)

生成的测试报告截图

0818b9ca8b590ca3270a3433284dd417.png

请教高手:我想在一个文件夹下面利用现有的图片和txt文字生成一个html文件,但是这个html的样式要设计成动态的利用python脚本控制生成。谢谢!

比如很简单的,可以这样:

# -*- coding:utf-8 -*-

import os,sys

html = open('index.html', 'w')

html.write("""

Test

""")

files = os.listdir('.')

# 首先处理文本

for f in files:

if f.lower().endswith('.txt'):

fp = open(f)

content = fp.read()

fp.close()

html.write("

%s

" % content)

# 然后处理图片

for f in files:

if f.lower().endswith('.jpg') or f.lower().endswith('.png'):

html.write("%s" % f)

html.write('')

html.close()

把这个python代码放在有图片和txt文本的目录里,运行就可以了。如果不是jpg,修改增加png,gif就行了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值