###WTD Case 開發手冊html
做者 何坤158109016@qq.com V2.0 2017/3/12 http://snappydata.topjava
WTD case開發手冊git
####文檔目錄github
<setGlobalVarible name="guid" value="$Cookie.guid"/> 或者<setGlobalVarible name="sToken" value="$Response.sToken" />
<test name="the correct values" expectContansString='iStatus":1' preExcution="loginByApp"> <parameter name="userId" value="1800012315" /> </test> <test name="the wrong values" expectContansString='iStatus":0'"> <parameter name="userId" value="1800012111" /> </test>
$Cookie,$Response,$PreResponse
變量名 | 描述 |
---|---|
webDriver | Webdriver 的一個實例,用於case進行頁面各類操做的一個對象,能夠直接在case中調用如,webDriver.get(); |
hostName | 當前測試的主要的host name, 能夠直接在case中調用 |
caseName | 當前測試的case 名字, 能夠直接在case中調用 |
logFolder | 當前case生成log和result文件的目錄, 能夠直接在case中調用 |
logger | 能夠用來記錄log到log文件, 能夠直接在case中調用 |
isOnlineTest | 判斷當前環境是否爲線上測試環境 |
screenCapture()方法:返回類型:String 調用此方法會截一張當前的圖片保存到當前case 的log文件夾裏。web
setDescription(String)方法: 返回類型:void 調用此方法會爲當前case設置描述信息。正則表達式
setErrorInfo(String)方法:返回類型:void 調用此方法會爲當前case設置一些錯誤的log信息,便於在log文件中查看錯誤緣由。shell
setPointResult(String name,String description,String result,String errorInfo)方法:返回類型:void 調用此方法會將每一個測試點的結果寫進result.xml和log文件中。注意:測試點是包含在每一個case中的,每一個case至少包含一個測試點,也就是說每一個case至少調用此方法一次。json
clickBy (By by)方法:返回類型:boolean 調用此方法會點擊頁面一個控件,並返回是否執行成功。windows
clickById(String id)方法:返回類型:boolean 調用此方法會點擊頁面一個控件,並返回是否執行成功。api
clickByLinkText(String link)方法:返回類型:boolean 調用此方法會點擊頁面一個控件,並返回是否執行成功。
sendKeys(By by, String value)方法:返回類型:boolean 調用此方法會向一個控件輸入信息,並返回是否執行成功。
sendKeysById(String id, String value)方法:返回類型:boolean 調用此方法會向一個控件輸入信息,並返回是否執行成功。
isExist(By by)方法:返回類型:boolean 調用此方法會判斷某個元素是否存在,並返回判斷結果,true是找到該元素。
isTextExist(String content)方法:返回類型:boolean 調用此方法會判斷是否存在某個值的元素,並返回判斷結果,true是找到該元素。好比判斷當前頁面是否有「註冊」字段。
isCurrentURL(String url)方法:返回類型:boolean 調用此方法會判斷當前URL是否和傳入的URL同樣,並返回判斷結果,true是表示同樣的。
更多方法能夠參考com.pub.wtd.common.BaseCase 類和webdiver對象中的方法。或者登錄 小木屋
<?xml version="1.0" encoding="utf-8" ?> <case description="change the userlogin passwd" type="post"> <testApi api="http://xxx.xxx.qa.ipo.com/api/internal/user/changepwd.html" /> <setGlobalVarible name="guid" value="$Cookie.guid"/> <setGlobalVarible name="token" value="$Response.token"/> <test name="the correct values" expectContansString='iStatus":1' preExcution="logintoManage"> <parameter name="iUserID" value="$PreResponse.istatus" /> <parameter name="sOldPassword" value="a592ee46b591ba0c8bcce6a27c109f65" /> <parameter name="sNewPassword" value="4e1cea91bcd58ab5982ab1b50c2a782b" /> </test> <test name="the correct values" expectContansString='iStatus":1'> <parameter name="iUserID" value="45671" /> <parameter name="sOldPassword" value="4e1cea91bcd58ab5982ab1b50c2a782b" /> <parameter name="sNewPassword" value="a592ee46b591ba0c8bcce6a27c109f65" /> </test> </case>
public class TC_BaiDuSearch extends BaseCase { /** * 每個ui自動化case都必須實現execute()方法,此方法是此case的入口。 * 編寫case時能夠參考如下步驟: * 1,打開首頁或者一個連接或者本身定義的一個頁面:webDriver.get(String),new HomePage(sessionData).goToPage(), * 2,設置這個case的描述信息:setDescription(String) * 3,執行某些操做。 * 4,檢查預期值或者頁面元素並設置這個測試點測試經過或者測試失敗:setPointResult("", "", "pass", "NULL"); * 5,有必要時能夠截取當前頁面的截屏:screenCapture() * * 對於第三步,目前支持如下操做。 * 1,查找頁面元素:findElement(By),findElementById(String),findElements(By). * 2,查找元素的值(也就是元素的value),findElvalue(By) * 3,點擊頁面元素:clickBy(By),clickById(String),clickByLinkText(String) * 4,判斷頁面元素是否存在:isExist(By) * 5,判斷文本是否存在:isTextExist(String) * 6,向諸如文本框之類的控件輸入值:sendKeysBy(By,String),sendKeysById(By,String) * 7,全部webdriver支持的操做。 * * 更多更新信息請到 snappydata.top */ public void execute() { //new HomePage(sessionData).goToPage();// 自定義一個頁面,全部case均可以共享這個頁面,直接在case中打開這個頁面。 webDriver.get("http://www.baidu.com");//利用webdriver執行打開頁面 setDescription("測試百度搜索功能");// 設置case的描述信息 if (isCurrentURL(hostName+"/")|| isCurrentURL(hostName )) {// 判斷當前頁面是不是百度主頁 setPointResult("GoToHome", "回到首頁", "pass", "NULL");//設置此測試點經過 } else { setPointResult("GoToHome", "回到首頁", "fail","can not go to home page");//設置此測試點失敗 } String path = screenCapture();// 截取當前頁面截屏 testSearch();//測試搜索功能 } public void testSearch(){ sendKeysById("kw","snappydata.top"); clickById("su"); if(isTextExist("snappydata")){ setPointResult("測試搜索","測試搜索功能","pass","NULL"); }else{ setPointResult("測試搜索","測試搜索功能","fail","百度搜索測試失敗"); screenCapture();// 截取當前頁面截屏 } } }