您的位置:軟件測試 > 開源軟件測試 > 開源功能測試工具 > Selenium
使用selenium在網(wǎng)站自動化測試中的實踐
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時間:[ 2013/2/6 14:39:54 ] 推薦標(biāo)簽:

使用selenium在網(wǎng)站自動化測試中的實踐

近用selenium在做網(wǎng)站自動化,按照google用selenium的經(jīng)驗做了一些嘗試。
     主要分成了4層,這樣做主要是為了對于代碼重用性的考慮。
     第一層是UIobject,主要是對于頁面上的UI做了一些封裝
    
MILY: Consolas, 'Courier New', Courier, mono; BACKGROUND-COLOR: transparent; WORD-WRAP: break-word">
Java代碼 javascripts/syntaxhighlighter/clipboard_new.swf width=14 height=15 type=application/x-shockwave-flash flashvars="clipboard=public%20class%20SelectUIObject%20extends%20UIObjiect%20%7B%0A%0A%20%20%20%20private%20SeleniumHelper%20helper%20%3D%20new%20SeleniumHelper()%3B%0A%20%20%20%20public%20String%20read(String%20locator)%7B%0A%20%20%20%20%20%20%20%20return%20%20helper.getSelectOptions(%20locator)%3B%0A%20%20%20%20%7D%3B%0A%20%20%20%20public%20void%20write(String%20locator%2C%20String%20value)%20%7B%0A%20%20%20%20%20%20%20String%20selectValue%20%3D%22label%3D%22%2Bvalue%3B%0A%20%20%20%20%20%20%20%20helper.select(locator%2C%20selectValue)%3B%0A%20%20%20%20%7D%0A%7D%0A%20%20%20%20%20%20%20" quality="high" allowscriptaclearcase/" target="_blank" >ccess="always">

    public class SelectUIObject extends UIObjiect { 
     
        private SeleniumHelper helper = new SeleniumHelper(); 
        public String read(String locator){ 
            return  helper.getSelectOptions( locator); 
        }; 
        public void write(String locator, String value) { 
           String selectValue ="label="+value; 
            helper.select(locator, selectValue); 
        } 
    } 
            


   其中的SeleniumHelper是一些基本selenium的客戶端的封裝,如;
Java代碼 TestCase.browser.getSelectOptions(locator)%3B%0A%20%20%20%20%20%20%20%20String%20value%20%3D%20%22%22%3B%0A%20%20%20%20%20%20%20%20for%20(int%20i%20%3D%200%3B%20i%20%3C%20values.length%3B%20i%2B%2B)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20value%20%3D%20value%20%2B%20values%5Bi%5D%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20value%20%3D%20value%20%2B%20'%2C'%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20return%20value%3B%0A%20%20%20%20%7D%0A%7D" quality="high" allowscriptaccess="always">

    public String getSelectOptions(String locator) { 
        String[] values = SeleniumTestCase.browser.getSelectOptions(locator); 
        String value = ""; 
        for (int i = 0; i < values.length; i++) { 
            value = value + values[i]; 
            value = value + ','; 
        } 
        return value; 
    } 


   第二層頁面層,主要是頁面的ui的封裝 。如
Java代碼

    /**
     * 搜索價格
     * @param price 單位下拉
     * @param maxPrice 高價格
     * @param minPrice 低價格
     */ 
        public void searchPrice(String price,String maxPrice,String minPrice) { 
            selectUI.write("o.121", price); 
            textUI.write("o.price", minPrice); 
            textUI.write("document.forms[1].elements[4]", maxPrice); 
            LinkUI.write("document.forms[1].elements[5]"); 
            waitForPageToLoad("30000"); 
        } 

這里有些問題,主要頁面上的元素的定位,還是在代碼中寫死,對于頁面的改版還是需要修改源代碼

軟件測試工具 | 聯(lián)系我們 | 投訴建議 | 誠聘英才 | 申請使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd