LoginSignup
1
1

More than 5 years have passed since last update.

SeleniumのWebdriverを使ってpythonでフォームテストを実施

Posted at

ボタンアクション時に処理する内容が多い場合、ちゃんと処理が完了するか確かめたかったので、Seleniumで簡単に作成しました。

Seleniumのインストール

pip install selenium 

※ブラウザによって使用するドライバが異なるので、必要に応じてダウンロードし、実行するフォルダに格納します。
 https://pypi.org/project/selenium/#drivers

フォームにキーワードを入力してボタンを押す行為を繰り返す

  • テストの目的
    • 50回連続でフォームアクションを続けても問題なく処理されるか?
  • 実施内容
    • 予めキーワードを50個入力されたCSVファイルを用いて5秒間隔で入力⇒ボタンクリックを繰り返していく。
  • 確認内容
    • 50キーワードがDBに登録されているか
    • 50キーワードが登録されたDBのカラムにnullは無いか など
#インストール
import os
import time
from selenium import webdriver
import pandas as pd

# URLの指定
url = 'http://hogehoge.jp/'

# キーワードを読み込み
keywords = pd.read_csv("keywords.csv", encoding="utf-8", engine="python", sep='\t')
keywords = list(keywords.values.flatten())

for search_keyword in search_keywords:
    browser = webdriver.Chrome('chromedriver.exe')
    browser.get(url)
    time.sleep(1)
    # キーワードを入力する
    searchBox = browser.find_element_by_class_name("form-input-landing")
    searchBox.send_keys(search_keyword)
    # 1秒待って検索ボタン押す
    time.sleep(1)
    kensakuBotan = browser.find_element_by_class_name('button-landing')
    kensakuBotan.click()
    # 3秒待つ
    time.sleep(3)
    #ウィンドウを閉じる
    browser.quit()

1
1
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
1
1