//如果找到多個TestObject滿足條件,
else if(foundTOs.length>1)
{
throw new AmbiguousRecognitionException("Found multi-TestObject with
"+property1+"<"+value1+">,"+property2+"<"+value2+">");
}
//返回唯一的查找結果
return foundTOs[0];
}
與此同時,針對腳本SearchLotusLink里為選擇操作對象而記錄下的的鼠標操作,及驗證點。我們也同樣對其進行抽象,攫取其中的關鍵行為,代之以程序動作。比如:
browser_htmlBrowser(document_htmlDocument(),DEFAULT_FLAGS).click(atPoint(455,108));
browser_htmlBrowser(document_htmlDocument(),DEFAULT_FLAGS).inputKeys("www.ibm.com{ENTER}");
這兩行腳本的操作是在瀏覽器的地址欄內輸入URL,再按下回車。這個動作如果借助Rational Functional Tester所提供的API來表示,可以簡化很多:
browser_htmlBrowser(document_htmlDocument(),DEFAULT_FLAGS).loadUrl("www.ibm.com");
再以程序的方式生成驗證點并驗證,不與腳本相關的數據結構發生干系。經過優化和精煉后的腳本SearchLotusLink如下:即使將來頁面布局和結構發生變化,這段腳本仍然能正確地定位到搜索輸入框和搜索按鈕。
public void testMain(Object[] args)
{
startBrowser("");
document_htmlDocument().waitForExistence();
// HTML Browser
browser_htmlBrowser(document_htmlDocument(),DEFAULT_FLAGS).loadUrl("www.ibm.com");
// Document: IBM United States: http://www.ibm.com/us/
text_q().waitForExistence();
text_q().setText("lotus");
button_search().click();
link_httpWwwLotusCom().waitForExistence();
IFtVerificationPoint vp1 =
vpManual("vp1","http://www.lotus.com/",link_httpWwwLotusCom().getProperty(".href"));
vp1.performTest();
}
四 擺脫語言的束縛
如今的軟件大多都要求支持"全球化",能夠適應多種語言環境。就用戶界面而言,需要在不同的語言環境中展示出本地語言界面。多語言環境下的人工測試往往不盡如人意,自動化測試反而更為迅速和準確。
文章來源于領測軟件測試網 http://www.k11sc111.com/