2014-01-07 41 views
0

尊敬的Robotium/Android社區。我是Robotium的新手,希望有人能幫助我指導正確的方法來檢測&在滑動(拖動)以更改頁面後,驗證當前正在查看的頁面。Robotium:如何驗證當前正在查看的頁面?

該測試旨在驗證在Android Home中更改頁面的操作。所以腳本啓動啓動器活動,並且測試步驟使用'solo.drag'來模擬左/右手勢的滑動以更改默認主頁中的頁面。

更具體地說,我的問題是:

1)之前,改變網頁,我需要一個測試步驟驗證啓動時的默認頁面確實是默認的主頁(用白色小家圖標表示)。 2)執行頁面更改(通過solo.drag)測試步驟需要檢測更改並返回成功或失敗

僅供參考,solo.drag的測試步驟目前看起來如下,沒有任何形式的驗證:

public void testScrollRight() throws Exception { 
    // *** require verification of current page here *** 
    //drag(float fromX, float toX, float fromY, float toY, int stepCount) 
    solo.drag(400, 950, 1500, 1440, 40); 
    // *** require verification of page change here *** 
} 
+0

很難不知道什麼對你的主頁和其他頁面回答。我最喜歡的方式是判斷我的應用是否在正確的位置,以檢查是否有預期的文字可見。例如assertTrue(solo.waitForText(「你知道的一些字符串在主頁上)」); –

+0

感謝這聽起來像一個有用的檢查 - 所以waitForText會找到該字符串,如果它出現在當前屏幕上? – mactwixs

+0

是的,這是正確的。 –

回答

3

您可以使用此方法的一個斷言你會看到屏幕上的活動:

void assertCurrentActivity(String message, Class activityClass) 
// Asserts that the Activity matching the specified class is active. 

void assertCurrentActivity(String message, Class activityClass, boolean isNewInstance) 
// Asserts that the Activity matching the specified class is active, with the possibility to // verify that the expected Activity is a new instance of the Activity. 

void assertCurrentActivity(String message, String name) 
//Asserts that the Activity matching the specified name is active. 

void assertCurrentActivity(String message, String name, boolean isNewInstance) 
//Asserts that the Activity matching the specified name is active, with the possibility to //verify that the expected Activity is a new instance of the Activity. 
相關問題