2016-09-07 107 views
0

任何人都知道驗證視圖(homePage/Browse)的自動化腳本是否可滾動。我可以使用頁面底部的ScrollTo(id)。但它不是一個正確的方法,因爲如果測試用例通過,如果該元素出現在第一頁如何驗證視圖在移動應用程序中可滾動(自動化)

+0

工作,這appium-Java的客戶端使用的是按照知識ScrollTo()沒有更多的在appium? –

回答

0

基本上你不能。您可以嘗試將視圖轉換爲ScrollView類,但是任何自定義視圖都可以實現滾動。

0

您可以將最後一個可見元素視爲「YourText」,但這僅僅是需要爲每個頁面定製的解決方法。

這裏我們使用滑動直到找到元素。在這種情況下,最後一個可見元素表示頁面的邊距。

Dimension dimensions = driver.manage().window().getSize(); 
Double screenHeightStart = dimensions.getHeight() * 0.5; 
int scrollStart = screenHeightStart.intValue(); 
System.out.println("s="+scrollStart); 
Double screenHeightEnd = dimensions.getHeight() * 0.2; 
int scrollEnd = screenHeightEnd.intValue(); 
for (int i = 0; i < dimensions.getHeight(); i++) { 
driver.swipe(0,scrollStart,0,scrollEnd,2000); 
if (driver.findElement(By.name("YourText")).size()>0) 
exit; 
} 
driver.findElement(By.name("YourText")).click(); 
0

獲取像按鈕等獨特元素的任何特定元素的座標。

使用driver.swipe()滑動到100或更多像素。

再次獲取該元素的座標並檢查x或y座標是否更改。

這將讓你知道它是一個單頁面應用程序還是更多的滾動。

0

基本上沒有API來檢查的觀點是滾動或沒有,但如果你仍然需要這個,那麼你可以做的周圍

@Test 
    public void testVerticalScroll() 
    { 
     //Try to Scroll till the 15th row 
     driver.scrollTo("List item:15"); 
     //Assert that the 1st row is not visible. 
     Assert.assertFalse(driver.findElement(By.name("List item:01")).isDiaplyes()) 
     //Assert that the 15th row is not visible. 
     Assert.assertTrue(driver.findElement(By.name("List item:15")).isDiaplyes()) 

    } 
相關問題