の使用のPytest - セレン簡単な例

Pytest-セレンPytestプラグ及び実装方法です。

PIP3 pytest pytest-セレンをインストール

:そして、実行時に--driverで指定されたブラウザを指定
pytest test_baidu.py --driverクローム

構成されたセレン環境とchromedriverを進めます

ここではDjangoが背景のコースを追加使用して簡単な例です:
#1 test_add_course.pyの
インポートpytest
インポート]を選択selenium.webdriver.support.selectから
のインポートがelement_exist AS presence_of_element_located selenium.webdriver.support.expected_conditionsから


デフtest_add_course(セレン、ログイン、del_course ):#の器具を使用してログインする方法とdel_courseパラメータ
    selenium.find_element_by_link_text( "コース")(クリック )#をクリックして'コース'リンクを。
    selenium.find_element_by_class_name( "AddLink")をクリックします()#を。 「コースを追加]ボタンをクリックしてください
    (selenium.find_element_by_id( "id_owner")を選択 )。select_by_visible_text( "hanzhichao")# 選択著者
    (selenium.find_element_by_id( "id_subject")を選択 。select_by_visible_text( ") インターフェース・テスト")#選択したトピック
    selenium.find_element_by_id( "id_title")send_keys( "Pythonのインターフェイスのテストガイド")#は、記事のタイトルを入力します。
    selenium.find_element_by_id( "id_overview")send_keys( "著者:プロ元")。#は、説明の入力
    selenium.find_element_by_class_name( "デフォルト" )。()#[保存]をクリックしますクリック
    主張element_exist((「リンクテキスト」 、「Pythonのタイトルページ#アサーションリターンリンクの名前があるインタフェースのテストチュートリアルを」))

Runメソッド:
クローム--driver pytest test_add_course.py

おすすめ

転載: www.linuxidc.com/Linux/2019-06/158957.htm