您的位置:軟件測試 > 開源軟件測試 > 開源功能測試工具 > Selenium
Selenium+Python的自動化框架搭建
作者:網(wǎng)絡轉載 發(fā)布時間:[ 2015/9/2 10:40:08 ] 推薦標簽:功能測試工具 軟件測試工具

  Selenium是一個web的自動化測試工具,和其它的自動化工具相比來說其主要的特色是跨平臺、跨瀏覽器。
  支持windows、linux、MAC,支持ie、ff、safari、opera、chrome等。
  此外還有一個特色是支持分布式測試用例的執(zhí)行,可以把測試用例分布到不同的測試機器的執(zhí)行,相當于分發(fā)機的功能。
  關于selenium的原理、架構、使用等可以參考其官網(wǎng)的資料,這里記錄如何搭建一個使用python的selenium測試用例開發(fā)環(huán)境。其實用python
  來開發(fā)selenium的方法有2種:一是去selenium官網(wǎng)下載python版的selenium引擎;還有一種沒有操作過,這里不列出來了,有興趣的朋友可以自行查閱資料
  這里記錄的是第一種搭建方式:
  1.安裝python2.7x32或者x64版本
  2.安裝pip工具
  3.直接使用pip安裝selenium,命令為:pip install -U selenium
  如果測試成功會看到打開瀏覽器后進行google搜索。另外selenium分版本1和版本2,這里安裝是版本2的selenium。派生到我的代碼片
#-*-coding:utf-8-*-
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
import time
# Create a new instance of the browser driver
driver = webdriver.Chrome()  ##可以替換為IE(), FireFox(),但前提是配置了各自瀏覽器的Driver,火狐在我自己使用中如果瀏覽器和驅動不兼容,瀏覽器在啟動和退出是會報停止工作,此處注意
# go to the google home page
driver.get("http://www.google.com")
# find the element that's name attribute is q (the google search box)
inputElement = driver.find_element_by_name("q")
# type in the search
inputElement.send_keys("Cheese!")
# submit the form. (although google automatically searches now without submitting)
inputElement.submit()
# the page is ajaxy so the title is originally this:
print driver.title
try:
# we have to wait for the page to refresh, the last thing that seems to be updated is the title
WebDriverWait(driver, 10).until(lambda driver : driver.title.lower().startswith("cheese!"))
# You should see "cheese! - Google Search"
print driver.title
finally:
driver.quit()
#==================================

軟件測試工具 | 聯(lián)系我們 | 投訴建議 | 誠聘英才 | 申請使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd