2013-06-24 28 views
1

我想通過使用robotium爲我們的Android應用程序構建自動化測試用例環境。儘管robotium現在可以運行,但我仍然對如何使測試案例更簡潔或有組織感到困惑。現在測試案例看起來非常複雜和混亂。 當我使用硒時,有一個pagefactory模式。機器人中是否有像pagefactory一樣的模式?

有沒有像在robotium什麼?

回答

1

使用頁面對象,你可以檢查出Robotium-Sandwich項目。 Robotium-Sandwich使得爲Robotium創建頁面對象變得非常容易。

5

首先,你需要頁面對象頁廠兩種模式之間的區別。

  • The 頁面對象模式通過製作表示網頁的類(或moiv應用程序中的equivilent)來實現。
  • 頁面出廠圖案是頁面對象Abstract Factory圖案的組合。硒不來帶班實行 PageObject廠格局,但實現可能會非常棘手且容易出錯,我的同事和我還沒有找到它需要使用。

因此,由於頁面對象模式是你真正想要的是什麼,我會告訴你我的一些同事和我都想出以實現Robotium這種模式。

在Robotium,硒的webdriver的粗糙equivilent是獨奏類。它基本上是一個decorator爲一堆其他對象一次(你可以看到GitHub Repository所有涉及的類的列表)。

實現與Robotium獨奏對象頁對象的模式,先用一個個領域的抽象頁面對象開始(如硒,你將有一個現場的webdriver)。

public abstract class AppPage { 

    private Solo solo; 

    public AppPage(Solo solo) { 
     this.solo = solo; 
    } 

    public Solo getSolo() { 
     return this.solo; 
    } 
} 

然後,延長AppPage的每一頁,就像這樣:

public class MainPage extends AppPage { 

    public MainPage(Solo solo) { 
     super(solo); 
    } 

    // It is useful to be able to chain methods together. 

    // For public methods that direct you to other pages, 
    // return the Page Object for that page. 
    public OptionsPage options() { 
     getSolo().clickOnButton(getSolo().getString(R.string.options_button)); 
     return new OptionsPage(getSolo()); 
    } 

    //For public methods that DON'T direct you to other pages, return this. 
    public MainPage searchEntries(String searchWord) { 
     EditText search = (EditText) solo.getView(R.id.search_field); 
     solo.enterText(search, searchWord); 
     return this; 
    } 
} 

有很多更有趣的東西落實在Robotium頁面對象模式時,你可以這樣做,但是這將讓你開始在正確的方向。

相關問題