pyse をめったに改名
Selenium と unittest に基づく WebUI 自動化テスト フレームワーク。
Selenium と unittest に基づく Web UI 自動化テスト フレームワーク。
特徴
- 自動化されたテストを作成するためのより単純な API を提供します。
- 自動化されたテスト プロジェクトをすばやく生成するための足場を提供します。
- HTML テスト レポート生成を自動的に生成します。
- 自己完結型のアサーション メソッド、アサーション タイトル、URL、およびテキスト。
- ユースケースのパラメーター化のサポート。
- ユース ケースの失敗の再実行をサポートします。
- ユースケースの失敗/エラーのスクリーンショット。
インストール
> pip install seldom
最新バージョンに追いつきたい場合は、github リポジトリの URL を使用してインストールできます。
> pip install -U git+https://github.com/defnngj/seldom.git@master
クイックスタート
1. ヘルプを表示:
> seldom -h
usage: seldom [-h] [-V] [--startproject STARTPROJECT] [-r R]
WebUI automation testing framework based on Selenium.
optional arguments:
-h, --help show this help message and exit
-V, --version show version
--startproject STARTPROJECT
Specify new project name.
-r R run test case
2. プロジェクトを作成します。
>seldom --startproject mypro
3. ディレクトリ構造:
mypro/
├── test_dir/
│ ├── test_sample.py
├── report/
└── run.py
test_dir/
カタログは、ユース ケースの記述を実装します。report/
ディレクトリには、生成されたテスト レポートが保存されます。run.py
テストケースを実行するためのファイル。
3. プロジェクトを実行します。
> seldom -r run.py
Python 3.7.1
_ _
| | | |
___ ___ | | __| | ___ _ __ ___
/ __| / _ \| | / _` | / _ \ | '_ ` _ \
\__ \| __/| || (_| || (_) || | | | | |
|___/ \___||_| \__,_| \___/ |_| |_| |_|
-----------------------------------------
@itest.info
generated html file: file:///D:\mypro\reports\2019_11_12_22_28_53_result.html
.1
4. レポートを表示する
mypro\reports\
ディレクトリに移動して、テスト レポートを表示できます 。
API ドキュメント
簡単なデモ
demo/test_sample.py
ファイルをご覧ください
import seldom
class YouTest(seldom.TestCase):
def test_case(self):
"""a simple test case """
self.open("https://www.baidu.com")
self.type(id_="kw", text="seldom")
self.click(css="#su")
self.assertTitle("seldom")
if __name__ == '__main__':
seldom.main("test_sample.py")
説明します:
- テスト クラスを作成するには、継承する必要があります
seldom.TestCase
。 - テスト ケース ファイル名は
test
で始まる必要があります。 assertTitle
、assertUrl
、 などassertText
のアサーション メソッドをカプセル化することはめったにありません。
main() メソッド
import seldom
# ...
if __name__ == '__main__':
seldom.main(path="./",
browser="chrome",
title="百度测试用例",
description="测试环境:chrome",
debug=False,
rerun=0,
save_last_run=False
)
説明します:
- path : テスト ディレクトリまたはファイルを指定します。
- browser: テスト ブラウザを指定します。デフォルトは です
Chrome
。 - title : テスト レポートのタイトルを指定します。
- description : テスト レポートの説明を指定します。
- debug : デバッグ モード。True に設定すると、テスト HTML テストが生成されません。デフォルトは です
False
。 - rerun : 失敗時の再実行回数を設定します。デフォルトは です
0
。 - save_last_run : 最後の結果のみを保存するように設定します。デフォルトは です
False
。
テストを実行する
import seldom
seldom.main(path="./") # 当前目录下的所有测试文件
seldom.main(path="./test_dir/") # 指定目录下的所有测试文件
seldom.main(path="./test_dir/test_sample.py") # 指定目录下的测试文件
seldom.main(path="test_sample.py") # 指定当前目录下的测试文件
説明します:
- ディレクトリが指定されている場合、テスト ファイルは
test
. - サブディレクトリのファイルを実行する場合は、サブディレクトリにファイルを追加する必要があります
__init__.py
。
サポートされているブラウザーとドライバー
テスト ケースが異なるブラウザーで実行されるように指定する場合は、非常に簡単です。seldom.main()
メソッドでbrowser
パラメーター設定を渡すだけで済みます。
import seldom
if __name__ == '__main__':
seldom.main(browser="chrome") # chrome浏览器,默认值
seldom.main(browser="firefox") # firefox浏览器
seldom.main(browser="ie") # IE浏览器
seldom.main(browser="opera") # opera浏览器
seldom.main(browser="edge") # edge浏览器
seldom.main(browser="chrome_headless") # chrome浏览器headless模式
seldom.main(browser="firefox_headless") # Firefox浏览器headless模式
さまざまなブラウザー ドライバーのダウンロード アドレス:
geckodriver(Firefox):リリース · mozilla/geckodriver · GitHub
Chromedriver (クローム): https://sites.google.com/a/chromium.org/chromedriver/home
IEDriverServer(IE): http://selenium-release.storage.googleapis.com/index.html
operadriver(Opera):リリース・operasoftware/operachromiumdriver・GitHub
MicrosoftWebDriver(Edge): Microsoft Edge WebDriver - Microsoft Edge 開発者
================================================== === ========
要素の配置
<form id="form" class="fm" action="/s" name="f">
<span class="bg s_ipt_wr quickdelete-wrap">
<input id="kw" class="s_ipt" name="wd">
ターゲティング:
self.type(id_="kw", text="seldom")
self.type(name="wd", text="seldom")
self.type(class_name="s_ipt", text="seldom")
self.type(tag="input", text="seldom")
self.type(link_text="hao123", text="seldom")
self.type(partial_link_text="hao", text="seldom")
self.type(xpath="//input[@id='kw']", text="seldom")
self.type(css="#kw", text="seldom")
パラメーター化されたテスト ケース
パラメータ化されたテストケースをサポートすることはめったになく、パラメータ化された.
import seldom
from seldom import ddt
# ...
class BaiduTest(seldom.TestCase):
@ddt.data([
(1, 'seldom'),
(2, 'selenium'),
(3, 'unittest'),
])
def test_baidu(self, name, keyword):
"""
used parameterized test
:param name: case name
:param keyword: search keyword
"""
self.open("https://www.baidu.com")
self.type(id_="kw", text=keyword)
self.click(css="#su")
self.assertTitle(search_key+"_百度搜索")
ページ オブジェクトのデザイン パターン
Page オブジェクトのデザインパターンをサポートすることはめったになく、poiumで使用できます 。
import seldom
from poium import Page, PageElement
class BaiduPage(Page):
"""baidu page"""
search_input = PageElement(id_="kw")
search_button = PageElement(id_="su")
class BaiduTest(seldom.TestCase):
"""Baidu serach test case"""
def test_case(self):
"""
A simple test
"""
page = BaiduPage(self.driver)
page.get("https://www.baidu.com")
page.search_input = "seldom"
page.search_button.click()
self.assertTitle("seldom_百度搜索")
if __name__ == '__main__':
seldom.main("test_po_demo.py")
poium は、ページレイヤーの作成を容易にするためのより便利な機能を提供します。