pytest使用總結(jié)

文件命名

必須以test_xxxx.py命名文件名

每一個測試用例要以test_xxx命令方法的名字

'''
def test_coure():
'''


image.png

.成功
F失敗

跳過測試用例
@pytest.mark.skip(reason="input your skip reason")

'''

創(chuàng)建多個py文件是為了區(qū)分(分割)不同的類型的測是用例(不同類型的功能模塊)

def test_sy():
shouye = ("text","首頁")
sygh = ("text","生涯規(guī)劃")
sykt = ("text","生涯課堂")
kc_id = ("id","com.znb.zxx:id/tv_title") # 生涯課堂中課程
find_element(driver,shouye).click()
find_element(driver,sygh).click()
# find_element(driver,sykt).click()
try:
assert is_element_exist(driver,sykt) == True
print("進入生涯首頁成功")
except:
print("進入生涯首頁失敗")
find_element(driver,sykt).click()
try:
assert is_element_exist(driver,kc_id) == True
print("生涯課程執(zhí)行成功")
except:
print("生涯課程執(zhí)行失敗")

def test_course_details():
kc_id = ("id","com.znb.zxx:id/tv_title")
mf_course = ("text","免費領(lǐng)取")
find_element(driver,kc_id).click()
find_element(driver,mf_course).click()
try:
assert is_element_exist(driver,mf_course) == False
print("領(lǐng)取免費課程成功")
except:
print("沒找到免費課程按鈕")
'''

Allure測試報告

1安裝并配置allure環(huán)境變量
2安裝allure-pytest插件
3 執(zhí)行測試腳本,并生成測試結(jié)果pytest ./ --alluredir=result
4 把測試結(jié)果編譯成網(wǎng)頁測試報告 allure generate result –o report --clean
5 打開測試報告 allure open -h 127.0.0.1 -p 10866 report


image.png

用法:
pytest test_demo.py --alluredir ./result
conftest.py 文件名是固定的 在里面寫入的方法 其他文件調(diào)用的時候不需要from XXX import xxx

import pytest


@pytest.mark.parametrize("arg_1,arg_2,arg_3", [(4399,4000,399),(2011,2000,11)])
def test_add_by_func_aaa(arg_1,arg_2,arg_3):
    assert  arg_1 == arg_2 + arg_3


最后編輯于
?著作權(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ù)。

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