Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   * Copyright 2011 NativeDriver committers Copyright 2011 Google Inc.
   * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
   * in compliance with the License. You may obtain a copy of the License at
   * Unless required by applicable law or agreed to in writing, software distributed under the License
  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
  * or implied. See the License for the specific language governing permissions and limitations under
  * the License.
 import static java.util.concurrent.TimeUnit.MILLISECONDS;
 import static java.util.concurrent.TimeUnit.SECONDS;
 import  io.selendroid.util.Function;

An implementation of the Wait interface that makes use of Android Native WebDriver.

Tomohiro Kaizu
 public class AndroidWait implements Wait<Void> {
   public static final long DEFAULT_SLEEP_INTERVAL = 200;
   private static final long DEFAULT_TIMEOUT = 5000;
   private final Clock clock;
   private final long sleepIntervalInMillis;
   private long timeoutInMillis;

Constructs an instance with default settings: 100 ms for sleep interval and 1 second for timeout.
   public AndroidWait() {


clock clock to use when measuring the timeout
sleepIntervalInMillis amount of time to sleep between attempts in milliseconds
timeoutInMillis timeout in milliseconds
   protected AndroidWait(Clock clocklong sleepIntervalInMillislong timeoutInMillis) {
     this. = clock;
     this. = sleepIntervalInMillis;
     this. = timeoutInMillis;
   public <T> T until(Function<Void, T> isTrue) {
     long end = .laterBy();
     NotFoundException lastException = null;
     do {
       try {
         T value = isTrue.apply(null);
         if (value != null && !..equals(value)) {
           return value;
       } catch (NotFoundException exception) {
         // Common case in many conditions, so swallow here, but be ready to
         // rethrow if it the element never appears.
         lastException = exception;
     } while (.isNowBefore(end));
     throw new TimeoutException(String.format("Timed out after %d seconds",
         .convert()), lastException);

Sleeps for a few milliseconds.
   protected void sleep() {
     try {
     } catch (InterruptedException exception) {
       throw new SelendroidException(exception);

Sets the time limit in milliseconds.

timeoutInMillis time limit
  public void setTimeoutInMillis(long timeoutInMillis) {
    this. = timeoutInMillis;

Gets the time limit in milliseconds.

time limit
  public long getTimeoutInMillis() {
    return ;
New to GrepCode? Check out our FAQ X