经过随机的迭代次数点击后,selenium webdriver测试停止

时间:2015-11-19 11:29:09

标签: java vb.net selenium automated-tests qa

我测试用VB.NET编写的Web应用程序。该应用程序使用许多嵌套的iframe。其中一个框架是项目列表。在第二帧中出现的字段与选择第一帧的特定元素一起填充了从数据库中检索到的关于该项目的信息。

我想创建一个性能测试,检查从单击加载数据所经过的时间。

点击加载数据后出现gif-animation,表示此操作。此时,我检查动画是否消失,然后继续下一次单击。我在java中编写代码,我的函数如下所示:

public void function(int i, int repeat){
             for(int a = 0; a<repeat; a++){
                 driver.switchTo().defaultContent();
                 driver.switchTo().frame("MyFrame");
                 driver.switchTo().frame("frame_Left");
                 driver.switchTo().frame("Elements");

                 List<WebElement> ele4 = driver.findElements(By.tagName("tr"));
                 long start=System.currentTimeMillis(); 
                 wait.until(ExpectedConditions.elementToBeClickable(ele4.get(i)));
                 ele4.get(i).findElement(By.xpath("td/div/a")).click();

                 driver.switchTo().defaultContent();
                 driver.switchTo().frame("MyFrame");
                 driver.switchTo().frame("frame_Right");
                 wait.until(ExpectedConditions.invisibilityOfElementLocated((By.xpath("//*[@src='/directiory/Loading.gif']"))));
                 long stop=System.currentTimeMillis();  

                 System.out.println("Time: "+(stop-start) + "\n");
                 ele4.clear();
              }
}

在某个随机时刻,自动测试会停止点击。应该遵循的其他操作也会停止。他没有报告任何错误或例外情况。当我手动点击一个有趣的元素,使测试再次恢复.m但随机迭代次数后循环问题重复。 我怎么能解决这个问题?

2 个答案:

答案 0 :(得分:0)

注意:这只是示例解决方案 - 请尝试查看

for(int counter = 0;counter<4;counter++)
    {
     try
       { 
       // Your Code for Clicking The element i.e - ele4.get(i).findElement(By.xpath("td/div/a")).click();
       }
       catch
       {
        // If the First click is a success  second  click will throw an exception which means you have proceed to the next step
        break;
       }
    }

P.S - 如果点击之间需要更多等待时间,请添加一个Thread.Sleep()

答案 1 :(得分:0)

最后我将测试重写为C#。据我所知,Java不支持点击超时。 C#中的类似代码不会冻结我的程序,但是在60秒后抛出异常(在我的情况下是可取的)。 Java中的相同程序在Windows 10上的工作原理与IE版本稍微高一点(在我使用Windows 8之前)。我不知道为什么会这样,但也许它可能是未来某人的线索。