パラメータ化とデータドライバ
要約:
使用してパラメータ化
pytest.mark.parametrize()に直接送信された基準
駆動データを
使用YAMLの外部ファイル
外部ファイルから取得した試験パラメータ
外部ファイルから取得するテストステップを
使用パラメータ化
@ pytest.mark.parametrize( "SEARCH_WORDS"、[ ' ゲーム'、 "hhdddx"])
具体的な使用事例:
from page.app import App
class TestDemo:
def setup(self):
self.main_page = App.start()
@pytest.mark.dependency()
def test_game_handle(self):
'''点击首页的游戏手柄,进入游戏中心'''
self.game_center = self.main_page.click_game_handle()
# @pytest.mark.dependency(depends=["TestDemo::test_game_handle"])
@pytest.mark.parametrize("keyword", ['游戏', "hhdddx"])
def test_game_search(self, keyword):
self.test_game_handle()
'''点击游戏中心页右上角的搜索,进行搜索查询'''
self.game_center.search(keyword)
sleep(5)
self.game_center.get_first_content(keyword)
def test_password_login(self):
'''从游戏中心-我的进入登录页面,进行登录'''
self.test_game_handle()
self.my_page = self.game_center.click_bottom_button_mine()
self.mobile_login = self.my_page.click_no_login_content()
self.password_login = self.mobile_login.switch_to_password_login()
self.password_login.password_login()
def teardown(self):
sleep(20)
App.quit()
ここ数回APP、APPを再起動させないために、使用されていないセットアップとティアダウン、しかしsetupclassの使用を再開します
データドリブン
パラメトリックデータは、外部ファイルを読み込む:使用YAML、JSONは読み
カスタム実行エンジン:外部ファイルを読み込むのテスト工程
の外部ファイルを読み込むステップアサート:カスタム実行エンジン
全体のユースケースは、外部ファイルを読み込む:動的ユースケースを作成します
パラメトリックデータは、外部ファイルをお読みください。
例:使用YAMLファイル
1 YAMLはインストール
インストールツールを使用してpycharm
コンピュータの窓 - オープンpycharm設定 - プロジェクト - プロジェクトInterpreter-はプラス記号をクリックします - 検索ボックス内に設置することPyYAMLと検索
インストールに使用するコマンド、ソースは、PyPIのから入手したインストールパッケージ
PIP3はPyYAMLとインストール
インストールに使用するコマンド、インストール・パッケージの国内源泉を使用し
インストールPIP3 PyYAMLと-i http://pypi.douban.com/simple --trustedホスト pypi.douban.com
インストールパッケージをダウンロードするには、国内の情報源の使用をピップ:インストールパッケージをダウンロードするには、国内の情報源のPIPを使用
チュートリアルのYAMLの使用:クリックして
2インポートYAML
インポートYAML
search_data = yaml.salf_load(オープン( "search.yaml"、 "R"))
印刷(search_dataを)
from time import sleep
import pytest
import yaml
from page.app import App
class TestDemo:
search_data = yaml.safe_load(open("search.yaml", "r"))
def setup(self):
self.main_page = App.start()
@pytest.mark.dependency()
def test_game_handle(self):
'''点击首页的游戏手柄,进入游戏中心'''
self.game_center = self.main_page.click_game_handle()
# @pytest.mark.dependency(depends=["TestDemo::test_game_handle"])
@pytest.mark.parametrize("keyword", search_data)
def test_game_search(self, keyword):
self.test_game_handle()
'''点击游戏中心页右上角的搜索,进行搜索查询'''
self.game_center.search(keyword)
sleep(5)
self.game_center.get_first_content(keyword)
search.yamlファイル
- ['游戏']
- [game]
参考記事:
==パッケージをダウンロードしてインストールするために、国内の情報源の使用をピップ:国内の情報源のピップの使用は、インストールパッケージをダウンロードします
チュートリアルのYAMLの使用:クリックして表示
外部ファイルを読み込むテストステップ
参考記事:
ビデオ:ビデオには、ジャンプするリンクをクリックして
記事を:
Junit5 + YAML簡単にパラメータ化とデータ駆動型、アプリケーションの自動化され、より効率的なテスト()ので、 ジャンプを打ち
* Junit5 + YAML簡単にパラメータ化とデータ駆動型、自動化されたアプリを聞かせてテストでは、(2)より効率的に
ジャンプします