我們仍然以這個場景為例,所不同的是:用戶進入IBM中國網站。再搜索關鍵字"lotus",驗證"www.lotus.com"這一鏈接存在于結果集內。測試過程的邏輯并沒有變化,但界面截然不同, "Search"按鈕在這里顯示為"搜索"按鈕。
為了拓展腳本SearchLotusLink對多語言的支持能力,我們在SearchLotusLinkHelper查找對象的過程中,加上一個中間層,通過它來銜接固定的操作邏輯和多變的界面。原先的方法findTestObjectInBrowser(String property1, String value1, String property2, String value2)只是按這兩個屬性值找出合適的對象;現在則要對屬性做適當的轉換,使它能適應其他語言環境,在不同語言的界面里都能定位到這個頁面對象。
將Rational Functional Tester切換到"Java透視圖",在SearchLotusLinkHelper所在的resources包中,添加一個類:utilities,來實現對多語言環境的支持。這里為簡單起見,我們將URL和搜索按鈕的文本的多語言表示直接保存在這個類里。用戶可以通過它來獲取某一屬性在特定語言環境下的表示。
public class utilities {
/**
* Script Name : <b>utilities</b>
* Generated : <b>2005-10-25 16:51:51</b>
* Description : Functional Test Script
* Original Host : WinNT Version 5.1 Build 2600 (S)
*
* @since 2005/10/25
* @author zhangguojun
*/
public static String EN_LOCALE = "en";
public static String CN_LOCALE = "cn";
public String CurrentLocale = EN_LOCALE;
private Hashtable textRepositoryForEN = new Hashtable();
private Hashtable textRepositoryForCN = new Hashtable();
private static utilities _instance = null;
private utilities(){
textRepositoryForEN.put("Search","Search");
textRepositoryForEN.put("IBMurl","www.ibm.com");
textRepositoryForCN.put("Search","搜索");
textRepositoryForCN.put("IBMurl","www.ibm.com/cn");
}
public static utilities getInstance() {
if (null == _instance)
_instance = new utilities();
return _instance;
}
public void setCurrentLocale(String locale)
{
CurrentLocale=locale;
}
public String getLocalText(String textId)
{
return getLocalText(CurrentLocale,textId);
}
public String getLocalText(String locale, String textId)
{
String returnVal = null;
if(locale.equals(EN_LOCALE))
returnVal = (String)textRepositoryForEN.get(textId);
else if(locale.equals(CN_LOCALE))
returnVal = (String)textRepositoryForCN.get(textId);
if(null==returnVal)
return textId;
else
return returnVal;
}
}
文章來源于領測軟件測試網 http://www.k11sc111.com/