进而我们对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();
}
文章来源于领测软件测试网 https://www.ltesting.net/