0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Django学習とWebDriverでのテスト [その1]

Posted at

目的

Djangoの開発の学習として、Tutorialを実装します。
その際に自動テストも行い、Djangoの自動テストを行うためのseleniumの学習も行います。

環境構築

docker環境構築

dockerの環境構築は完了している前提で作業します。
参照:Docker上でDjango開発準備

selenium環境構築

最小限のselenium環境構築は完了している前提で作業します。
参照:pythonでWebDriverを駆動

チュートリアル1の自動テスト

アプリ作成

以下のURLを参照にし、アプリを作成してみます。
はじめての Django アプリ作成、その 1
以下のURLにアクセスし、表示されることを確認します。
http://127.0.0.1:8000/polls/

スクリプト作成

スクリプトを作成します。

test_01_polls.py
from selenium import webdriver

# EdgeDriver
driver = webdriver.Edge()
# URL
driver.get("http://localhost:8000/polls/")
# screenshot
driver.save_screenshot("01_polls.png")

実行

スクリプト実行してみます。

python .\test_01_polls.py

結果確認

うまく動作すれば、画面がキャプチャされて「01_polls.png」が作成されているはずです。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?