2014-12-02 106 views
0

任何人都可以請幫助如何找到一個搜索結果有多個結果使用硒和TestNG。方案如下:如何驗證搜索結果是否有多個結果?

  1. 啓動www.amazon.com
  2. 在搜索框中輸入搜索字符串,然後單擊搜索

現在驗證搜索結果中有更多然後1次的結果(> 1)。以下是我想到的線Assert.assertEquals(actual, expected, delta);。這是正確的方法嗎?

回答

0

請嘗試下面的代碼。它提取所有搜索結果,然後檢查計數是否大於1,然後相應地打印。 : -

driver.get("http://www.amazon.in/"); 

    driver.findElement(By.id("twotabsearchtextbox")).sendKeys("bagsasdfafds"); 

    int count = driver.findElements(By.className("suggest_link")).size(); 

    Assert.assertTrue(count>=1); 
    System.out.println("Count is greater than or equal to 1. Count is: "+count);//This line will ONLY be printed if the count is greater than or equal to 1. 
+0

這樣測試將在這兩種情況下傳似即使是小於1。我想提出一個斷言此所以,如果是小於1的測試應該失敗。 – Venki 2014-12-03 09:11:17

+0

@Venki:請現在檢查..已使用** Assert類** ..使用代碼'import junit.framework.Assert;'在頂部導入它。 – Subh 2014-12-05 17:40:41

+0

它工作正常。謝謝。 – Venki 2015-01-08 09:45:56