2014-12-02 105 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