進而我們對SearchLotusLinkHelper中方法findTestObjectInBrowser(String property1, String value1, String property2, String value2)的做相應的修改,使它能夠得到當前語言環境下屬性的表述形式。
protected TestObject findTestObjectInBrowser(String property1, String value1,
String property2, String value2)
{
TestObject[] foundTOs ;
String val1 = utilities.getInstance().getLocalText(value1);
String val2;
//在當前瀏覽器頁面中查找
if(null==property2)
foundTOs = browser_htmlBrowser().find(atDescendant(property1,val1)) ;
else
{
val2 = utilities.getInstance().getLocalText(value2);
foundTOs = browser_htmlBrowser().find(atDescendant(property1,value1,property2,val2)) ;
}
//如果沒有找到滿足條件的TestObject
if(foundTOs.length<1)
{
throw new com.rational.test.ft.ObjectNotFoundException("Can NOT find TestObject with
"+property1+"<"+value1+">,"+property2+"<"+value2+">");
}
//如果找到多個TestObject滿足條件,
else if(foundTOs.length>1)
{
throw new AmbiguousRecognitionException("Found multi-TestObject with
"+property1+"<"+value1+">,"+property2+"<"+value2+">");
}
//返回唯一的查找結果
return foundTOs[0];
}
最后,我們在腳本SearchLotusLink中加上一個開關,用來設置當前所使用的語言環境。我們只需要簡單地設置一下這個開關,同樣的腳本就可以在中英文兩種環境下進行測試。按這種模式,測試還可以延伸到其它語言環境中。
public void testMain(Object[] args)
{
//設置當前所使用的語言環境
utilities.getInstance().setCurrentLocale(utilities.CN_LOCALE);
startBrowser("");
document_htmlDocument().waitForExistence();
// HTML Browser
browser_htmlBrowser(document_htmlDocument(),DEFAULT_FLAGS).loadUrl(utilities.getInstance().
getLocalText("IBMurl"));
// 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/