Best io.appium code snippet using io.appium.java_client.CommandExecutionHelper
AndroidDriver.java
Source:AndroidDriver.java
...29import static io.appium.java_client.android.AndroidMobileCommandHelper.toggleLocationServicesCommand;30import static io.appium.java_client.android.AndroidMobileCommandHelper.unlockCommand;31import io.appium.java_client.AppiumDriver;32import io.appium.java_client.AppiumSetting;33import io.appium.java_client.CommandExecutionHelper;34import io.appium.java_client.FindsByAndroidUIAutomator;35import io.appium.java_client.MobileSelector;36import io.appium.java_client.android.internal.JsonToAndroidElementConverter;37import io.appium.java_client.remote.MobilePlatform;38import io.appium.java_client.service.local.AppiumDriverLocalService;39import io.appium.java_client.service.local.AppiumServiceBuilder;40import org.apache.commons.codec.binary.Base64;41import org.apache.commons.io.FileUtils;42import org.openqa.selenium.Capabilities;43import org.openqa.selenium.WebDriverException;44import org.openqa.selenium.WebElement;45import org.openqa.selenium.remote.HttpCommandExecutor;46import org.openqa.selenium.remote.http.HttpClient;47import java.io.File;48import java.io.IOException;49import java.net.URL;50import java.util.List;51/**52 * @param <T> the required type of class which implement {@link org.openqa.selenium.WebElement}.53 * Instances of the defined type will be returned via findElement* and findElements*.54 * Warning (!!!). Allowed types:55 * {@link org.openqa.selenium.WebElement}56 * {@link io.appium.java_client.TouchableElement}57 * {@link org.openqa.selenium.remote.RemoteWebElement}58 * {@link io.appium.java_client.MobileElement}59 * {@link io.appium.java_client.android.AndroidElement}60 */61public class AndroidDriver<T extends WebElement>62 extends AppiumDriver<T>63 implements AndroidDeviceActionShortcuts, HasNetworkConnection, PushesFiles, StartsActivity,64 FindsByAndroidUIAutomator<T> {65 private static final String ANDROID_PLATFORM = MobilePlatform.ANDROID;66 /**67 * @param executor is an instance of {@link org.openqa.selenium.remote.HttpCommandExecutor}68 * or class that extends it. Default commands or another vendor-specific69 * commands may be specified there.70 * @param capabilities take a look71 * at {@link org.openqa.selenium.Capabilities}72 */73 public AndroidDriver(HttpCommandExecutor executor, Capabilities capabilities) {74 super(executor, capabilities, JsonToAndroidElementConverter.class);75 }76 /**77 * @param remoteAddress is the address of remotely/locally78 * started Appium server79 * @param desiredCapabilities take a look80 * at {@link org.openqa.selenium.Capabilities}81 */82 public AndroidDriver(URL remoteAddress, Capabilities desiredCapabilities) {83 super(remoteAddress, substituteMobilePlatform(desiredCapabilities, ANDROID_PLATFORM),84 JsonToAndroidElementConverter.class);85 }86 /**87 * @param remoteAddress is the address of remotely/locally88 * started Appium server89 * @param httpClientFactory take a look90 * at {@link org.openqa.selenium.remote.http.HttpClient.Factory}91 * @param desiredCapabilities take a look92 * at {@link org.openqa.selenium.Capabilities}93 */94 public AndroidDriver(URL remoteAddress, HttpClient.Factory httpClientFactory,95 Capabilities desiredCapabilities) {96 super(remoteAddress, httpClientFactory,97 substituteMobilePlatform(desiredCapabilities, ANDROID_PLATFORM),98 JsonToAndroidElementConverter.class);99 }100 /**101 * @param service take a look102 * at {@link io.appium.java_client.service.local.AppiumDriverLocalService}103 * @param desiredCapabilities take a look104 * at {@link org.openqa.selenium.Capabilities}105 */106 public AndroidDriver(AppiumDriverLocalService service, Capabilities desiredCapabilities) {107 super(service, substituteMobilePlatform(desiredCapabilities, ANDROID_PLATFORM),108 JsonToAndroidElementConverter.class);109 }110 /**111 * @param service take a look112 * at {@link io.appium.java_client.service.local.AppiumDriverLocalService}113 * @param httpClientFactory take a look114 * at {@link org.openqa.selenium.remote.http.HttpClient.Factory}115 * @param desiredCapabilities take a look116 * at {@link org.openqa.selenium.Capabilities}117 */118 public AndroidDriver(AppiumDriverLocalService service, HttpClient.Factory httpClientFactory,119 Capabilities desiredCapabilities) {120 super(service, httpClientFactory,121 substituteMobilePlatform(desiredCapabilities, ANDROID_PLATFORM),122 JsonToAndroidElementConverter.class);123 }124 /**125 * @param builder take a look126 * at {@link io.appium.java_client.service.local.AppiumServiceBuilder}127 * @param desiredCapabilities take a look128 * at {@link org.openqa.selenium.Capabilities}129 */130 public AndroidDriver(AppiumServiceBuilder builder, Capabilities desiredCapabilities) {131 super(builder, substituteMobilePlatform(desiredCapabilities, ANDROID_PLATFORM),132 JsonToAndroidElementConverter.class);133 }134 /**135 * @param builder take a look136 * at {@link io.appium.java_client.service.local.AppiumServiceBuilder}137 * @param httpClientFactory take a look138 * at {@link org.openqa.selenium.remote.http.HttpClient.Factory}139 * @param desiredCapabilities take a look140 * at {@link org.openqa.selenium.Capabilities}141 */142 public AndroidDriver(AppiumServiceBuilder builder, HttpClient.Factory httpClientFactory,143 Capabilities desiredCapabilities) {144 super(builder, httpClientFactory,145 substituteMobilePlatform(desiredCapabilities, ANDROID_PLATFORM),146 JsonToAndroidElementConverter.class);147 }148 /**149 * @param httpClientFactory take a look150 * at {@link org.openqa.selenium.remote.http.HttpClient.Factory}151 * @param desiredCapabilities take a look152 * at {@link org.openqa.selenium.Capabilities}153 */154 public AndroidDriver(HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities) {155 super(httpClientFactory, substituteMobilePlatform(desiredCapabilities, ANDROID_PLATFORM),156 JsonToAndroidElementConverter.class);157 }158 /**159 * @param desiredCapabilities take a look160 * at {@link org.openqa.selenium.Capabilities}161 */162 public AndroidDriver(Capabilities desiredCapabilities) {163 super(substituteMobilePlatform(desiredCapabilities, ANDROID_PLATFORM),164 JsonToAndroidElementConverter.class);165 }166 /**167 * @see io.appium.java_client.TouchShortcuts#swipe(int, int, int, int, int)168 */169 @Override public void swipe(int startx, int starty, int endx, int endy, int duration) {170 doSwipe(startx, starty, endx, endy, duration);171 }172 /**173 * Send a key event to the device.174 *175 * @param key code for the key pressed on the device.176 */177 @Override public void pressKeyCode(int key) {178 CommandExecutionHelper.execute(this, pressKeyCodeCommand(key));179 }180 /**181 * @param key code for the key pressed on the Android device.182 * @param metastate metastate for the keypress.183 * @see AndroidKeyCode184 * @see AndroidKeyMetastate185 * @see AndroidDeviceActionShortcuts#pressKeyCode(int, Integer).186 */187 @Override public void pressKeyCode(int key, Integer metastate) {188 CommandExecutionHelper.execute(this, pressKeyCodeCommand(key, metastate));189 }190 /**191 * Send a long key event to the device.192 *193 * @param key code for the long key pressed on the device.194 */195 @Override public void longPressKeyCode(int key) {196 CommandExecutionHelper.execute(this, longPressKeyCodeCommand(key));197 }198 /**199 * @param key code for the long key pressed on the Android device.200 * @param metastate metastate for the long key press.201 * @see AndroidKeyCode202 * @see AndroidKeyMetastate203 * @see AndroidDeviceActionShortcuts#pressKeyCode(int, Integer)204 */205 @Override public void longPressKeyCode(int key, Integer metastate) {206 CommandExecutionHelper.execute(this, longPressKeyCodeCommand(key, metastate));207 }208 @Override public void setConnection(Connection connection) {209 CommandExecutionHelper.execute(this, setConnectionCommand(connection));210 }211 @Override public Connection getConnection() {212 long bitMask = CommandExecutionHelper.execute(this, getNetworkConnectionCommand());213 Connection[] types = Connection.values();214 for (Connection connection: types) {215 if (connection.bitMask == bitMask) {216 return connection;217 }218 }219 throw new WebDriverException("The unknown network connection "220 + "type has been returned. The bitmask is " + bitMask);221 }222 @Override public void pushFile(String remotePath, byte[] base64Data) {223 CommandExecutionHelper.execute(this, pushFileCommandCommand(remotePath, base64Data));224 }225 @Override public void pushFile(String remotePath, File file) throws IOException {226 checkNotNull(file, "A reference to file should not be NULL");227 if (!file.exists()) {228 throw new IOException("The given file "229 + file.getAbsolutePath() + " doesn't exist");230 }231 pushFile(remotePath,232 Base64.encodeBase64(FileUtils.readFileToByteArray(file)));233 }234 @Override public void startActivity(String appPackage, String appActivity,235 String appWaitPackage,236 String appWaitActivity, String intentAction,237 String intentCategory, String intentFlags,238 String optionalIntentArguments,boolean stopApp )239 throws IllegalArgumentException {240 CommandExecutionHelper.execute(this, startActivityCommand(appPackage, appActivity,241 appWaitPackage, appWaitActivity, intentAction, intentCategory, intentFlags,242 optionalIntentArguments, stopApp));243 }244 @Override245 public void startActivity(String appPackage, String appActivity,246 String appWaitPackage, String appWaitActivity, boolean stopApp)247 throws IllegalArgumentException {248 this.startActivity(appPackage,appActivity,appWaitPackage,249 appWaitActivity,null,null,null,null,stopApp);250 }251 @Override public void startActivity(String appPackage, String appActivity,252 String appWaitPackage,253 String appWaitActivity) throws IllegalArgumentException {254 this.startActivity(appPackage, appActivity,255 appWaitPackage, appWaitActivity,null,null,null,null,true);256 }257 @Override public void startActivity(String appPackage, String appActivity)258 throws IllegalArgumentException {259 this.startActivity(appPackage, appActivity, null, null,260 null,null,null,null,true);261 }262 @Override public void startActivity(String appPackage, String appActivity,263 String appWaitPackage, String appWaitActivity,264 String intentAction,String intentCategory,265 String intentFlags,String intentOptionalArgs)266 throws IllegalArgumentException {267 this.startActivity(appPackage,appActivity,268 appWaitPackage,appWaitActivity,269 intentAction,intentCategory,intentFlags,intentOptionalArgs,true);270 }271 /**272 * Get test-coverage data.273 *274 * @param intent intent to broadcast.275 * @param path path to .ec file.276 */277 public void endTestCoverage(String intent, String path) {278 CommandExecutionHelper.execute(this, endTestCoverageCommand(intent, path));279 }280 /**281 * Get the current activity being run on the mobile device.282 *283 * @return a current activity being run on the mobile device.284 */285 public String currentActivity() {286 return CommandExecutionHelper.execute(this, currentActivityCommand());287 }288 /**289 * Open the notification shade, on Android devices.290 */291 public void openNotifications() {292 CommandExecutionHelper.execute(this, openNotificationsCommand());293 }294 /**295 * Check if the device is locked.296 *297 * @return true if device is locked. False otherwise298 */299 public boolean isLocked() {300 return CommandExecutionHelper.execute(this, isLockedCommand());301 }302 public void toggleLocationServices() {303 CommandExecutionHelper.execute(this, toggleLocationServicesCommand());304 }305 /**306 * Set the `ignoreUnimportantViews` setting. *Android-only method*.307 * Sets whether Android devices should use `setCompressedLayoutHeirarchy()`308 * which ignores all views which are marked IMPORTANT_FOR_ACCESSIBILITY_NO309 * or IMPORTANT_FOR_ACCESSIBILITY_AUTO (and have been deemed not important310 * by the system), in an attempt to make things less confusing or faster.311 *312 * @param compress ignores unimportant views if true, doesn't ignore otherwise.313 */314 // Should be moved to the subclass315 public void ignoreUnimportantViews(Boolean compress) {316 setSetting(AppiumSetting.IGNORE_UNIMPORTANT_VIEWS, compress);317 }318 /**319 * @throws WebDriverException This method is not320 * applicable with browser/webview UI.321 */322 @Override323 public T findElementByAndroidUIAutomator(String using)324 throws WebDriverException {325 return findElement(MobileSelector.ANDROID_UI_AUTOMATOR.toString(), using);326 }327 /**328 * @throws WebDriverException This method is not329 * applicable with browser/webview UI.330 */331 @Override332 public List<T> findElementsByAndroidUIAutomator(String using)333 throws WebDriverException {334 return findElements(MobileSelector.ANDROID_UI_AUTOMATOR.toString(), using);335 }336 /**337 * This method locks a device.338 */339 public void lockDevice() {340 CommandExecutionHelper.execute(this, lockDeviceCommand());341 }342 /**343 * This method unlocks a device.344 */345 public void unlockDevice() {346 CommandExecutionHelper.execute(this, unlockCommand());347 }348}...
IOSDriver.java
Source:IOSDriver.java
...18import static io.appium.java_client.ios.IOSMobileCommandHelper.hideKeyboardCommand;19import static io.appium.java_client.ios.IOSMobileCommandHelper.lockDeviceCommand;20import static io.appium.java_client.ios.IOSMobileCommandHelper.shakeCommand;21import io.appium.java_client.AppiumDriver;22import io.appium.java_client.CommandExecutionHelper;23import io.appium.java_client.FindsByIosUIAutomation;24import io.appium.java_client.MobileSelector;25import io.appium.java_client.ios.internal.JsonToIOSElementConverter;26import io.appium.java_client.remote.MobilePlatform;27import io.appium.java_client.service.local.AppiumDriverLocalService;28import io.appium.java_client.service.local.AppiumServiceBuilder;29import org.openqa.selenium.Alert;30import org.openqa.selenium.Capabilities;31import org.openqa.selenium.WebDriverException;32import org.openqa.selenium.WebElement;33import org.openqa.selenium.remote.DriverCommand;34import org.openqa.selenium.remote.HttpCommandExecutor;35import org.openqa.selenium.remote.Response;36import org.openqa.selenium.remote.http.HttpClient;37import org.openqa.selenium.security.Credentials;38import java.net.URL;39import java.util.List;40/**41 * @param <T> the required type of class which implement42 * {@link org.openqa.selenium.WebElement}.43 * Instances of the defined type will be returned via findElement* and findElements*.44 * Warning (!!!). Allowed types:45 * {@link org.openqa.selenium.WebElement}46 * {@link io.appium.java_client.TouchableElement}47 * {@link org.openqa.selenium.remote.RemoteWebElement}48 * {@link io.appium.java_client.MobileElement}49 * {@link io.appium.java_client.ios.IOSElement}50 */51public class IOSDriver<T extends WebElement>52 extends AppiumDriver<T>53 implements IOSDeviceActionShortcuts,54 FindsByIosUIAutomation<T> {55 private static final String IOS_PLATFORM = MobilePlatform.IOS;56 /**57 * @param executor is an instance of {@link org.openqa.selenium.remote.HttpCommandExecutor}58 * or class that extends it. Default commands or another vendor-specific59 * commands may be specified there.60 * @param capabilities take a look61 * at {@link org.openqa.selenium.Capabilities}62 */63 public IOSDriver(HttpCommandExecutor executor, Capabilities capabilities) {64 super(executor, capabilities, JsonToIOSElementConverter.class);65 }66 /**67 * @param remoteAddress is the address68 * of remotely/locally started Appium server69 * @param desiredCapabilities take a look70 * at {@link org.openqa.selenium.Capabilities}71 */72 public IOSDriver(URL remoteAddress, Capabilities desiredCapabilities) {73 super(remoteAddress, substituteMobilePlatform(desiredCapabilities, IOS_PLATFORM),74 JsonToIOSElementConverter.class);75 }76 /**77 * @param remoteAddress is the address78 * of remotely/locally started Appium server79 * @param httpClientFactory take a look80 * at {@link org.openqa.selenium.remote.http.HttpClient.Factory}81 * @param desiredCapabilities take a look82 * at {@link org.openqa.selenium.Capabilities}83 */84 public IOSDriver(URL remoteAddress, HttpClient.Factory httpClientFactory,85 Capabilities desiredCapabilities) {86 super(remoteAddress, httpClientFactory,87 substituteMobilePlatform(desiredCapabilities, IOS_PLATFORM),88 JsonToIOSElementConverter.class);89 }90 /**91 * @param service take a look92 * at {@link io.appium.java_client.service.local.AppiumDriverLocalService}93 * @param desiredCapabilities take a look94 * at {@link org.openqa.selenium.Capabilities}95 */96 public IOSDriver(AppiumDriverLocalService service, Capabilities desiredCapabilities) {97 super(service, substituteMobilePlatform(desiredCapabilities, IOS_PLATFORM),98 JsonToIOSElementConverter.class);99 }100 /**101 * @param service take a look102 * at {@link io.appium.java_client.service.local.AppiumDriverLocalService}103 * @param httpClientFactory take a look104 * at {@link org.openqa.selenium.remote.http.HttpClient.Factory}105 * @param desiredCapabilities take a look106 * at {@link org.openqa.selenium.Capabilities}107 */108 public IOSDriver(AppiumDriverLocalService service, HttpClient.Factory httpClientFactory,109 Capabilities desiredCapabilities) {110 super(service, httpClientFactory,111 substituteMobilePlatform(desiredCapabilities, IOS_PLATFORM),112 JsonToIOSElementConverter.class);113 }114 /**115 * @param builder take a look116 * at {@link io.appium.java_client.service.local.AppiumServiceBuilder}117 * @param desiredCapabilities take a look118 * at {@link org.openqa.selenium.Capabilities}119 */120 public IOSDriver(AppiumServiceBuilder builder, Capabilities desiredCapabilities) {121 super(builder, substituteMobilePlatform(desiredCapabilities, IOS_PLATFORM),122 JsonToIOSElementConverter.class);123 }124 /**125 * @param builder take a look126 * at {@link io.appium.java_client.service.local.AppiumServiceBuilder}127 * @param httpClientFactory take a look128 * at {@link org.openqa.selenium.remote.http.HttpClient.Factory}129 * @param desiredCapabilities take a look130 * at {@link org.openqa.selenium.Capabilities}131 */132 public IOSDriver(AppiumServiceBuilder builder, HttpClient.Factory httpClientFactory,133 Capabilities desiredCapabilities) {134 super(builder, httpClientFactory,135 substituteMobilePlatform(desiredCapabilities, IOS_PLATFORM),136 JsonToIOSElementConverter.class);137 }138 /**139 * @param httpClientFactory take a look140 * at {@link org.openqa.selenium.remote.http.HttpClient.Factory}141 * @param desiredCapabilities take a look142 * at {@link org.openqa.selenium.Capabilities}143 */144 public IOSDriver(HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities) {145 super(httpClientFactory, substituteMobilePlatform(desiredCapabilities, IOS_PLATFORM),146 JsonToIOSElementConverter.class);147 }148 /**149 * @param desiredCapabilities take a look150 * at {@link org.openqa.selenium.Capabilities}151 */152 public IOSDriver(Capabilities desiredCapabilities) {153 super(substituteMobilePlatform(desiredCapabilities, IOS_PLATFORM),154 JsonToIOSElementConverter.class);155 }156 /**157 * @see io.appium.java_client.TouchShortcuts#swipe(int, int, int, int, int).158 */159 @Override public void swipe(int startx, int starty, int endx, int endy, int duration) {160 doSwipe(startx, starty, endx - startx, endy - starty, duration);161 }162 /**163 * @see IOSDeviceActionShortcuts#hideKeyboard(String, String).164 */165 @Override public void hideKeyboard(String strategy, String keyName) {166 CommandExecutionHelper.execute(this, hideKeyboardCommand(strategy, keyName));167 }168 /**169 * @see IOSDeviceActionShortcuts#hideKeyboard(String).170 */171 @Override public void hideKeyboard(String keyName) {172 CommandExecutionHelper.execute(this, hideKeyboardCommand(keyName));173 }174 /**175 * @see IOSDeviceActionShortcuts#shake().176 */177 @Override public void shake() {178 CommandExecutionHelper.execute(this, shakeCommand());179 }180 /**181 * @throws WebDriverException182 * This method is not applicable with browser/webview UI.183 */184 @Override185 public T findElementByIosUIAutomation(String using)186 throws WebDriverException {187 return findElement(MobileSelector.IOS_UI_AUTOMATION.toString(), using);188 }189 /**190 * @throws WebDriverException This method is not applicable with browser/webview UI.191 */192 @Override193 public List<T> findElementsByIosUIAutomation(String using)194 throws WebDriverException {195 return findElements(MobileSelector.IOS_UI_AUTOMATION.toString(), using);196 }197 /**198 * Lock the device (bring it to the lock screen) for a given number of199 * seconds.200 *201 * @param seconds number of seconds to lock the screen for202 */203 public void lockDevice(int seconds) {204 CommandExecutionHelper.execute(this, lockDeviceCommand(seconds));205 }206 @Override public TargetLocator switchTo() {207 return new InnerTargetLocator();208 }209 private class InnerTargetLocator extends RemoteTargetLocator {210 @Override public Alert alert() {211 return new IOSAlert(super.alert());212 }213 }214 class IOSAlert implements Alert {215 private final Alert alert;216 IOSAlert(Alert alert) {217 this.alert = alert;218 }...
SupportsSpecialEmulatorCommands.java
Source:SupportsSpecialEmulatorCommands.java
...5import static io.appium.java_client.android.AndroidMobileCommandHelper.networkSpeedCommand;6import static io.appium.java_client.android.AndroidMobileCommandHelper.powerACCommand;7import static io.appium.java_client.android.AndroidMobileCommandHelper.powerCapacityCommand;8import static io.appium.java_client.android.AndroidMobileCommandHelper.sendSMSCommand;9import io.appium.java_client.CommandExecutionHelper;10import io.appium.java_client.ExecutesMethod;11public interface SupportsSpecialEmulatorCommands extends ExecutesMethod {12 /**13 * Emulate send SMS event on the connected emulator.14 *15 * @param phoneNumber The phone number of message sender.16 * @param message The message content.17 */18 default void sendSMS(String phoneNumber, String message) {19 CommandExecutionHelper.execute(this, sendSMSCommand(phoneNumber, message));20 }21 /**22 * Emulate GSM call event on the connected emulator.23 *24 * @param phoneNumber The phone number of the caller.25 * @param gsmCallActions One of available {@link GsmCallActions} values.26 */27 default void makeGsmCall(String phoneNumber, GsmCallActions gsmCallActions) {28 CommandExecutionHelper.execute(this, gsmCallCommand(phoneNumber, gsmCallActions));29 }30 /**31 * Emulate GSM signal strength change event on the connected emulator.32 *33 * @param gsmSignalStrength One of available {@link GsmSignalStrength} values.34 */35 default void setGsmSignalStrength(GsmSignalStrength gsmSignalStrength) {36 CommandExecutionHelper.execute(this, gsmSignalStrengthCommand(gsmSignalStrength));37 }38 /**39 * Emulate GSM voice event on the connected emulator.40 *41 * @param gsmVoiceState One of available {@link GsmVoiceState} values.42 */43 default void setGsmVoice(GsmVoiceState gsmVoiceState) {44 CommandExecutionHelper.execute(this, gsmVoiceCommand(gsmVoiceState));45 }46 /**47 * Emulate network speed change event on the connected emulator.48 *49 * @param networkSpeed One of available {@link NetworkSpeed} values.50 */51 default void setNetworkSpeed(NetworkSpeed networkSpeed) {52 CommandExecutionHelper.execute(this, networkSpeedCommand(networkSpeed));53 }54 /**55 * Emulate power capacity change on the connected emulator.56 *57 * @param percent Percentage value in range [0, 100].58 */59 default void setPowerCapacity(int percent) {60 CommandExecutionHelper.execute(this, powerCapacityCommand(percent));61 }62 /**63 * Emulate power state change on the connected emulator.64 *65 * @param powerACState One of available {@link PowerACState} values.66 */67 default void setPowerAC(PowerACState powerACState) {68 CommandExecutionHelper.execute(this, powerACCommand(powerACState));69 }70}
StartsActivity.java
Source:StartsActivity.java
...16package io.appium.java_client.android;17import static io.appium.java_client.android.AndroidMobileCommandHelper.currentActivityCommand;18import static io.appium.java_client.android.AndroidMobileCommandHelper.currentPackageCommand;19import static io.appium.java_client.android.AndroidMobileCommandHelper.startActivityCommand;20import io.appium.java_client.CommandExecutionHelper;21import io.appium.java_client.ExecutesMethod;22public interface StartsActivity extends ExecutesMethod {23 /**24 * This method should start arbitrary activity during a test. If the activity belongs to25 * another application, that application is started and the activity is opened.26 * <p>27 * Usage:28 * </p>29 * <pre>30 * {@code31 * Activity activity = new Activity("app package goes here", "app activity goes here");32 * activity.setWaitAppPackage("app wait package goes here");33 * activity.setWaitAppActivity("app wait activity goes here");34 * driver.startActivity(activity);35 * }36 * </pre>37 *38 * @param activity The {@link Activity} object39 */40 default void startActivity(Activity activity) {41 CommandExecutionHelper.execute(this,42 startActivityCommand(activity.getAppPackage(), activity.getAppActivity(),43 activity.getAppWaitPackage(), activity.getAppWaitActivity(),44 activity.getIntentAction(), activity.getIntentCategory(), activity.getIntentFlags(),45 activity.getOptionalIntentArguments(), activity.isStopApp()));46 }47 /**48 * Get the current activity being run on the mobile device.49 *50 * @return a current activity being run on the mobile device.51 */52 default String currentActivity() {53 return CommandExecutionHelper.execute(this, currentActivityCommand());54 }55 /**56 * Get the current package being run on the mobile device.57 *58 * @return a current package being run on the mobile device.59 */60 default String getCurrentPackage() {61 return CommandExecutionHelper.execute(this, currentPackageCommand());62 }63}...
AndroidElement.java
Source:AndroidElement.java
...14 * limitations under the License.15 */16package io.appium.java_client.android;17import static io.appium.java_client.android.AndroidMobileCommandHelper.replaceElementValueCommand;18import io.appium.java_client.CommandExecutionHelper;19import io.appium.java_client.FindsByAndroidUIAutomator;20import io.appium.java_client.MobileElement;21import io.appium.java_client.MobileSelector;22import org.openqa.selenium.WebDriverException;23import java.util.List;24public class AndroidElement extends MobileElement25 implements FindsByAndroidUIAutomator<MobileElement> {26 /**27 * @throws WebDriverException This method is not applicable with browser/webview UI.28 */29 @Override public MobileElement findElementByAndroidUIAutomator(String using)30 throws WebDriverException {31 return findElement(MobileSelector.ANDROID_UI_AUTOMATOR.toString(), using);32 }33 /**34 * @throws WebDriverException This method is not applicable with browser/webview UI.35 */36 @Override public List<MobileElement> findElementsByAndroidUIAutomator(String using)37 throws WebDriverException {38 return findElements(MobileSelector.ANDROID_UI_AUTOMATOR.toString(), using);39 }40 /**41 * This method replace current text value.42 * @param value a new value43 */44 public void replaceValue(String value) {45 CommandExecutionHelper.execute(this, replaceElementValueCommand(this, value));46 }47}...
LocksAndroidDevice.java
Source:LocksAndroidDevice.java
...17import static io.appium.java_client.MobileCommand.lockDeviceCommand;18import static io.appium.java_client.android.AndroidMobileCommandHelper.isLockedCommand;19import static io.appium.java_client.android.AndroidMobileCommandHelper.unlockCommand;20import static java.time.Duration.ofMillis;21import io.appium.java_client.CommandExecutionHelper;22import io.appium.java_client.ExecutesMethod;23import java.time.Duration;24public interface LocksAndroidDevice extends ExecutesMethod {25 /**26 * Check if the device is locked.27 *28 * @return true if device is locked. False otherwise29 */30 default boolean isLocked() {31 return CommandExecutionHelper.execute(this, isLockedCommand());32 }33 /**34 * This method locks a device.35 */36 default void lockDevice() {37 CommandExecutionHelper.execute(this, lockDeviceCommand(ofMillis(0)));38 }39 /**40 * This method unlocks a device.41 */42 default void unlockDevice() {43 CommandExecutionHelper.execute(this, unlockCommand());44 }45}...
HasDeviceDetails.java
Source:HasDeviceDetails.java
1package io.appium.java_client.android;2import static io.appium.java_client.android.AndroidMobileCommandHelper.getDisplayDensityCommand;3import static io.appium.java_client.android.AndroidMobileCommandHelper.getSystemBarsCommand;4import static io.appium.java_client.android.AndroidMobileCommandHelper.isKeyboardShownCommand;5import io.appium.java_client.CommandExecutionHelper;6import io.appium.java_client.ExecutesMethod;7import java.util.Map;8public interface HasDeviceDetails extends ExecutesMethod {9 /*10 Retrieve the display density of the Android device.11 */12 default Long getDisplayDensity() {13 return CommandExecutionHelper.execute(this, getDisplayDensityCommand());14 }15 /*16 Retrieve visibility and bounds information of the status and navigation bars.17 */18 default Map<String, String> getSystemBars() {19 return CommandExecutionHelper.execute(this, getSystemBarsCommand());20 }21 /**22 * Check if the keyboard is displayed.23 *24 * @return true if keyboard is displayed. False otherwise25 */26 default boolean isKeyboardShown() {27 return CommandExecutionHelper.execute(this, isKeyboardShownCommand());28 }29}...
SupportsNetworkStateManagement.java
Source:SupportsNetworkStateManagement.java
1package io.appium.java_client.android;2import static io.appium.java_client.android.AndroidMobileCommandHelper.toggleAirplaneCommand;3import static io.appium.java_client.android.AndroidMobileCommandHelper.toggleDataCommand;4import static io.appium.java_client.android.AndroidMobileCommandHelper.toggleWifiCommand;5import io.appium.java_client.CommandExecutionHelper;6import io.appium.java_client.ExecutesMethod;7public interface SupportsNetworkStateManagement extends ExecutesMethod {8 /**9 * Toggles Wifi on and off.10 */11 default void toggleWifi() {12 CommandExecutionHelper.execute(this, toggleWifiCommand());13 }14 /**15 * Toggle Airplane mode and this works on OS 6.0 and lesser16 * and does not work on OS 7.0 and greater17 */18 default void toggleAirplaneMode() {19 CommandExecutionHelper.execute(this, toggleAirplaneCommand());20 }21 /**22 * Toggle Mobile Data and this works on Emulator and rooted device.23 */24 default void toggleData() {25 CommandExecutionHelper.execute(this, toggleDataCommand());26 }27}...
CommandExecutionHelper
Using AI Code Generation
1import io.appium.java_client.android.AndroidDriver;2import io.appium.java_client.android.AndroidElement;3import io.appium.java_client.remote.AndroidMobileCapabilityType;4import io.appium.java_client.remote.MobileCapabilityType;5import org.openqa.selenium.remote.DesiredCapabilities;6import java.io.File;7import java.net.MalformedURLException;8import java.net.URL;9import java.util.concurrent.TimeUnit;10public class Appium {11 public static void main(String[] args) throws MalformedURLException {12 DesiredCapabilities cap = new DesiredCapabilities();13 cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Device");14 cap.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "com.android.calculator2");15 cap.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, "com.android.calculator2.Calculator");
CommandExecutionHelper
Using AI Code Generation
1import io.appium.java_client.AppiumDriver;2import io.appium.java_client.CommandExecutionHelper;3import io.appium.java_client.android.AndroidDriver;4import io.appium.java_client.android.AndroidKeyCode;5import io.appium.java_client.ios.IOSDriver;6import io.appium.java_client.ios.IOSElement;7import java.net.URL;8import java.util.List;9import java.util.concurrent.TimeUnit;10import org.openqa.selenium.By;11import org.openqa.selenium.WebElement;12import org.openqa.selenium.remote.DesiredCapabilities;13import org.openqa.selenium.remote.Response;14public class AppiumJavaTest {15 public static void main(String[] args) throws Exception {16 DesiredCapabilities capabilities = new DesiredCapabilities();17 capabilities.setCapability("deviceName", "emulator-5554");18 capabilities.setCapability("browserName", "Android");19 capabilities.setCapability("platformVersion", "6.0.1");20 capabilities.setCapability("platformName", "Android");21 capabilities.setCapability("appPackage", "com.android.calculator2");22 capabilities.setCapability("appActivity", "com.android.calculator2.Calculator");
CommandExecutionHelper
Using AI Code Generation
1import io.appium.java_client.CommandExecutionHelper;2import io.appium.java_client.android.AndroidDriver;3import org.openqa.selenium.WebElement;4import org.openqa.selenium.remote.DesiredCapabilities;5import java.net.URL;6public class AppiumTest {7 public static void main(String[] args) throws Exception {8 DesiredCapabilities capabilities = new DesiredCapabilities();9 capabilities.setCapability("deviceName", "My Phone");10 capabilities.setCapability("browserName", "Android");11 capabilities.setCapability("platformVersion", "4.4");12 capabilities.setCapability("platformName", "Android");13 capabilities.setCapability("appPackage", "com.android.calculator2");14 capabilities.setCapability("appActivity", "com.android.calculator2.Calculator");
CommandExecutionHelper
Using AI Code Generation
1public class CommandExecutionHelperTest {2 private static CommandExecutionHelper commandExecutionHelper;3 private static AppiumDriver driver;4 public static void setUp() throws MalformedURLException {5 DesiredCapabilities capabilities = new DesiredCapabilities();6 capabilities.setCapability("deviceName", "Android Emulator");7 capabilities.setCapability("platformName", "Android");8 capabilities.setCapability("platformVersion", "4.4");9 capabilities.setCapability("appPackage", "io.appium.android.apis");10 capabilities.setCapability("appActivity", ".ApiDemos");
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!