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://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)

生成的测试报告截图


已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页