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

  Selenium是一個(gè)web的自動(dòng)化測(cè)試工具,和其它的自動(dòng)化工具相比來(lái)說其主要的特色是跨平臺(tái)、跨瀏覽器。
  支持windows、linux、MAC,支持ie、ff、safari、opera、chrome等。
  此外還有一個(gè)特色是支持分布式測(cè)試用例的執(zhí)行,可以把測(cè)試用例分布到不同的測(cè)試機(jī)器的執(zhí)行,相當(dāng)于分發(fā)機(jī)的功能。
  關(guān)于selenium的原理、架構(gòu)、使用等可以參考其官網(wǎng)的資料,這里記錄如何搭建一個(gè)使用python的selenium測(cè)試用例開發(fā)環(huán)境。其實(shí)用python
  來(lái)開發(fā)selenium的方法有2種:一是去selenium官網(wǎng)下載python版的selenium引擎;還有一種沒有操作過,這里不列出來(lái)了,有興趣的朋友可以自行查閱資料
  這里記錄的是第一種搭建方式:
  1.安裝python2.7x32或者x64版本
  2.安裝pip工具
  3.直接使用pip安裝selenium,命令為:pip install -U selenium
  如果測(cè)試成功會(huì)看到打開瀏覽器后進(jìn)行g(shù)oogle搜索。另外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,火狐在我自己使用中如果瀏覽器和驅(qū)動(dòng)不兼容,瀏覽器在啟動(dòng)和退出是會(huì)報(bào)停止工作,此處注意
# 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()
#==================================

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