天天看點

搭建eclipse+python+selenium測試環境

經過幾天的糾結之後,終于在今天把該環境搭建起來了,在這裡要特别感謝深圳-乙醇老師的幫助

  搭建環境:

  系統環境:win7 64位;

  jdk版本:java version “1.6.0_45″

  eclipse版本:4.2.0

  下面就給大家介紹一下詳細的步驟:

  (2) 添加path,比如:c:\python27;c:\python27\scripts;(最好添加目前使用者下面的path,避免破壞其他使用者的系統環境)

搭建eclipse+python+selenium測試環境

  (3) 利用pip安裝selenium,具體做法如下:

  a. 下載下傳和安裝一個帆樯軟體,這裡給大家介紹自由門,該軟體無需安裝,隻需要運作起exe檔案,就可以,很友善快捷

  b. 進入dos模式,切換路徑到c:\python27\scripts,然後輸入指令pip install selenium,系統就會自動下載下傳和安裝selenium

  (4) 打開eclipse,安裝pydev插件,具體操作如下:

  a. 直接在eclipse中選擇菜單:help—install new software..—add,輸入http://pydev.org/updates,下載下傳并安裝。

搭建eclipse+python+selenium測試環境

  b. 完成後重新開機eclipse,在eclipse菜單help->about eclipse->installation detail->plug-ins,若能看到pydev元件,則表示安裝成功

搭建eclipse+python+selenium測試環境
搭建eclipse+python+selenium測試環境

<a href="http://www.51testing.com/batch.download.php?aid=44694" target="_blank"></a>

搭建eclipse+python+selenium測試環境

  (6) 測試是否配置成功

  a. 建立一個python項目,操作步驟可見截圖

搭建eclipse+python+selenium測試環境

  b. 建立一個python module,輸入以下内容

#-*- 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位系統環境下面搭建該測試環境,如果你是先安裝python2.7之後再來安裝setuptools和pip,那麼你在用pip install selenium時可能會報錯,比如提示你:storing debug log for failure in c:\users\xxx\pip\pip.log,是以需要在任意一個根目錄下面建立一個register.py,該檔案的具體内容,如下:

#

# 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/[email protected]/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:

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!"

if (queryvalue(reg, installkey) == installpath and

queryvalue(reg, pythonkey) == pythonpath):

print "=== python", version, "is already registered!"

print "*** you probably have another python installation!"

registerpy()

  建立好之後,在dos模式下,進入到對應的根目錄下,輸入以下指令:python register.py,系統就會自動運作該檔案。然後再來運作pip來下載下傳安裝selenium,就不會報錯了,報錯的童鞋可以試試,嘿嘿~~

最新内容請見作者的github頁:http://qaseven.github.io/