170e34108e0fc19277e642aef3b36b65b8e254899Kevin Jin/* 270e34108e0fc19277e642aef3b36b65b8e254899Kevin Jin * Copyright (C) 2013 DroidDriver committers 370e34108e0fc19277e642aef3b36b65b8e254899Kevin Jin * 470e34108e0fc19277e642aef3b36b65b8e254899Kevin Jin * Licensed under the Apache License, Version 2.0 (the "License"); 570e34108e0fc19277e642aef3b36b65b8e254899Kevin Jin * you may not use this file except in compliance with the License. 670e34108e0fc19277e642aef3b36b65b8e254899Kevin Jin * You may obtain a copy of the License at 770e34108e0fc19277e642aef3b36b65b8e254899Kevin Jin * 870e34108e0fc19277e642aef3b36b65b8e254899Kevin Jin * http://www.apache.org/licenses/LICENSE-2.0 970e34108e0fc19277e642aef3b36b65b8e254899Kevin Jin * 1070e34108e0fc19277e642aef3b36b65b8e254899Kevin Jin * Unless required by applicable law or agreed to in writing, software 1170e34108e0fc19277e642aef3b36b65b8e254899Kevin Jin * distributed under the License is distributed on an "AS IS" BASIS, 1270e34108e0fc19277e642aef3b36b65b8e254899Kevin Jin * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1370e34108e0fc19277e642aef3b36b65b8e254899Kevin Jin * See the License for the specific language governing permissions and 1470e34108e0fc19277e642aef3b36b65b8e254899Kevin Jin * limitations under the License. 1570e34108e0fc19277e642aef3b36b65b8e254899Kevin Jin */ 1670e34108e0fc19277e642aef3b36b65b8e254899Kevin Jin 174b31201b5a2dbf8036da5a8d089a68a39cc1dc44Kevin Jinpackage io.appium.droiddriver; 1870e34108e0fc19277e642aef3b36b65b8e254899Kevin Jin 19f50519233078e65a056cff49d7b4989d57c3e750Kevin Jinimport android.graphics.Bitmap.CompressFormat; 20f50519233078e65a056cff49d7b4989d57c3e750Kevin Jin 214b31201b5a2dbf8036da5a8d089a68a39cc1dc44Kevin Jinimport io.appium.droiddriver.actions.Action; 2270e34108e0fc19277e642aef3b36b65b8e254899Kevin Jin 2370e34108e0fc19277e642aef3b36b65b8e254899Kevin Jin/** 2470e34108e0fc19277e642aef3b36b65b8e254899Kevin Jin * Interface for device-wide interaction. 2570e34108e0fc19277e642aef3b36b65b8e254899Kevin Jin */ 2670e34108e0fc19277e642aef3b36b65b8e254899Kevin Jinpublic interface UiDevice { 2770e34108e0fc19277e642aef3b36b65b8e254899Kevin Jin /** 2870e34108e0fc19277e642aef3b36b65b8e254899Kevin Jin * Returns whether the screen is on. 2970e34108e0fc19277e642aef3b36b65b8e254899Kevin Jin */ 3070e34108e0fc19277e642aef3b36b65b8e254899Kevin Jin boolean isScreenOn(); 3170e34108e0fc19277e642aef3b36b65b8e254899Kevin Jin 3270e34108e0fc19277e642aef3b36b65b8e254899Kevin Jin /** Wakes up device if the screen is off */ 3370e34108e0fc19277e642aef3b36b65b8e254899Kevin Jin void wakeUp(); 3470e34108e0fc19277e642aef3b36b65b8e254899Kevin Jin 3570e34108e0fc19277e642aef3b36b65b8e254899Kevin Jin /** Puts device to sleep if the screen is on */ 3670e34108e0fc19277e642aef3b36b65b8e254899Kevin Jin void sleep(); 3770e34108e0fc19277e642aef3b36b65b8e254899Kevin Jin 3846cbd1ba6301e660d32bed661bd65994d4911c4eKevin Jin /** Simulates pressing "back" button */ 3946cbd1ba6301e660d32bed661bd65994d4911c4eKevin Jin void pressBack(); 4046cbd1ba6301e660d32bed661bd65994d4911c4eKevin Jin 4170e34108e0fc19277e642aef3b36b65b8e254899Kevin Jin /** 4270e34108e0fc19277e642aef3b36b65b8e254899Kevin Jin * Executes a global action without the context of a certain UiElement. 4370e34108e0fc19277e642aef3b36b65b8e254899Kevin Jin * 4470e34108e0fc19277e642aef3b36b65b8e254899Kevin Jin * @param action The action to execute 4570e34108e0fc19277e642aef3b36b65b8e254899Kevin Jin * @return true if the action is successful 4670e34108e0fc19277e642aef3b36b65b8e254899Kevin Jin */ 4770e34108e0fc19277e642aef3b36b65b8e254899Kevin Jin boolean perform(Action action); 48f50519233078e65a056cff49d7b4989d57c3e750Kevin Jin 49f50519233078e65a056cff49d7b4989d57c3e750Kevin Jin /** 50f50519233078e65a056cff49d7b4989d57c3e750Kevin Jin * Takes a screenshot of current window and stores it in {@code path} as PNG. 51a5bb27d69e8501b7c8321b838646d0b8f6fa0d05Kevin Jin * <p> 52a5bb27d69e8501b7c8321b838646d0b8f6fa0d05Kevin Jin * If this is used in a test which extends 53a5bb27d69e8501b7c8321b838646d0b8f6fa0d05Kevin Jin * {@link android.test.ActivityInstrumentationTestCase2}, call this before 54a5bb27d69e8501b7c8321b838646d0b8f6fa0d05Kevin Jin * {@code tearDown()} because {@code tearDown()} finishes activities created 55a5bb27d69e8501b7c8321b838646d0b8f6fa0d05Kevin Jin * by {@link android.test.ActivityInstrumentationTestCase2#getActivity()}. 56f50519233078e65a056cff49d7b4989d57c3e750Kevin Jin * 57f50519233078e65a056cff49d7b4989d57c3e750Kevin Jin * @param path the path of file to save screenshot 58f50519233078e65a056cff49d7b4989d57c3e750Kevin Jin * @return true if screen shot is created successfully 59f50519233078e65a056cff49d7b4989d57c3e750Kevin Jin */ 60f50519233078e65a056cff49d7b4989d57c3e750Kevin Jin boolean takeScreenshot(String path); 61f50519233078e65a056cff49d7b4989d57c3e750Kevin Jin 62f50519233078e65a056cff49d7b4989d57c3e750Kevin Jin /** 63f50519233078e65a056cff49d7b4989d57c3e750Kevin Jin * Takes a screenshot of current window and stores it in {@code path}. Note 64f50519233078e65a056cff49d7b4989d57c3e750Kevin Jin * some implementations may not capture everything on the screen, for example 65f50519233078e65a056cff49d7b4989d57c3e750Kevin Jin * InstrumentationDriver may not see the IME soft keyboard or system content. 66f50519233078e65a056cff49d7b4989d57c3e750Kevin Jin * 67f50519233078e65a056cff49d7b4989d57c3e750Kevin Jin * @param path the path of file to save screenshot 68f50519233078e65a056cff49d7b4989d57c3e750Kevin Jin * @param format The format of the compressed image 69f50519233078e65a056cff49d7b4989d57c3e750Kevin Jin * @param quality Hint to the compressor, 0-100. 0 meaning compress for small 70f50519233078e65a056cff49d7b4989d57c3e750Kevin Jin * size, 100 meaning compress for max quality. Some formats, like PNG 71f50519233078e65a056cff49d7b4989d57c3e750Kevin Jin * which is lossless, will ignore the quality setting 72f50519233078e65a056cff49d7b4989d57c3e750Kevin Jin * @return true if screen shot is created successfully 73f50519233078e65a056cff49d7b4989d57c3e750Kevin Jin */ 74f50519233078e65a056cff49d7b4989d57c3e750Kevin Jin boolean takeScreenshot(String path, CompressFormat format, int quality); 7570e34108e0fc19277e642aef3b36b65b8e254899Kevin Jin} 76