Allureテストレポートフレームワークは、「高レベル」のレポートプレゼンテーションを簡単に実現するのに役立ちます。この記事では、Allureテストフレームワークを0から1に統合する方法を例とともに示します。Allureを既存の自動テストプロジェクトに統合する方法と、レポートの表示を最適化する方法に焦点を当てています。Allureは非常に強力で、複数の
関連トピックをサポートしています:javapythonwww.cppcns.comnbsp;(Homebrewバージョンが古い場合、インストールされているallureバージョンも非常に古いです。HomebrewAllure
テストレポートフレームワークをアップグレードして、簡単に実現できるようにする必要があります。 「高レベル」のレポート表示。この記事は合格です。この例は、Allureテストフレームワークを0から1に統合する方法を示しています。これは、Allureを既存の自動テストプロジェクトに統合する方法と、レポートの表示を最適化する方法に焦点を当てています。Allureは非常に強力で、java/pythonまたはJunit/TestNGに関係なく、複数の言語と複数のテストフレームワークをサポートします。他の言語またはフレームワークの実装プロセスはこの記事と同じであり、特定の構成は各言語のフレームワーク仕様
インストール
アリュールをインストール
Windowsユーザー:
scoop install allure(最初にScoopをダウンロードしてインストールする必要があります。この方法では、環境変数を構成する必要はありません)
MACユーザー:
Homebrew brew install allure&www.cppcns.comnbsp;による自動インストール
(Homebrewバージョンが古い場合は、最初にHomebrewをアップグレードする必要があります。そうでない場合、インストールされたallureバージョンも非常に古く、Pythonプラグインと互換性がない可能性があります)
手動インストール:
公式ウェブサイトhttps://repo.maven.apache.org/maven2/io/qameta/allure/allure-commandline/から手動でダウンロードできます
。最新バージョンは2.13.6です。allure
を使用してPythonでテストレポートを生成する方法オートメーション
ダウンロード後、環境変数を解凍して構成します
allure-pytestプラグインをインストールします
pip install allure-pytest
共通の機能を魅了する
レポートでテスト機能、サブ機能、またはシナリオを確認したい場合は、テストの追加情報を含むテストステップで、@ feature、@ story、@ step、@attachを使用できます。
ステップ:
import allure
function plus @ allure.feature( "feature name")
sub-feature plus @ allure.story( "sub-feature name")
step plus @ allure.step( "step details")
@ allure.attach( "specific Text情報")、追加情報が必要です。これには、データ、テキスト、写真、ビデオ、Webページなどがあります。
一部の機能のみをテストする場合は、制限とフィルターを追加できます
。pytest file name --allure-features"実行する必要のある関数」
魅力的な機能—機能/ストーリー
@ allure.feature vs @ allure.store
機能は、ケースを機能に分類し、レポートの動作に表示する関数、大きなモジュールに相当します。これは、
この関数またはモジュールのさまざまなシナリオに対応するテストスイートストーリーに相当します。機能に属するブランチ関数。レポートの構造は機能に表示されます。これは
、親子関係の
ステップ機能と同様のテストケース機能およびストーリーに相当します。
テストプロセスの各ステップは通常、特定のロジックメソッドに
配置されますが、主要なステップに配置でき、アプリのレポートに表示されます
。ウェブ自動テスト。ステップの
使用法として新しいページに切り替えることをお勧めします。
@ allure.step()は、allure.step()を使用してデコレータの形式でクラスまたはメソッドにのみ配置
できます。テストケースメソッドに配置できますが、テストステップのコードをに含める必要があります。実行するステートメント
:
www.cppcns.comのテスト実行中に結果を収集します
pytest[テストファイル]-s-q--alluredir=。/result--clean-alluredir
--alluredirこのオプションは、テスト結果を保存するパスを指定するために使用されます
--clean-alluredirこのオプションは、以前に生成された結果をクリアするために使用され
ます。テストレポートを表示します。
方法1:テストの完了後に実際のレポートを表示し、オンラインでレポートを監視し、デフォルトのブラウザーを直接開いて現在のレポートを表示します
アリュールサーブ./result
方法2:結果からレポートを生成します。これは、Tomcatを開始するサービスであり、2つのステップが必要です。
レポートの生成:
allure generate ./result -o ./report --clean(注:-cleanは、以前に生成されたレポートをクリアするために使用されます)
レポートを開きます。
allure open -h 127.0.0.1 -p 8883 ./report(このメソッドは、リモートアクセス可能なTomcatサービスを直接生成します)
例えば:
以下のコードファイルがあります
#!/usr/bin/python
# -*- coding: UTF-8 -*-
"""
@author:chenshifeng
@file:test_allure.py
@time:2020/10/10
"""
import allure
import pytest
@allure.feature('登录模块')
class TestLogin():
@allure.story('登录成功')
@allure.title('登录成功标题')
def test_login_sucess(self):
with allure.step('步骤1:打开应用'):
print('应用已打开')
with allure.step('步骤2:进入登录页面'):
print('登录页面已打开')
with allure.step('步骤3:输入用户名和密码'):
print('用户名和密码输入成功')
print('登录测试用例:登录成功')
@allure.story('登录成功')
def test_login_sucess2(self):
assert '1' == 1
print('登录测试用例:登录成功')
@allure.story('登录失败')
def test_login_failure_a(self):
print('登录测试用例:登录失败,用户名缺失')
@allure.story('登录失败')
def test_login_failure_b(self):
print('登录测试用例:登录失败,密码缺失')
@allure.story('登录失败')
def test_login_failure_c(self):
with allure.step('输入用户名'):
print('已输入用户名')
with allure.step('输入密码'):
print('已输入密码')
with allure.step('点击登录'):
print('已点击登录')
print('登录测试用例:登录失败,密码错误')
@allure.feature('搜索模块')
class TestSearch():
def test_search1(self):
print('搜索用例1')
TEST_CASE_LINK = 'https://mirrors.huaweicloud.com/'
@allure.testcase(TEST_CASE_LINK,'测试用例连接')
def test_search2(self):
print('搜索用例2')
@allure.step('搜索步骤')
def test_search3(self):
print('搜索用例3')
コマンドを順番に実行します。
pytest test_allure.py--alluredir=。/result--clean-alluredir
アリュールサーブ./result
chenshifengdeMacBook-Pro:testcode chenshifeng$ pytest test_allure.py --alluredir=./result --clean-alluredir
============================================================================= test session starts =============================================================================
platform darwin -- Python 3.9.0, pytest-6.1.1, py-1.9.0, pluggy-0.13.1
rootdir: /Users/chenshifeng/MyCode/PythonCode/SFDSZL/test_pytest, configfile: pytest.ini
plugins: allure-pytest-2.8.18
collected 8 items
test_allure.py .F...... [100%]
================================================================================== FAILURES ===================================================================================
________________________________________________________________________ TestLogin.test_login_sucess2 _________________________________________________________________________
self = <test_allure.TestLogin object at 0x7fef3d5cba90>
@allure.story('登录成功')
def test_login_sucess2(self):
> assert '1' == 1
E AssertionError: assert '1' == 1
test_allure.py:27: AssertionError
=========================================================================== short test summary info ===========================================================================
FAILED test_allure.py::TestLogin::test_login_sucess2 - AssertionError: assert '1' == 1
========================================================================= 1 failed, 7 passed in 0.07s =========================================================================
chenshifengdeMacBook-Pro:testcode chenshifeng$ allure serve ./result
Generating report to temp directory...
Report successfully generated to /var/folders/p0/3_7fwrvx6n3ftpfd4wjb01300000gn/T/7024790777193223986/allure-report
Starting web server...
2020-10-13 21:39:56.174:INFO::main: Logging initialized @6818ms to org.eclipse.jetty.util.log.StdErrLog
Server started at <http://192.168.12.100:58977/>. Press <Ctrl+C> to exit
生成されたレポート:
アリュールを使用してPython自動化でテストレポートを生成する方法
allure-feature-testcase
関連するテストケース(テストケースのアドレスに直接リンクできます)
例:
TEST_CASE_LINK = 'https://mirrors.huaweicloud.com/'
@allure.testcase(TEST_CASE_LINK,'测试用例连接')
def test_search(self):
print('搜索用例')
アリュールを使用してPython自動化でテストレポートを生成する方法
重要度によるスコープテスト
通常、テストには、P0、スモークテスト、および検証オンラインテストが含まれます。重要度に応じて実行します。たとえば、メインプロセスと重要なモジュールは、オンラインになるときに1回実行する必要があります。これは、次の方法で解決できます。
@pytest.markタグを追加する
allure.feature、allure.story経由
allure.severityを介してタグを付けることもできます
レベル:
些細な:重要ではない、軽微な欠陥(プロンプトなしで入力する必要がある、またはプロンプトが不規則)
軽微な重要ではない、軽微な欠陥(インターフェイスエラーがUI要件と一致しない)
正常:通常の問題、一般的な欠陥(数値計算エラー)
重大:重大で重大な欠陥(ファンクションポイントの欠落)
ブロッカー:ブロッキング、中断の欠陥(クライアントプログラムが応答せず、次の操作を実行できません)
使用法:
メソッド、関数、クラスの上に@ allure.severity(allure.severity_level.TRIVIAL)を追加します
埋め込む:
pytest -s -v filename --allure-重大度通常、クリティカル
例えば:
#!/usr/bin/python
# -*- coding: UTF-8 -*-
"""
@author:chenshifeng
@file:test_severity.py
@time:2020/10/11
"""
import allure
import pytest
# 不加任何标记,默认normal
def test_with_no_severity():
pass
# trivial:不重要,轻微缺陷(必输项无提示,或者提示不规范)
@allure.severity(allure.severity_level.TRIVIAL)
def test_with_trivial_severity():
pass
# minor 级别 不太重要,次要缺陷(界面错误与UI需求不符)
@allure.severity(allure.severity_level.MINOR)
def test_with_minor_severity():
pass
# normal:正常问题,普通缺陷(数值计算错误)
@allure.severity(allure.severity_level.NORMAL)
def test_with_normal_severity():
pass
# critical:严重,临界缺陷(功能点缺失)
@allure.severity(allure.severity_level.CRITICAL)
def test_with_ritical_severity():
pass
# blocker:阻塞,中断缺陷(客户端程序无响应,无法执行下一步操作)
@allure.severity(allure.severity_level.BLOCKER)
def test_with_blocker_severity():
pass
@allure.severity(allure.severity_level.NORMAL)
class TestClassWithNormalSeverity(object):
# 不加任何标记,默认为同class级别
def test_inside_with_normal_severity(self):
pass
# 重新设置了critical级别
@allure.severity(allure.severity_level.CRITICAL)
def test_inside_with_critical_severity(self):
pass
埋め込む:
chenshifengdeMacBook-Pro:testcode chenshifeng$ pytest test_severity.py --alluredir=./result --clean-alluredir -vs
============================================================================= test session starts =============================================================================
platform darwin -- Python 3.9.0, pytest-6.1.1, py-1.9.0, pluggy-0.13.1 -- /usr/local/bin/python3.9
cachedir: .pytest_cache
rootdir: /Users/chenshifeng/MyCode/PythonCode/SFDSZL/test_pytest, configfile: pytest.ini
plugins: allure-pytest-2.8.18
collected 8 items
test_severity.py::test_with_no_severity PASSED
test_severity.py::test_with_trivial_severity PASSED
test_severity.py::test_with_minor_severity PASSED
test_severity.py::test_with_normhttp://www.cppcns.comal_severity PASSED
test_severity.py::test_with_ritical_severity PASSED
test_severity.py::test_with_blocker_severity PASSED
test_severity.py::TestClassWithNormalSeverity::test_inside_with_normal_severity PASSED
test_severity.py::TestClassWithNormalSeverity::test_inside_with_critical_severity PASSED
============================================================================== 8 passed in 0.03s ========================================================================www.cppcns.com======
chenshifengdeMacBook-Pro:testcode chenshifeng$ allure serve ./result
Generating report to temp directory...
Report successfully generated to /var/folders/p0/3_7fwrvx6n3ftpfd4wjb01300000gn/T/17788207943997663035/allure-report
Starting web server...
2020-10-13 22:27:49.842:INFO::main: Logging initialized @6620ms to org.eclipse.jetty.util.log.StdErrLog
Server started at <http://192.168.12.100:59696/>. Press <Ctrl+C> to exit
python自动化之如何利用allure生成测试报告
究極のユースケース:
Baidu検索:
#!/usr/bin/python
# -*- coding: UTF-8 -*-
"""
@author:chenshifeng
@file:test_baidudemo.py
@time:2020/10/13
"""
import pytest
import allure
from selenium import webdriver
import time
@allure.testcase('https://www.github.com')
@allure.feature("百度搜索")
@pytest.mark.parametrize('test_data1',['allure','pytest','unittest'])
def test_steps_demo(test_data1):
with allure.step('打开百度网页'):
driver=webdriver.Chrome()
driver.get('http://www.baidu.com')
driver.maximize_window()
with allure.step(f'输入搜索词:{test_data1}'):
driver.find_element_by_id('kw').send_keys(test_data1)
time.sl编程客栈eep(2)
driver.find_element_by_id('su').click()
time.sleep(2)
with allure.step('保存图片'):
driver.save_screenshot('./screenshot/baidu.png')
allure.attach.file('./screenshot/baidu.png',attachment_type=allure.attachment_type.PNG)
with allure.step('关闭浏览器'):
driver.quit()
埋め込む:
chenshifengdeMacBook-Pro:testcode chenshifeng$ pytest test_baidudemo.py --alluredir=./result --clean-alluredir -vs
============================================================================= test session starts =============================================================================
platform darwin -- Python 3.9.0, pytest-6.1.1, py-1.9.0, pluggy-0.13.1 -- /usr/local/bin/python3.9
cachedir: .pytest_cache
rootdir: /Users/chenshifeng/MyCode/PythonCode/SFDSZL/test_pytest, configfile: pytest.ini
plugins: allure-pytest-2.8.18
collected 3 items
test_baidudemo.py::test_steps_demo[allure] PASSED
test_baidudemo.py::test_steps_demo[pytest] PASSED
test_baidudemo.py::test_steps_demo[unittest] PASSED
============================================================================= 3 passed in 24.65s ==============================================================================
chenshifengdeMacBook-Pro:testcode chenshifeng$ allure serve ./result
Generating report to temp directory...
Report successfully generated to /var/folders/p0/3_7fwrvx6n3ftpfd4wjb01300000gn/T/18005664130273264423/allure-report
Starting web server...
2020-10-13 23:03:39.221:INFO::main: Logging initialized @7360ms to org.eclipse.jetty.util.log.StdErrLog
Server started at <http://192.168.12.100:60775/>. Press <Ctrl+C> to exit
励まし:[あなたを助けるかもしれないチュートリアル]
これらの資料は、[ソフトウェアテスト]を行う友人にとって最も包括的で完全な準備倉庫である必要があります。この倉庫は、最も困難な旅にも同行しました。これもお役に立てば幸いです。特にテクノロジー業界では、すべてをできるだけ早く行う必要があり、技術基盤を改善する必要があります。
私のWeChatパブリックアカウント[ProgramYuanmuzi]をフォローして、無料で入手してください〜
山に登らなければ、空の高さはわかりません。待つことはあなたを逃すだけであり、闘争は成功するでしょう。
私の研究グループ:644956177グループにはコミュニケーションと共有を行う技術専門家がいます〜