【Python】UI自動化-1

來源:互聯網
上載者:User

標籤:ESS   應用   utf-8   自動化指令碼   enc   不能   執行   產生   瀏覽器   

一、安裝selenium和環境配置

1 pip install selenium

2 三個驅動檔案放到d:盤根目錄

3 安裝Firefox版本33

4 安裝外掛程式:selenium ide\firebug\firepath

5 下載三個Py程式,分別修改,將路徑設定為三個驅動檔案所在的路徑,然後分別執行,看看是否可以開啟瀏覽器,顯示搜狗頁面,有一個能成功即可

 

【踩坑】

IE瀏覽器的話需要設定

1、  縮放100%

2、  全勾選或者全不勾選

 

二、自動化測試1、自動化測試優勢:(1)重複多次執行時節省時間,提高測試覆蓋率(2)自動化迴歸(3)正常化過程(4)曆史文檔記錄2、自動化測試局限性:(1)只能發現15%的bug(2)不能提高測試有效性,只能提高效率(3)不具想象力,沒人聰明(4)不能取代手工測試3、自動化測試的內容:(1)測試資料自動產生(2)自動化輸入(3)測試結果自動比較(4)測試自動執行(5)測試案例的管理(6)線上監控4、自動化指令碼技術:(1)線性指令碼(2)結構化指令碼(3)共用指令碼(4)資料驅動指令碼(5)關鍵字驅動指令碼資料驅動指令碼樣本:程式不變資料變data.txt:e:\\a.txte:\\1.html main.py:#encoding=utf-8 with open("data.txt") as fp:    for i in fp:        with open(i.strip()) as fp1:            print fp1.read()  關鍵字驅動腳本樣本:通過資料檔案中的關鍵字,調用另一個檔案中的函數,實現某個功能。 將測試邏輯按照這些關鍵字進行分解,形成資料檔案,用關鍵字的形式將測試邏輯封裝在資料檔案中,測試載入器只要能夠解釋這些關鍵字即可對其應用自動化 #練習:(1)將data.txt檔案中op作為關鍵字,調用kd.py中的op()方法讀取1.txt檔案中的所有內容;(2)將data.txt檔案中第二、三行資料用","區分,write和read作為操作類型;e:\\test4\\...作為操作路徑;w和r作為操作許可權;"glory road is good!"為寫入內容;kd.py:#encoding=utf-8def op():    with open("e:\\test4\\1.txt") as fp:        print fp.read() def write(file_path,mode,content):    with open(file_path,mode) as fp1:        fp1.write(content) def read(file_path,mode):    with open(file_path,mode) as fp2:        print fp2.read() kd2.py:#encoding=utf-8from kd import * with open("e:\\test4\\data.txt") as fp:    for i in fp:        if i.find(",")!=-1:            prams=i.strip().split(",")            if len(prams)==4:                command=prams[0]+"(\""+prams[1]+"\",\""+prams[2]+"\",\""+prams[3]+"\")"                print command                eval(command)             if len(prams)==3:                command=prams[0]+"(\""+prams[1]+"\",\""+prams[2]+"\")"                print command                eval(command)        else:            prams=i.strip()            command=prams+"()"            print command            eval(command) data.txt:opwrite,e:\\a.txt,w,glory road is good!read,e:\\a.txt,r 1.txt:Process-2:2018-03-31 15:02:31glory road is good! 

 

5、使用自動化的一些典型情境:(1)大量的迴歸測試(2)注入測試資料(3)敏捷開發的TDD模式,行為驅動開發模式(4)機械並繁瑣的測試(5)業務監控6、自動化術語:(1)架構:整個或部分系統的可重用設計,可以看做是一種應用骨架(2)關鍵字驅動的自動化測試:主要包括被操作對象、操作和值

【Python】UI自動化-1

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.