您的位置:軟件測(cè)試 > 開(kāi)源軟件測(cè)試 > 開(kāi)源功能測(cè)試工具 > Selenium
Selenium私房菜系列全集
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時(shí)間:[ 2013/3/28 13:48:19 ] 推薦標(biāo)簽:

    storeAttribute(.{}elementLocator@attributeName,variableName.{})
    把指定元素的屬性的值賦予給變量
    storeAttribute  input1@class   classOfInput1
    verifyAttribute  input2@class  $.{classOfInput1}
    chooseCancel.., answer..
    chooseCancelOnNextConfirmation()
    - 當(dāng)下次JavaScript彈出confirm對(duì)話(huà)框的時(shí)候,讓selenium選擇Cancel
    - 如果沒(méi)有該命令時(shí),遇到confirm對(duì)話(huà)框Selenium默認(rèn)返回true,如手動(dòng)選擇OK按鈕一樣
    chooseCancelOnNextConfirmation      

    - 如果已經(jīng)運(yùn)行過(guò)該命令,當(dāng)下一次又有confirm對(duì)話(huà)框出現(xiàn)時(shí),也會(huì)同樣地再次選擇Cancel
    answerOnNextPrompt(answerString)
    - 在下次JavaScript彈出prompt提示框時(shí),賦予其anweerString的值,并選擇確定
    answerOnNextPrompt  Kangaroo  

Assertions

