• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2013 DroidDriver committers
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package io.appium.droiddriver;
18 
19 import android.graphics.Bitmap.CompressFormat;
20 
21 import io.appium.droiddriver.actions.Action;
22 
23 /**
24  * Interface for device-wide interaction.
25  */
26 public interface UiDevice {
27   /**
28    * Returns whether the screen is on.
29    */
isScreenOn()30   boolean isScreenOn();
31 
32   /** Wakes up device if the screen is off */
wakeUp()33   void wakeUp();
34 
35   /** Puts device to sleep if the screen is on */
sleep()36   void sleep();
37 
38   /** Simulates pressing "back" button */
pressBack()39   void pressBack();
40 
41   /**
42    * Executes a global action without the context of a certain UiElement.
43    *
44    * @param action The action to execute
45    * @return true if the action is successful
46    */
perform(Action action)47   boolean perform(Action action);
48 
49   /**
50    * Takes a screenshot of current window and stores it in {@code path} as PNG.
51    * <p>
52    * If this is used in a test which extends
53    * {@link android.test.ActivityInstrumentationTestCase2}, call this before
54    * {@code tearDown()} because {@code tearDown()} finishes activities created
55    * by {@link android.test.ActivityInstrumentationTestCase2#getActivity()}.
56    *
57    * @param path the path of file to save screenshot
58    * @return true if screen shot is created successfully
59    */
takeScreenshot(String path)60   boolean takeScreenshot(String path);
61 
62   /**
63    * Takes a screenshot of current window and stores it in {@code path}. Note
64    * some implementations may not capture everything on the screen, for example
65    * InstrumentationDriver may not see the IME soft keyboard or system content.
66    *
67    * @param path the path of file to save screenshot
68    * @param format The format of the compressed image
69    * @param quality Hint to the compressor, 0-100. 0 meaning compress for small
70    *        size, 100 meaning compress for max quality. Some formats, like PNG
71    *        which is lossless, will ignore the quality setting
72    * @return true if screen shot is created successfully
73    */
takeScreenshot(String path, CompressFormat format, int quality)74   boolean takeScreenshot(String path, CompressFormat format, int quality);
75 }
76