qileilove

          blog已經(jīng)轉(zhuǎn)移至github,大家請(qǐng)?jiān)L問(wèn) http://qaseven.github.io/

          搭建eclipse+python+selenium測(cè)試環(huán)境

          經(jīng)過(guò)幾天的糾結(jié)之后,終于在今天把該環(huán)境搭建起來(lái)了,在這里要特別感謝深圳-乙醇老師的幫助
            搭建環(huán)境:
            系統(tǒng)環(huán)境:Win7 64位;
            JDK版本:java version “1.6.0_45″
            eclipse版本:4.2.0
            下面就給大家介紹一下詳細(xì)的步驟:
            (1) 下載一個(gè)active-python安裝軟件(該軟件已經(jīng)包含了python2.7和setuptools),默認(rèn)安裝好之后,對(duì)應(yīng)的python目錄里面就已經(jīng)存在Scripts文件夾了,十分方便
            (2) 添加Path,比如:C:\Python27;C:\Python27\Scripts;(最好添加當(dāng)前用戶下面的path,避免破壞其他用戶的系統(tǒng)環(huán)境)
            (3) 利用pip安裝selenium,具體做法如下:
            a. 下載和安裝一個(gè)帆檣軟件,這里給大家介紹自由門,該軟件無(wú)需安裝,只需要運(yùn)行起exe文件,就可以,很方便快捷
            b. 進(jìn)入dos模式,切換路徑到C:\Python27\Scripts,然后輸入命令pip install selenium,系統(tǒng)就會(huì)自動(dòng)下載和安裝selenium
            (4) 打開(kāi)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,點(diǎn)擊ok之后,就能添加你需要的插件內(nèi)容
            (6) 測(cè)試是否配置成功
            a. 新建一個(gè)python項(xiàng)目,操作步驟可見(jiàn)截圖
            
            b. 新建一個(gè)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.如果通過(guò)firefox瀏覽器打開(kāi)了google界面,那么表明配置成功
            其中需要提示一下:
            Win 7 64位系統(tǒng)環(huán)境下面搭建該測(cè)試環(huán)境,如果你是先安裝python2.7之后再來(lái)安裝setuptools和pip,那么你在用pip install selenium時(shí)可能會(huì)報(bào)錯(cuò),比如提示你:Storing debug log for failure in C:\Users\XXX\pip\pip.log,所以需要在任意一個(gè)根目錄下面新建一個(gè)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)入到對(duì)應(yīng)的根目錄下,輸入以下命令:python register.py,系統(tǒng)就會(huì)自動(dòng)運(yùn)行該文件。然后再來(lái)運(yùn)行pip來(lái)下載安裝selenium,就不會(huì)報(bào)錯(cuò)了,報(bào)錯(cuò)的童鞋可以試試,嘿嘿~~

          posted on 2014-02-27 10:14 順其自然EVO 閱讀(2331) 評(píng)論(0)  編輯  收藏 所屬分類: selenium and watir webdrivers 自動(dòng)化測(cè)試學(xué)習(xí)

          <2014年2月>
          2627282930311
          2345678
          9101112131415
          16171819202122
          2324252627281
          2345678

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 长武县| 九江市| 英德市| 和政县| 长兴县| 苗栗市| 利川市| 时尚| 普兰县| 永吉县| 东兰县| 扶绥县| 崇礼县| 绥中县| 普安县| 安塞县| 嘉峪关市| 雷山县| 阜城县| 阿拉善左旗| 镇巴县| 浠水县| 云和县| 韶山市| 紫金县| 崇文区| 千阳县| 上高县| 宽城| 横峰县| 东莞市| 且末县| 城固县| 七台河市| 澄江县| 正镶白旗| 合水县| 阳新县| 高陵县| 博乐市| 和平区|