シンプルな Web UI 自動テスト フレームワークはめったにありません

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 で始まる必要があります。
  • assertTitleassertUrl 、 など assertTextのアサーション メソッドをカプセル化することはほとんどありません。

main() メソッド

import seldom

# ...

if __name__ == '__main__':
    
    seldom.main(path="./",
              browser="chrome",
              title="百度测试用例", 
              description="测试环境:chrome", 
              debug=False,
              rerun=0,
              save_last_run=False
    )

例証します:

  • path : テスト ディレクトリまたはファイルを指定します。
  • ブラウザ: テスト ブラウザ (デフォルト) を指定しますChrome
  • title : テストレポートのタイトルを指定します。
  • description : テストレポートの説明を指定します。
  • debug : デバッグ モード。テスト HTML テストを生成しない場合は True に設定します。デフォルトは です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(Chrome): 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 は、ページレイヤーの作成を容易にするために、さらに便利な機能を提供します。

おすすめ

転載: blog.csdn.net/nhb687096/article/details/131353410