<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                >[info] 本章節,將在測試代碼中結合Allure,輸出美觀的測試報告 > [TOC] ## Allure測試報告介紹 Allure是一款非常輕量級并且非常靈活的開源測試報告生成框架。 它支持絕大多數測試框架, 例如TestNG、Pytest、JUint等 官網地址:[https://docs.qameta.io/allure/](https://docs.qameta.io/allure/) ## Pytest框架集成Allure ### 安裝 allure-pytest 通過allure-pytest,我們可以**生成Allure2所需要的用于生成測試報告的數據**。 ```cmd pip install allure-pytest ``` ### 改造Pytest的測試用例 為了使用Allure生成報告,需要在conftest.py和測試腳本中加入Allure特性。 下面直接用前面的項目為例,直接介紹如何將Allure應用到自己的測試項目中。 * 首先將環境信息,放到公共fixture中,改造后 `conftest.py`如下: ```python from selenium import webdriver import pytest @pytest.fixture() def get_driver(request): # 創建Chrome驅動實例,這里創建driver時,傳入chrome_options參數,告訴服務器,我是用移動端瀏覽器訪問的。 options = webdriver.ChromeOptions() options.add_argument('User-Agent=Mozilla/5.0 (Linux; U; Android 4.0.2; en-us; Galaxy Nexus Build/ICL53F) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30') driver = webdriver.Chrome(chrome_options=options) # 設置瀏覽器大小,讓它看起來跟手機的樣式差不多。 driver.set_window_size("380", "680") # 設置一個全局的等待超時時間 10s driver.implicitly_wait(10) def fin(): driver.quit() request.addfinalizer(fin) return driver ``` * 改造測試代碼,加入Allture特性,改造后的 `test_login.py`如下: ```python import pytest from page import LoginPage import allure @allure.feature('登錄模塊') class TestLogin(object): @allure.story('正確登錄') def test_login_succss(self,get_driver): """登錄成功用例""" with pytest.allure.step('初始化瀏覽器driver'): login_page = LoginPage(get_driver) with pytest.allure.step('輸入正確的用戶名與密碼'): login_page.login("gfc@qq.com", "123456") with pytest.allure.step('登錄后,頁面源碼中包含用戶名信息'): assert "gfc@qq.com" in login_page.get_source() @allure.story('錯誤登錄') def test_login_fail(self,get_driver): """登錄失敗用例""" with pytest.allure.step('初始化瀏覽器driver'): login_page = LoginPage(get_driver) with pytest.allure.step('使用錯誤的賬號與密碼登錄'): login_page.login("gfc@123.com", "123456") alert = login_page.accept_alert() with pytest.allure.step('彈窗提示信息包含:User does not exist!'): assert "User does not exist!" in alert.text if __name__ == '__main__': import os pytest.main(['-s', '-q', 'test_login.py','--alluredir', './result/']) os.system('allure serve ./result/') ``` 上面使用了Allure的幾個特性: * @allure.feature # 用于定義被測試的功能,被測產品的需求點 * @allure.story # 用于定義被測功能的用戶場景,即子功能點 * with allure.step # 用于將一個測試用例,分成幾個步驟在報告中輸出 * allure.attach # 用于向測試報告中輸入一些附加的信息,通常是一些測試數據信息 * @pytest.allure.step # 用于將一些通用的函數作為測試步驟輸出到報告,調用此函數的地方會向報告中輸出步驟 ### 生成Allure測試報告的數據 在測試腳本中添加了Allure特性之后,pytest 執行測試的時候,指定–-alluredir選項及測試數據保存的目錄,即可在指定目錄下生成Allure測試報告的數據 >[warning] 在生成allure報告前,我們需要先運行測試用例,生成基礎數據。 在本示例中,運行以下命令 ```cmd pytest test_login.py --alluredir=./result/ ``` 運行后,我們可以看到在result目錄下,生成了兩個xml,顯然,這還不是我們預期的美觀html報告,這只是測試報告的數據而已。 ## Allure測試報告 ### 安裝 allure-commandline 要生成Allure測試報告,需要使用到allure命令行工具,下載地址: [https://github.com/allure-framework/allure2](https://github.com/allure-framework/allure2) https://pan.baidu.com/s/1LoPJQM27PfGwXWZ--bs8XQ 下載后,記得要配置到環境變量中,例如將其解壓到本地目錄D:\360YP\VM\allure-2.7.0\bin\allure.bat 后,要將該路徑添加到電腦環境變量的path中。 > 提示:要運行該命令行工具,需要提前安裝好java運行環境。 > ### 生成并打開Allure測試報告 方式一 ```cmd allure serve ./result/ ``` 方式二 ```cmd allure generate ./result/ -o ./report/ --clean allure open -h 127.0.0.1 -p 8083 ./report/ ``` 運行后本機的瀏覽器將打開 `http://127.0.0.1:8083/index.html` 網頁,展示測試報告,測試報告如下: ![](https://box.kancloud.cn/0361d0d64310b562c19514c7ca51a25f_1228x769.jpg) ![](https://box.kancloud.cn/161b417bfbb1b43c7a621cc9998ae1fc_1305x547.jpg) ## 參考文檔 [https://docs.qameta.io/allure/latest/](https://docs.qameta.io/allure/latest/) <hr style="margin-top:50px"> <section class="" style="box-sizing: border-box;" powered-by="xiumi.us"><section class="" style="margin: 40px 0% 10px;box-sizing: border-box;"><section class="" style="display: inline-block;width: 100%;border-width: 5px;border-style: double;border-color: rgb(23, 22, 24);padding: 10px;border-radius: 2px;box-sizing: border-box;"><section class="" style="box-sizing: border-box;" powered-by="xiumi.us"><section class="" style="transform: translate3d(20px, 0px, 0px);-webkit-transform: translate3d(20px, 0px, 0px);-moz-transform: translate3d(20px, 0px, 0px);-o-transform: translate3d(20px, 0px, 0px);font-size: 11px;margin: -50px 0% 0px;box-sizing: border-box;"><section class="" style="box-sizing: border-box;width: 7em;height: 7em;display: inline-block;vertical-align: bottom;border-radius: 100%;border-width: 4px;border-style: double;border-color: rgb(23, 22, 24);background-position: center center;background-repeat: no-repeat;background-size: cover;background-image: url(&quot;http://pav7h2emv.bkt.clouddn.com/FnD-fHkNDLN1-b02XmnMvsz6ld-n&quot;);"><section class="" style="width: 100%;height: 100%;overflow: hidden;box-sizing: border-box;"><img class="" data-ratio="0.6012024" data-w="499" data-src="http://pav7h2emv.bkt.clouddn.com/FnD-fHkNDLN1-b02XmnMvsz6ld-n" style="opacity: 0; box-sizing: border-box; width: 100% !important; height: auto !important; visibility: visible !important;" width="100%" data-type="jpeg" _width="100%" src="http://pav7h2emv.bkt.clouddn.com/FnD-fHkNDLN1-b02XmnMvsz6ld-n" data-fail="0"></section></section></section></section><section class="" style="box-sizing: border-box;" powered-by="xiumi.us"><section class="" style="margin: -30px 0% 30px;box-sizing: border-box;"><section class="" style="display: inline-block;vertical-align: top;width: 61.8%;padding: 0px 15px;box-sizing: border-box;"><section class="" style="box-sizing: border-box;" powered-by="xiumi.us"><section class="" style="margin: 40px 0% 0px;box-sizing: border-box;"><section class="" style="color: rgb(160, 160, 160);box-sizing: border-box;"><p style="margin: 0px;padding: 0px;box-sizing: border-box;">微信公眾號:</p><p style="margin: 0px;padding: 0px;box-sizing: border-box;">python測試開發圈</p><p style="margin: 0px;padding: 0px;box-sizing: border-box;"><br style="box-sizing: border-box;"></p></section></section></section></section><section class="" style="display: inline-block;vertical-align: top;width: 38.2%;box-sizing: border-box;"><section class="" style="box-sizing: border-box;" powered-by="xiumi.us"><section class="" style="text-align: center;margin: 10px 0% 0px;box-sizing: border-box;"><section class="" style="max-width: 100%;vertical-align: middle;display: inline-block;border-width: 0px;border-radius: 0px;box-shadow: rgb(0, 0, 0) 0px 0px 0px;width: 90%;overflow: hidden !important;box-sizing: border-box;"><img data-ratio="1" data-w="430" data-src="http://pav7h2emv.bkt.clouddn.com/FibGgIJSMfHtehzeWOOzjdQKSMx5" style="vertical-align: middle; max-width: 100%; box-sizing: border-box; width: 100% !important; height: auto !important; visibility: visible !important;" width="100%" data-type="jpeg" _width="100%" class="" src="http://pav7h2emv.bkt.clouddn.com/FibGgIJSMfHtehzeWOOzjdQKSMx5" data-fail="0"></section></section></section></section></section></section><section class="" style="box-sizing: border-box;" powered-by="xiumi.us"><section class="" style="margin: -30px 0% 0px;box-sizing: border-box;"><section class="" style="display: inline-block;vertical-align: top;width: 61.8%;padding: 0px 15px;box-sizing: border-box;"><section class="" style="box-sizing: border-box;" powered-by="xiumi.us"><section class="" style="transform: translate3d(5px, 0px, 0px);-webkit-transform: translate3d(5px, 0px, 0px);-moz-transform: translate3d(5px, 0px, 0px);-o-transform: translate3d(5px, 0px, 0px);box-sizing: border-box;"><section class="" style="color: rgb(160, 160, 160);font-size: 14px;box-sizing: border-box;"><p style="margin: 0px;padding: 0px;box-sizing: border-box;">一起分享學習與成長路線</p></section></section></section></section><section class="" style="display: inline-block;vertical-align: top;width: 38.2%;box-sizing: border-box;"><section class="" style="box-sizing: border-box;" powered-by="xiumi.us"><section class="" style="transform: translate3d(10px, 0px, 0px);-webkit-transform: translate3d(10px, 0px, 0px);-moz-transform: translate3d(10px, 0px, 0px);-o-transform: translate3d(10px, 0px, 0px);box-sizing: border-box;"><section class="" style="color: rgb(160, 160, 160);font-size: 14px;box-sizing: border-box;"><p style="margin: 0px;padding: 0px;box-sizing: border-box;">長按(或掃描)二維碼關注</p></section></section></section></section></section></section></section></section></section>
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看