python webdriver測試報告

2021-06-29 12:29:59 字數 1607 閱讀 3440

即將開始一系列的自動化專案實踐,很多公共類和屬性都需要提前搞定。今天,解決了測試報告的一些難題,參照了很多博文,最終覺得htmltestrunner非常不錯,自己也研讀了原始碼,可進行一些自定義的配置。

下面就說一些體會:

一、配置:

htmltestrunner看了原始碼才知道作者是:wai yip tung.到底這是哪位大神就不做深究了,至少我很敬佩。

2、將該檔案儲存在python安裝路徑下的lib資料夾中。在檔案中能import htmltestrunner成功,即配置成功。

注:如果失敗,在專案中新建乙個這樣的檔案也是可以的,只要達到能引入和使用就行。

二、使用

引入完成後,在呼叫測試檔案中加入如下**即可:

if __name__ == '__main__':

testunit=unittest.testsuite()  

#定義乙個單元測試容器

testunit.addtest(element("test_find_element"))  

#將測試用例加入到測試容器中

testunit.addtest(element("test_search"))

filename="./***.html"  

#定義個報告存放路徑,支援相對路徑。

fp=file(filename,'wb')

runner = htmltestrunner.htmltestrunner(stream=fp,title='report_title',description='report_description')  

#使用htmltestrunner配置引數,輸出報告路徑、報告標題、描述

runner.run(

testunit) #自動進行測試

生成報告如下:

element:單元測試類名

test_find_element:測試用例方法名

詳細資訊:測試用例方法中print的資料、出錯後資訊。

if

__name__ == "

__main__":

#定義乙個單元測試容器

testunit=unittest.testsuite()

#將測試用例加入到測試容器中

testunit.addtest(測試類名("

testunit.addtest(測試類名(

"test_google"))

#定義個報告存放路徑,支援相對路徑

filename = '

g:\\seleniums\\result.html

'fp = file(filename, 'wb'

)#定義測試報告

runner =htmltestrunner.htmltestrunner(stream=fp,title=u'

測試報告

',description=u'

用例執行詳情::')

#執行測試用例

runner.run(testunit)

Python Webdriver常用函式

載入瀏覽器驅動 webdriver.firefox 開啟頁面 get 關閉瀏覽器 quit 最大化視窗 maximize window 設定視窗引數 set window size 600,800 後退到前一頁 back 前進到後一頁 forward 重新整理頁面 refresh 元素定位 清除文字...

二 Python WebDriver環境搭建

在命令列中輸入 顯示安裝成功 1.selenium預設為firefox。驗證 2from selenium import webdriver 34 driver webdriver.firefox 5 將控制的webdriver的firefox賦值給driver 獲得了瀏覽器物件才可以啟動瀏覽器,開...

七 HTMLTestRunner生成測試報告

coding utf 8 created on 2019 01 21 author codeali import os import unittest import time import logging from lib import pathdeal from lib import log fr...