python3.5+selenium3.4自動化測試8_selenium框架1.0

框架1.0

(這邊說的框架1.0,其實不是測試框架,是學(xué)習(xí)框架,在學(xué)習(xí)每個工具我們都要定一個目標(biāo),分解目標(biāo),每個小目標(biāo)應(yīng)該有自己的一個學(xué)習(xí)框架,先學(xué)習(xí)掌握什么,后優(yōu)化學(xué)習(xí)目標(biāo),從學(xué)習(xí)框架1.0到2.0,3.0等方向不斷完善,最后就是變成一個完整的學(xué)習(xí)框架,也是完整的測試框架,后期將繼續(xù)分享框架2.0,3.0等文章,關(guān)注我的簡書或微信公眾號:無敵輕車)

1.安裝python和selenium測試環(huán)境,安裝瀏覽器的webdriver

參照之前寫的文章:

安裝測試環(huán)境

2.了解webdriver的API

參照之前寫的文章:

webdriver API上

webdriver API下

3.大量練習(xí)(通過下面簡單的框架形式進(jìn)行大量練習(xí),把用例寫成多個py文件,然后批量執(zhí)行)

from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select

driver = webdriver.Chrome()
driver.maximize_window()
driver.get("http://192.168.1.131/")
try:
    #填寫用戶名
    driver.find_element_by_id("username").send_keys("admin")
    time.sleep(1)
    #填寫密碼
    driver.find_element_by_id("secret").send_keys("password1")
    Select(driver.find_element_by_id('language')).select_by_value("zh_CN")
    driver.find_element_by_id("login_button").click()
    time.sleep(1)



    # print(browser.title)
    time.sleep(10)
except:
    driver.get_screenshot_as_file(u"D:/python/selenium/error_png/1.login/1.5/%s.png" % datetime.now().strftime("%Y%m%d.%H%M%S.%f")[:-3])

driver.quit()

4.批量執(zhí)行

import os,sys

#os.listdir返回指定路徑下所有文件夾列表
#所在 py 文件運行一次后會生成一個 pyc 的副本
casesuit=os.listdir('D:\\python\\selenium\\test_case\\backup')
print(casesuit)
for file in casesuit:

    s=file.split('.')[1]
    print(s)
    #選取后綴名為 py 的文件
    if s=='py':
    #此處執(zhí)行 dos 命令并將結(jié)果保存到 log.txt
        os.system('D:\\python\\selenium\\test_case\\backup\\%s 1>>log.txt 2>&1'%a)
-----------------------------------------------------分割線-----------------------------------------------------

用實際用例代碼長期更新,介紹selenium使用中的知識小點,希望大家關(guān)注,給予鼓勵贊賞

關(guān)注微信公眾號:無敵輕車

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容