搭建eclipse+python+selenium測試環(huán)境
經(jīng)過幾天的糾結(jié)之后,終于在今天把該環(huán)境搭建起來了,在這里要特別感謝深圳-乙醇老師的幫助
搭建環(huán)境:
系統(tǒng)環(huán)境:Win7 64位;
JDK版本:java version “1.6.0_45″
eclipse版本:4.2.0
下面就給大家介紹一下詳細(xì)的步驟:
(1) 下載一個active-python安裝軟件(該軟件已經(jīng)包含了python2.7和setuptools),默認(rèn)安裝好之后,對應(yīng)的python目錄里面就已經(jīng)存在Scripts文件夾了,十分方便
(2) 添加Path,比如:C:\Python27;C:\Python27\Scripts;(最好添加當(dāng)前用戶下面的path,避免破壞其他用戶的系統(tǒng)環(huán)境)
(3) 利用pip安裝selenium,具體做法如下:
a. 下載和安裝一個帆檣軟件,這里給大家介紹自由門,該軟件無需安裝,只需要運行起exe文件,就可以,很方便快捷
b. 進(jìn)入dos模式,切換路徑到C:\Python27\Scripts,然后輸入命令pip install selenium,系統(tǒng)就會自動下載和安裝selenium
(4) 打開eclipse,安裝PyDev插件,具體操作如下:
a. 直接在Eclipse中選擇菜單:Help—Install New Software..—Add,輸入http://pydev.org/updates,下載并安裝。
b. 完成后重啟Eclipse,在Eclipse菜單Help->About Eclipse->Installation Detail->Plug-ins,若能看到PyDev組件,則表示安裝成功

(5) 需要配置Python解釋器,具體操作如下:
在 Eclipse 菜單欄中,選擇 Window > Preferences > Pydev > Interpreter – Python。單擊 New,選擇 Python 解釋器 python.exe,點擊ok之后,就能添加你需要的插件內(nèi)容
(6) 測試是否配置成功
a. 新建一個python項目,操作步驟可見截圖
b. 新建一個python module,輸入以下內(nèi)容
#-*- conding=utf-8 -*- from selenium import webdriver if __name__ == "__main__": driver = webdriver.Firefox() driver.implicitly_wait(30) driver.get("http://www.google.com.hk") print 'Page title is:',driver.title driver.quit() |
c.如果通過firefox瀏覽器打開了google界面,那么表明配置成功
其中需要提示一下:
Win 7 64位系統(tǒng)環(huán)境下面搭建該測試環(huán)境,如果你是先安裝python2.7之后再來安裝setuptools和pip,那么你在用pip install selenium時可能會報錯,比如提示你:Storing debug log for failure in C:\Users\XXX\pip\pip.log,所以需要在任意一個根目錄下面新建一個register.py,該文件的具體內(nèi)容,如下:
# # script to register Python 2.0 or later for use with win32all # and other extensions that require Python registry settings # # written by Joakim Loew for Secret Labs AB / PythonWare # # source: # http://www.pythonware.com/products/works/articles/regpy20.htm # # modified by Valentine Gogichashvili as described in http://www.mail-archive.com/distutils-sig@python.org/msg10512.html import sys from _winreg import * # tweak as necessary version = sys.version[:3] installpath = sys.prefix regpath = "SOFTWARE\\Python\\Pythoncore\\%s\\" % (version) installkey = "InstallPath" pythonkey = "PythonPath" pythonpath = "%s;%s\\Lib\\;%s\\DLLs\\" % ( installpath, installpath, installpath ) def RegisterPy(): try: reg = OpenKey(HKEY_CURRENT_USER, regpath) except EnvironmentError as e: try: reg = CreateKey(HKEY_CURRENT_USER, regpath) SetValue(reg, installkey, REG_SZ, installpath) SetValue(reg, pythonkey, REG_SZ, pythonpath) CloseKey(reg) except: print "*** Unable to register!" return print "--- Python", version, "is now registered!" return if (QueryValue(reg, installkey) == installpath and QueryValue(reg, pythonkey) == pythonpath): CloseKey(reg) print "=== Python", version, "is already registered!" return CloseKey(reg) print "*** Unable to register!" print "*** You probably have another Python installation!" if __name__ == "__main__": RegisterPy() |
建立好之后,在dos模式下,進(jìn)入到對應(yīng)的根目錄下,輸入以下命令:python register.py,系統(tǒng)就會自動運行該文件。然后再來運行pip來下載安裝selenium,就不會報錯了,報錯的童鞋可以試試,嘿嘿~~
posted on 2014-02-27 10:14 順其自然EVO 閱讀(2330) 評論(0) 編輯 收藏 所屬分類: selenium and watir webdrivers 自動化測試學(xué)習(xí)