View Javadoc

1   package com.atlassian.selenium;
2   
3   import com.atlassian.performance.EventTime;
4   import com.thoughtworks.selenium.Selenium;
5   
6   class TimedWaitFor implements EventTime.TimedEvent
7   {
8       private ByTimeoutConfiguration config;
9       private Selenium client;
10  
11      public TimedWaitFor(ByTimeoutConfiguration config, Selenium client)
12      {
13          this.config = config;
14          this.client = client;
15      }
16  
17      public boolean run()
18      {
19          long startTime = System.currentTimeMillis();
20          while (true)
21          {
22              long timePassed = System.currentTimeMillis() - startTime;
23              if (timePassed >= config.getMaxWaitTime())
24              {
25                  if(config.getCondition().executeTest(client))
26                  {
27                      return false;
28                  }
29                  else
30                  {
31                      //Timed out waiting for condition
32                      return true;
33                  }
34  
35              }
36              else if (config.getCondition().executeTest(client))
37              {
38                  return false;
39              }
40  
41              try
42              {
43                  Thread.sleep(config.getConditionCheckInterval());
44              }
45              catch (InterruptedException e)
46              {
47                  throw new RuntimeException("Thread was interupted", e);
48              }
49          }
50      }
51  }