LoginSignup
2
2

More than 5 years have passed since last update.

WindowsでのSeleniumPythonBindingのSetUp

Last updated at Posted at 2014-06-18

WindowsでのSeleniumPythonBindingのSetUp(非エンジニア向け)

  • QAやテスト業務をやってて、Webdriverやってみたいけど、環境構築がよくわからない人向け。
  • Windows7(64bit)での確認手順となります。
    • 他のWindows環境では適宜読み替えての操作をお願いします。

1. Pythonのインストール

  1. http://www.python.org/download/releases/2.7.6/ へアクセスし、Python2.7.XのインストーラーをDLします。
    • Pythonは後方互換のない、2.Xと3.X系がありますが、ここでは気にせず、2.X系をDLします。
    • PCの環境に応じて、32bit版、64bit版をインストールしてください。
  2. DLしたPython-2.X.X.msiをダブルクリックし、インストールします。
    • ひたすらNextで問題ないです。
    • Cドライブ直下にPython2Xのフォルダができていることを確認してください。
  3. 以下の環境変数を設定します。
C:\Python27\
C:\Python27\Scripts

こんな感じで設定します。



4. コマンドプロンプトを起動し、以下のコマンドを実行し、Pythonのインストール&Pathが通っていることを確認します。

cmd
>python --version
Python 2.7.6

2. setuptoolsのインストール

setuptoolsは後にインストールしたいpipを使うためにSetUpします。

これをインストール後に、別途pipやSeleniumをインストールします。

  1. https://pypi.python.org/pypi/setuptools#windows-7-or-graphical-install へアクセスし、ez_setup.pyを右クリック>名前をつけて保存でDLします。
  2. DLしたez_setup.pyを実行します。
cmd
>python ez_setup.py  

以下成功時に表示されるメッセージ

Installed c:\python27\lib\site-packages\setuptools-3.1-py2.7.egg
Processing dependencies for setuptools==3.1
Finished processing dependencies for setuptools==3.1

3. pipのインストール

pipはPythonのパッケージ管理ツールになります。

これをインストール後に、Seleniumをインストールします。

  1. easy_install pip を実行します。
cmd
>easy_install pip
Searching for pip
Reading https://pypi.python.org/simple/pip/
Best match: pip 1.5.4
Downloading https://pypi.python.org/packages/source/p/pip/pip-1.5.4.tar.gz#md5=
34b2904f92d46aaa333267fb1c922bb
Processing pip-1.5.4.tar.gz
Writing c:\users\tmge017\appdata\local\temp\easy_install-jm8nbg\pip-1.5.4\setup
cfg
Running pip-1.5.4\setup.py -q bdist_egg --dist-dir c:\users\tmge017\appdata\loc
l\temp\easy_install-jm8nbg\pip-1.5.4\egg-dist-tmp-ifcgio
warning: no files found matching 'pip\cacert.pem'
warning: no files found matching '*.html' under directory 'docs'
warning: no previously-included files matching '*.rst' found under directory 'd
cs\_build'
no previously-included directories found matching 'docs\_build\_sources'
Adding pip 1.5.4 to easy-install.pth file
Installing pip-script.py script to C:\Python27\Scripts
Installing pip.exe script to C:\Python27\Scripts
Installing pip2.7-script.py script to C:\Python27\Scripts
Installing pip2.7.exe script to C:\Python27\Scripts
Installing pip2-script.py script to C:\Python27\Scripts
Installing pip2.exe script to C:\Python27\Scripts

Installed c:\python27\lib\site-packages\pip-1.5.4-py2.7.egg
Processing dependencies for pip
Finished processing dependencies for pip

4. Seleniumのインストール

pipを使用して、Seleniumをインストールします。
これでPython版のWebdriverを使用できるようなります。

  1. pip install -U selenium と叩きます。以下のようなメッセージが表示されれば、seleniumのインストール完了です。
cmd
>pip install -U selenium
Downloading/unpacking selenium
  Running setup.py (path:c:\users\hogehoge\appdata\local\temp\pip_build_hogehoge\s
elenium\setup.py) egg_info for package selenium

Installing collected packages: selenium
  Running setup.py install for selenium

Successfully installed selenium
Cleaning up...

5. pytestのインストール

pipを使用して、pytestをインストールします。
pytestはPythonにおけるテスティングフレームワークの1つになります。
標準のunittest(xunitベースのテスティングフレームワーク)と比較し、
出力情報が多いため、テストスクリプトのデバッグに重宝します。

  1. pip install -U pytest と叩きます。以下のようなメッセージが表示されれば、pytestのインストールdoneです。
cmd
Installing collected packages: pytest, py, colorama
  Running setup.py install for pytest

    Installing py.test-script.py script to C:\Python27\Scripts
    Installing py.test.exe script to C:\Python27\Scripts
    Installing py.test-2.7-script.py script to C:\Python27\Scripts
    Installing py.test-2.7.exe script to C:\Python27\Scripts
  Running setup.py install for py

  Running setup.py install for colorama

Successfully installed pytest py colorama
Cleaning up...

6. スクリプトを書いて動かす。

  1. SeleniumBuilderでWebdriver2の形式で記録したものを、File>Import>Python/unittest して、hoge.py(拡張子はPythonファイルである.py)で保存します。
  2. 保存したファイルをpy.testで実行します。
cmd
py.test -v -s hoge.py
2
2
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
2
2