允許用戶(hù)去檢查當(dāng)前狀態(tài)。兩種模式: Assert 和 Verify, 當(dāng)Assert失敗,則退出測(cè)試;當(dāng)Verify失敗,測(cè)試會(huì)繼續(xù)運(yùn)行。

    assertLocation, assertTitle
    assertLocation(relativeLocation)
    判斷當(dāng)前是在正確的頁(yè)面
    verifyLocation  /mypage  
    assertLocation  /mypage  
    assertTitle(titlePattern)
    檢查當(dāng)前頁(yè)面的title是否正確
    verifyTitle  My Page  
    assertTitle  My Page  
    assertValue
    assertValue(inputLocator, valuePattern)
    - 檢查input的值
    - 對(duì)于 checkbox或radio,如果已選擇,則值為"on",反之為"off"
    verifyValue  nameField  John Smith
    assertValue  document.forms[2].nameField  John Smith
    assertSelected, assertSelectedOptions
    assertSelected(selectLocator, optionSpecifier)
    檢查select的下拉菜單中選中的選型是否和optionSpecifer(Select選擇選項(xiàng)器)的選項(xiàng)相同
    verifySelected  dropdown2  John Smith
    verifySelected  dorpdown2  value=js*123
    assertSelected  document.forms[2].dropDown  label=J*Smith
    assertSelected  document.forms[2].dropDown  index=0
    assertSelectOptions(selectLocator, optionLabelList)
    - 檢查下拉菜單中的選項(xiàng)的文本是否和optionLabelList相同
    - optionLabelList是以逗號(hào)分割的一個(gè)字符串
    verifySelectOptions  dropdown2  John Smith,Dave Bird
    assertSelectOptions  document.forms[2].dropdown  Smith,J,Bird,D
    assertText
    assertText(elementLocator,textPattern)
    - 檢查指定元素的文本
    - 只對(duì)有包含文本的元素生效
    - 對(duì)于Mozilla類(lèi)型的瀏覽器,用textContent取元素的文本,對(duì)于IE類(lèi)型的瀏覽器,用innerText取元素文本
    verifyText  statusMessage  Successful
    assertText  //div[@id='foo']//h1  Successful
    assertTextPresent, assertAttribute
    assertTextPresent(text)
    檢查在當(dāng)前給用戶(hù)顯示的頁(yè)面上是否有出現(xiàn)指定的文本
    verifyTextPresent  You are now logged in  
    assertTextPresent  You are now logged in  
    assertAttribute(.{}elementLocator@attributeName.{}, ValuePattern)
    檢查當(dāng)前指定元素的屬性的值
    verifyAttribute  txt1@class  bigAndBlod
    assertAttribute  document.images[0]@alt  alt-text
    verifyAttribute  //img[@id='foo']/alt  alt-text
    assertTextPresent, etc.
    assertTextPresent(text)
    assertTextNotPresent(text)
    assertElementPresent(elementLocator)
    verifyElementPresent  submitButton  
    assertElementPresent  //img[@alt='foo']     assertElementNotPresent(elementLocator)
    assertTable
    assertTable(cellAddress, valuePattern)
    - 檢查table里的某個(gè)cell中的值
    - cellAddress的語(yǔ)法是tableName.row.column, 注意行列序號(hào)都是從0開(kāi)始
    verifyTable  myTable.1.6  Submitted
    assertTable  results0.2  13
    assertVisible, nonVisible
    assertVisible(elementLocator)
    - 檢查指定的元素是否可視的
    - 隱藏一個(gè)元素可以用設(shè)置css的'visibility'屬性為'hidden',也可以設(shè)置'display'屬性為'none'
    verfyVisible  postcode  
    assertVisible  postcode  
    assertNotVisible(elementLocator)
    verfyNotVisible  postcode  
    assertNotVisible  postcode  
    Editable, non-editable
    assertEditable(inputLocator)
    檢查指定的input是否可以編輯
    verifyEditable  shape  
    assertEditable  colour  
    assertNotEditable(inputLocator)
    檢查指定的input是否不可以編輯
    assertAlert
    assertAlert(messagePattern)
    - 檢查JavaScript是否有產(chǎn)生帶指定message的alert對(duì)話(huà)框
    - alert產(chǎn)生的順序必須與檢查的順序一致
    - 檢查alert時(shí)會(huì)產(chǎn)生與手動(dòng)點(diǎn)擊'OK'按鈕一樣的效果。如果一個(gè)alert產(chǎn)生了,而你卻沒(méi)有去檢查它,selenium會(huì)在下個(gè)action中報(bào)錯(cuò)。
    - 注意:Selenium 不支持 JavaScript 在onload()事件時(shí) 調(diào)用alert();在這種情況下,Selenium需要你自己手動(dòng)來(lái)點(diǎn)擊OK.
    assertConfirmation
    assertConfirmation(messagePattern)
    - 檢查JavaScript是否有產(chǎn)生帶指定message的confirmation對(duì)話(huà)框和alert情況一樣,confirmation對(duì)話(huà)框也必須在它們產(chǎn)生的時(shí)候進(jìn)行檢查
    - 默認(rèn)情況下,Selenium會(huì)讓confirm() 返回true, 相當(dāng)于手動(dòng)點(diǎn)擊Ok按鈕的效果。你能夠通過(guò)chooseCancelOnNextConfirmation命令讓confirm()返回false.同樣 地,如果一個(gè)cofirmation對(duì)話(huà)框出現(xiàn)了,但你卻沒(méi)有檢查的話(huà),Selenium將會(huì)在下個(gè)action中報(bào)錯(cuò)
    - 注意:在Selenium的環(huán)境下,confirmation對(duì)話(huà)框框?qū)⒉粫?huì)再出現(xiàn)彈出顯式對(duì)話(huà)框
    - 注意:Selenium不支持在onload()事件時(shí)調(diào)用confirmation對(duì)話(huà)框,在這種情況下,會(huì)出現(xiàn)顯示confirmatioin對(duì)話(huà)框,并需要你自己手動(dòng)點(diǎn)擊。
    assertPrompt
    assertPrompt(messagePattern)
    - 檢查JavaScript是否有產(chǎn)生帶指定message的Prompt對(duì)話(huà)框
    - 你檢查的prompt的順序Prompt對(duì)話(huà)框產(chǎn)生的順序必須相同
    - 必須在verifyPrompt之前調(diào)用answerOnNextPrompt命令
    - 如果prompt對(duì)話(huà)框出現(xiàn)了但你卻沒(méi)有檢查,則Selenium會(huì)在下個(gè)action中報(bào)錯(cuò)
    answerOnNextPrompt  Joe  
    click  id=delegate  
    verifyPrompt  Delegate to who?  

Parameters and Variables

參數(shù)和變量的聲明范圍由簡(jiǎn)單的賦值到JavaScript表達(dá)式賦值。
Store,storeValue 和storeText 為下次訪(fǎng)問(wèn)保存值。
在Selenium內(nèi)部是用一個(gè)叫storeVars的map來(lái)保存變量名。

    Variable Substitution 變量替換
    提供了一個(gè)簡(jiǎn)單的方法去訪(fǎng)問(wèn)變量,語(yǔ)法 $.{xxx}
    store  Mr  title
    storeValue  nameField  surname
    store  $.{title} $.{suname}  fullname
    type  textElement  Full name is: $.{fullname}
    JavaScript Evaluation JavaScript賦值
    你能用JavaScript來(lái)構(gòu)建任何你所需要的值。
    這個(gè)參數(shù)是以javascript開(kāi)頭,語(yǔ)法是 javascript.{'with a trailing'}。
    可以通過(guò)JavaScript表達(dá)式給某元素賦值。
    store  javascript.{'merchant'+(new Date()).getTime()}  merchantId
    type  textElement  javascript.{storedVars['merchantId'].toUpperCase()}

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