How to use MobileCommand class of io.appium.java_client package

Best io.appium code snippet using io.appium.java_client.MobileCommand

AppiumDriver_4.1.2.java

Source:AppiumDriver_4.1.2.java Github

copy

Full Screen

...14 * limitations under the License.15 */16package io.appium.java_client;17import static com.google.common.base.Preconditions.checkNotNull;18import static io.appium.java_client.MobileCommand.CLOSE_APP;19import static io.appium.java_client.MobileCommand.GET_DEVICE_TIME;20import static io.appium.java_client.MobileCommand.GET_SESSION;21import static io.appium.java_client.MobileCommand.GET_SETTINGS;22import static io.appium.java_client.MobileCommand.GET_STRINGS;23import static io.appium.java_client.MobileCommand.HIDE_KEYBOARD;24import static io.appium.java_client.MobileCommand.INSTALL_APP;25import static io.appium.java_client.MobileCommand.IS_APP_INSTALLED;26import static io.appium.java_client.MobileCommand.LAUNCH_APP;27import static io.appium.java_client.MobileCommand.PERFORM_MULTI_TOUCH;28import static io.appium.java_client.MobileCommand.PERFORM_TOUCH_ACTION;29import static io.appium.java_client.MobileCommand.PULL_FILE;30import static io.appium.java_client.MobileCommand.PULL_FOLDER;31import static io.appium.java_client.MobileCommand.REMOVE_APP;32import static io.appium.java_client.MobileCommand.RUN_APP_IN_BACKGROUND;33import static io.appium.java_client.MobileCommand.SET_SETTINGS;34import static io.appium.java_client.MobileCommand.prepareArguments;35import com.google.common.collect.ImmutableList;36import com.google.common.collect.ImmutableMap;37import com.google.gson.JsonObject;38import com.google.gson.JsonParser;39import io.appium.java_client.remote.AppiumCommandExecutor;40import io.appium.java_client.remote.MobileCapabilityType;41import io.appium.java_client.service.local.AppiumDriverLocalService;42import io.appium.java_client.service.local.AppiumServiceBuilder;43import org.openqa.selenium.By;44import org.openqa.selenium.Capabilities;45import org.openqa.selenium.Dimension;46import org.openqa.selenium.Point;47import org.openqa.selenium.ScreenOrientation;48import org.openqa.selenium.WebDriver;49import org.openqa.selenium.WebDriverException;50import org.openqa.selenium.WebElement;51import org.openqa.selenium.html5.Location;52import org.openqa.selenium.remote.DesiredCapabilities;53import org.openqa.selenium.remote.DriverCommand;54import org.openqa.selenium.remote.ErrorHandler;55import org.openqa.selenium.remote.ExecuteMethod;56import org.openqa.selenium.remote.HttpCommandExecutor;57import org.openqa.selenium.remote.RemoteWebDriver;58import org.openqa.selenium.remote.Response;59import org.openqa.selenium.remote.html5.RemoteLocationContext;60import org.openqa.selenium.remote.http.HttpClient;61import org.openqa.selenium.remote.internal.JsonToWebElementConverter;62import java.lang.reflect.Constructor;63import java.lang.reflect.InvocationTargetException;64import java.net.URL;65import java.util.LinkedHashSet;66import java.util.List;67import java.util.Map;68import java.util.Set;69import javax.xml.bind.DatatypeConverter;70/**71* @param <T> the required type of class which implement {@link org.openqa.selenium.WebElement}.72 * Instances of the defined type will be returned via findElement* and findElements*73 * Warning (!!!). Allowed types:74 * {@link org.openqa.selenium.WebElement}75 * {@link io.appium.java_client.TouchableElement}76 * {@link org.openqa.selenium.remote.RemoteWebElement}77 * {@link io.appium.java_client.MobileElement} and its subclasses that designed78 * specifically79 * for each target mobile OS (still Android and iOS)80*/81@SuppressWarnings("unchecked")82public abstract class AppiumDriver<T extends WebElement>83 extends DefaultGenericMobileDriver<T> {84 private static final ErrorHandler errorHandler = new ErrorHandler(new ErrorCodesMobile(), true);85 // frequently used command parameters86 private URL remoteAddress;87 private RemoteLocationContext locationContext;88 private ExecuteMethod executeMethod;89 /**90 * @param executor is an instance of {@link org.openqa.selenium.remote.HttpCommandExecutor}91 * or class that extends it. Default commands or another vendor-specific92 * commands may be specified there.93 * @param capabilities take a look94 * at {@link org.openqa.selenium.Capabilities}95 * @param converterClazz is an instance of a class that extends96 * {@link org.openqa.selenium.remote.internal.JsonToWebElementConverter}. It converts97 * JSON response to an instance of98 * {@link org.openqa.selenium.WebElement}99 */100 protected AppiumDriver(HttpCommandExecutor executor, Capabilities capabilities,101 Class<? extends JsonToWebElementConverter> converterClazz) {102 super(executor, capabilities);103 this.executeMethod = new AppiumExecutionMethod(this);104 locationContext = new RemoteLocationContext(executeMethod);105 super.setErrorHandler(errorHandler);106 this.remoteAddress = executor.getAddressOfRemoteServer();107 try {108 Constructor<? extends JsonToWebElementConverter> constructor =109 converterClazz.getConstructor(RemoteWebDriver.class);110 this.setElementConverter(constructor.newInstance(this));111 } catch (NoSuchMethodException | IllegalAccessException | InstantiationException112 | InvocationTargetException e) {113 throw new RuntimeException(e);114 }115 }116 public AppiumDriver(URL remoteAddress, Capabilities desiredCapabilities,117 Class<? extends JsonToWebElementConverter> converterClazz) {118 this(new AppiumCommandExecutor(MobileCommand.commandRepository, remoteAddress),119 desiredCapabilities, converterClazz);120 }121 public AppiumDriver(URL remoteAddress, HttpClient.Factory httpClientFactory,122 Capabilities desiredCapabilities,123 Class<? extends JsonToWebElementConverter> converterClazz) {124 this(new AppiumCommandExecutor(MobileCommand.commandRepository, remoteAddress,125 httpClientFactory), desiredCapabilities, converterClazz);126 }127 public AppiumDriver(AppiumDriverLocalService service, Capabilities desiredCapabilities,128 Class<? extends JsonToWebElementConverter> converterClazz) {129 this(new AppiumCommandExecutor(MobileCommand.commandRepository, service),130 desiredCapabilities, converterClazz);131 }132 public AppiumDriver(AppiumDriverLocalService service, HttpClient.Factory httpClientFactory,133 Capabilities desiredCapabilities,134 Class<? extends JsonToWebElementConverter> converterClazz) {135 this(new AppiumCommandExecutor(MobileCommand.commandRepository, service, httpClientFactory),136 desiredCapabilities, converterClazz);137 }138 public AppiumDriver(AppiumServiceBuilder builder, Capabilities desiredCapabilities,139 Class<? extends JsonToWebElementConverter> converterClazz) {140 this(builder.build(), desiredCapabilities, converterClazz);141 }142 public AppiumDriver(AppiumServiceBuilder builder, HttpClient.Factory httpClientFactory,143 Capabilities desiredCapabilities,144 Class<? extends JsonToWebElementConverter> converterClazz) {145 this(builder.build(), httpClientFactory, desiredCapabilities, converterClazz);146 }147 public AppiumDriver(HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities,148 Class<? extends JsonToWebElementConverter> converterClazz) {149 this(AppiumDriverLocalService.buildDefaultService(), httpClientFactory,150 desiredCapabilities, converterClazz);151 }152 public AppiumDriver(Capabilities desiredCapabilities,153 Class<? extends JsonToWebElementConverter> converterClazz) {154 this(AppiumDriverLocalService.buildDefaultService(), desiredCapabilities, converterClazz);155 }156 /**157 * @param originalCapabilities the given {@link Capabilities}.158 * @param newPlatform a {@link MobileCapabilityType#PLATFORM_NAME} value which has159 * to be set up160 * @return {@link Capabilities} with changed mobile platform value161 */162 protected static Capabilities substituteMobilePlatform(Capabilities originalCapabilities,163 String newPlatform) {164 DesiredCapabilities dc = new DesiredCapabilities(originalCapabilities);165 dc.setCapability(MobileCapabilityType.PLATFORM_NAME, newPlatform);166 return dc;167 }168 @Override public List<T> findElements(By by) {169 return super.findElements(by);170 }171 @Override public List<T> findElements(String by, String using) {172 return super.findElements(by, using);173 }174 @Override public List<T> findElementsById(String id) {175 return super.findElementsById(id);176 }177 public List<T> findElementsByLinkText(String using) {178 return super.findElementsByLinkText(using);179 }180 public List<T> findElementsByPartialLinkText(String using) {181 return super.findElementsByPartialLinkText(using);182 }183 public List<T> findElementsByTagName(String using) {184 return super.findElementsByTagName(using);185 }186 public List<T> findElementsByName(String using) {187 return super.findElementsByName(using);188 }189 public List<T> findElementsByClassName(String using) {190 return super.findElementsByClassName(using);191 }192 public List<T> findElementsByCssSelector(String using) {193 return super.findElementsByCssSelector(using);194 }195 public List<T> findElementsByXPath(String using) {196 return super.findElementsByXPath(using);197 }198 @Override public List<T> findElementsByAccessibilityId(String using) {199 return super.findElementsByAccessibilityId(using);200 }201 @Override protected Response execute(String command) {202 return super.execute(command, ImmutableMap.<String, Object>of());203 }204 @Override public ExecuteMethod getExecuteMethod() {205 return executeMethod;206 }207 /**208 * @see InteractsWithApps#resetApp().209 */210 @Override public void resetApp() {211 execute(MobileCommand.RESET);212 }213 /**214 * @see InteractsWithApps#isAppInstalled(String).215 */216 @Override public boolean isAppInstalled(String bundleId) {217 Response response = execute(IS_APP_INSTALLED, ImmutableMap.of("bundleId", bundleId));218 return Boolean.parseBoolean(response.getValue().toString());219 }220 /**221 * @see InteractsWithApps#installApp(String).222 */223 @Override public void installApp(String appPath) {224 execute(INSTALL_APP, ImmutableMap.of("appPath", appPath));225 }...

Full Screen

Full Screen

AppiumDriver.java

Source:AppiumDriver.java Github

copy

Full Screen

...14 * limitations under the License.15 */16package io.appium.java_client;17import static com.google.common.base.Preconditions.checkNotNull;18import static io.appium.java_client.MobileCommand.CLOSE_APP;19import static io.appium.java_client.MobileCommand.GET_DEVICE_TIME;20import static io.appium.java_client.MobileCommand.GET_SESSION;21import static io.appium.java_client.MobileCommand.GET_SETTINGS;22import static io.appium.java_client.MobileCommand.GET_STRINGS;23import static io.appium.java_client.MobileCommand.HIDE_KEYBOARD;24import static io.appium.java_client.MobileCommand.INSTALL_APP;25import static io.appium.java_client.MobileCommand.IS_APP_INSTALLED;26import static io.appium.java_client.MobileCommand.LAUNCH_APP;27import static io.appium.java_client.MobileCommand.PERFORM_MULTI_TOUCH;28import static io.appium.java_client.MobileCommand.PERFORM_TOUCH_ACTION;29import static io.appium.java_client.MobileCommand.PULL_FILE;30import static io.appium.java_client.MobileCommand.PULL_FOLDER;31import static io.appium.java_client.MobileCommand.REMOVE_APP;32import static io.appium.java_client.MobileCommand.RUN_APP_IN_BACKGROUND;33import static io.appium.java_client.MobileCommand.SET_SETTINGS;34import static io.appium.java_client.MobileCommand.prepareArguments;35import com.google.common.collect.ImmutableList;36import com.google.common.collect.ImmutableMap;37import com.google.gson.JsonObject;38import com.google.gson.JsonParser;39import io.appium.java_client.remote.AppiumCommandExecutor;40import io.appium.java_client.remote.MobileCapabilityType;41import io.appium.java_client.service.local.AppiumDriverLocalService;42import io.appium.java_client.service.local.AppiumServiceBuilder;43import org.openqa.selenium.By;44import org.openqa.selenium.Capabilities;45import org.openqa.selenium.Dimension;46import org.openqa.selenium.Point;47import org.openqa.selenium.ScreenOrientation;48import org.openqa.selenium.WebDriver;49import org.openqa.selenium.WebDriverException;50import org.openqa.selenium.WebElement;51import org.openqa.selenium.html5.Location;52import org.openqa.selenium.remote.DesiredCapabilities;53import org.openqa.selenium.remote.DriverCommand;54import org.openqa.selenium.remote.ErrorHandler;55import org.openqa.selenium.remote.ExecuteMethod;56import org.openqa.selenium.remote.HttpCommandExecutor;57import org.openqa.selenium.remote.RemoteWebDriver;58import org.openqa.selenium.remote.Response;59import org.openqa.selenium.remote.html5.RemoteLocationContext;60import org.openqa.selenium.remote.http.HttpClient;61import org.openqa.selenium.remote.internal.JsonToWebElementConverter;62import java.lang.reflect.Constructor;63import java.lang.reflect.InvocationTargetException;64import java.net.URL;65import java.util.LinkedHashSet;66import java.util.List;67import java.util.Map;68import java.util.Set;69import javax.xml.bind.DatatypeConverter;70/**71* @param <T> the required type of class which implement {@link org.openqa.selenium.WebElement}.72 * Instances of the defined type will be returned via findElement* and findElements*73 * Warning (!!!). Allowed types:74 * {@link org.openqa.selenium.WebElement}75 * {@link io.appium.java_client.TouchableElement}76 * {@link org.openqa.selenium.remote.RemoteWebElement}77 * {@link io.appium.java_client.MobileElement} and its subclasses that designed78 * specifically79 * for each target mobile OS (still Android and iOS)80*/81@SuppressWarnings("unchecked")82public abstract class AppiumDriver<T extends WebElement>83 extends DefaultGenericMobileDriver<T> {84 private static final ErrorHandler errorHandler = new ErrorHandler(new ErrorCodesMobile(), true);85 // frequently used command parameters86 private URL remoteAddress;87 private RemoteLocationContext locationContext;88 private ExecuteMethod executeMethod;89 /**90 * @param executor is an instance of {@link org.openqa.selenium.remote.HttpCommandExecutor}91 * or class that extends it. Default commands or another vendor-specific92 * commands may be specified there.93 * @param capabilities take a look94 * at {@link org.openqa.selenium.Capabilities}95 * @param converterClazz is an instance of a class that extends96 * {@link org.openqa.selenium.remote.internal.JsonToWebElementConverter}. It converts97 * JSON response to an instance of98 * {@link org.openqa.selenium.WebElement}99 */100 protected AppiumDriver(HttpCommandExecutor executor, Capabilities capabilities,101 Class<? extends JsonToWebElementConverter> converterClazz) {102 super(executor, capabilities);103 this.executeMethod = new AppiumExecutionMethod(this);104 locationContext = new RemoteLocationContext(executeMethod);105 super.setErrorHandler(errorHandler);106 this.remoteAddress = executor.getAddressOfRemoteServer();107 try {108 Constructor<? extends JsonToWebElementConverter> constructor =109 converterClazz.getConstructor(RemoteWebDriver.class);110 this.setElementConverter(constructor.newInstance(this));111 } catch (NoSuchMethodException | IllegalAccessException | InstantiationException112 | InvocationTargetException e) {113 throw new RuntimeException(e);114 }115 }116 public AppiumDriver(URL remoteAddress, Capabilities desiredCapabilities,117 Class<? extends JsonToWebElementConverter> converterClazz) {118 this(new AppiumCommandExecutor(MobileCommand.commandRepository, remoteAddress),119 desiredCapabilities, converterClazz);120 }121 public AppiumDriver(URL remoteAddress, HttpClient.Factory httpClientFactory,122 Capabilities desiredCapabilities,123 Class<? extends JsonToWebElementConverter> converterClazz) {124 this(new AppiumCommandExecutor(MobileCommand.commandRepository, remoteAddress,125 httpClientFactory), desiredCapabilities, converterClazz);126 }127 public AppiumDriver(AppiumDriverLocalService service, Capabilities desiredCapabilities,128 Class<? extends JsonToWebElementConverter> converterClazz) {129 this(new AppiumCommandExecutor(MobileCommand.commandRepository, service),130 desiredCapabilities, converterClazz);131 }132 public AppiumDriver(AppiumDriverLocalService service, HttpClient.Factory httpClientFactory,133 Capabilities desiredCapabilities,134 Class<? extends JsonToWebElementConverter> converterClazz) {135 this(new AppiumCommandExecutor(MobileCommand.commandRepository, service, httpClientFactory),136 desiredCapabilities, converterClazz);137 }138 public AppiumDriver(AppiumServiceBuilder builder, Capabilities desiredCapabilities,139 Class<? extends JsonToWebElementConverter> converterClazz) {140 this(builder.build(), desiredCapabilities, converterClazz);141 }142 public AppiumDriver(AppiumServiceBuilder builder, HttpClient.Factory httpClientFactory,143 Capabilities desiredCapabilities,144 Class<? extends JsonToWebElementConverter> converterClazz) {145 this(builder.build(), httpClientFactory, desiredCapabilities, converterClazz);146 }147 public AppiumDriver(HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities,148 Class<? extends JsonToWebElementConverter> converterClazz) {149 this(AppiumDriverLocalService.buildDefaultService(), httpClientFactory,150 desiredCapabilities, converterClazz);151 }152 public AppiumDriver(Capabilities desiredCapabilities,153 Class<? extends JsonToWebElementConverter> converterClazz) {154 this(AppiumDriverLocalService.buildDefaultService(), desiredCapabilities, converterClazz);155 }156 /**157 * @param originalCapabilities the given {@link Capabilities}.158 * @param newPlatform a {@link MobileCapabilityType#PLATFORM_NAME} value which has159 * to be set up160 * @return {@link Capabilities} with changed mobile platform value161 */162 protected static Capabilities substituteMobilePlatform(Capabilities originalCapabilities,163 String newPlatform) {164 DesiredCapabilities dc = new DesiredCapabilities(originalCapabilities);165 dc.setCapability(MobileCapabilityType.PLATFORM_NAME, newPlatform);166 return dc;167 }168 @Override public List<T> findElements(By by) {169 return super.findElements(by);170 }171 @Override public List<T> findElements(String by, String using) {172 return super.findElements(by, using);173 }174 @Override public List<T> findElementsById(String id) {175 return super.findElementsById(id);176 }177 public List<T> findElementsByLinkText(String using) {178 return super.findElementsByLinkText(using);179 }180 public List<T> findElementsByPartialLinkText(String using) {181 return super.findElementsByPartialLinkText(using);182 }183 public List<T> findElementsByTagName(String using) {184 return super.findElementsByTagName(using);185 }186 public List<T> findElementsByName(String using) {187 return super.findElementsByName(using);188 }189 public List<T> findElementsByClassName(String using) {190 return super.findElementsByClassName(using);191 }192 public List<T> findElementsByCssSelector(String using) {193 return super.findElementsByCssSelector(using);194 }195 public List<T> findElementsByXPath(String using) {196 return super.findElementsByXPath(using);197 }198 @Override public List<T> findElementsByAccessibilityId(String using) {199 return super.findElementsByAccessibilityId(using);200 }201 @Override protected Response execute(String command) {202 return super.execute(command, ImmutableMap.<String, Object>of());203 }204 @Override public ExecuteMethod getExecuteMethod() {205 return executeMethod;206 }207 /**208 * @see InteractsWithApps#resetApp().209 */210 @Override public void resetApp() {211 execute(MobileCommand.RESET);212 }213 /**214 * @see InteractsWithApps#isAppInstalled(String).215 */216 @Override public boolean isAppInstalled(String bundleId) {217 Response response = execute(IS_APP_INSTALLED, ImmutableMap.of("bundleId", bundleId));218 return Boolean.parseBoolean(response.getValue().toString());219 }220 /**221 * @see InteractsWithApps#installApp(String).222 */223 @Override public void installApp(String appPath) {224 execute(INSTALL_APP, ImmutableMap.of("appPath", appPath));225 }...

Full Screen

Full Screen

MobileRecordingListener.java

Source:MobileRecordingListener.java Github

copy

Full Screen

...21import org.testng.ITestResult;22import org.testng.Reporter;23import com.qaprosoft.zafira.client.ZafiraSingleton;24import com.qaprosoft.zafira.models.dto.TestArtifactType;25import io.appium.java_client.MobileCommand;26import io.appium.java_client.screenrecording.BaseStartScreenRecordingOptions;27import io.appium.java_client.screenrecording.BaseStopScreenRecordingOptions;28/**29 * ScreenRecordingListener - starts/stops video recording for Android and IOS drivers.30 * 31 * @author akhursevich32 */33@SuppressWarnings({ "rawtypes"})34public class MobileRecordingListener<O1 extends BaseStartScreenRecordingOptions, O2 extends BaseStopScreenRecordingOptions> implements IDriverCommandListener {35 protected static final Logger LOGGER = Logger.getLogger(MobileRecordingListener.class);36 37 private CommandExecutor commandExecutor;38 private O1 startRecordingOpt;39 private O2 stopRecordingOpt;40 41 private boolean recording = false;42 43 private TestArtifactType videoArtifact;44 45 public MobileRecordingListener(CommandExecutor commandExecutor, O1 startRecordingOpt, O2 stopRecordingOpt, TestArtifactType artifact) {46 this.commandExecutor = commandExecutor;47 this.startRecordingOpt = startRecordingOpt;48 this.stopRecordingOpt = stopRecordingOpt;49 this.videoArtifact = artifact;50 }51 @Override52 public void beforeEvent(Command command) {53 if (recording) {54 onBeforeEvent();55 56 if (DriverCommand.QUIT.equals(command.getName())) {57 try {58 commandExecutor.execute(new Command(command.getSessionId(), 59 MobileCommand.STOP_RECORDING_SCREEN, 60 MobileCommand.stopRecordingScreenCommand((BaseStopScreenRecordingOptions) stopRecordingOpt).getValue()));61 if (ZafiraSingleton.INSTANCE.isRunning()) {62 ZafiraSingleton.INSTANCE.getClient().addTestArtifact(videoArtifact);63 }64 } catch (Exception e) {65 LOGGER.error("Unable to stop screen recording: " + e.getMessage(), e);66 }67 }68 }69 }70 @Override71 public void afterEvent(Command command) {72 if (!recording && command.getSessionId() != null) {73 try {74 recording = true;75 commandExecutor.execute(new Command(command.getSessionId(), 76 MobileCommand.START_RECORDING_SCREEN, 77 MobileCommand.startRecordingScreenCommand((BaseStartScreenRecordingOptions) startRecordingOpt).getValue()));78 } catch (Exception e) {79 LOGGER.error("Unable to start screen recording: " + e.getMessage(), e);80 }81 }82 }83 84 private void onBeforeEvent() {85 // 4a. if "tzid" not exist inside videoArtifact and exists in Reporter -> register new videoArtifact in Zafira.86 // 4b. if "tzid" already exists in current artifact but in Reporter there is another value. Then this is use case for class/suite mode when we share the same87 // driver across different tests88 89 ITestResult res = Reporter.getCurrentTestResult();90 if (res != null && res.getAttribute("ztid") != null) {91 Long ztid = (Long) res.getAttribute("ztid");...

Full Screen

Full Screen

InteractsWithApps.java

Source:InteractsWithApps.java Github

copy

Full Screen

...13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16package io.appium.java_client;17import static io.appium.java_client.MobileCommand.CLOSE_APP;18import static io.appium.java_client.MobileCommand.INSTALL_APP;19import static io.appium.java_client.MobileCommand.IS_APP_INSTALLED;20import static io.appium.java_client.MobileCommand.LAUNCH_APP;21import static io.appium.java_client.MobileCommand.REMOVE_APP;22import static io.appium.java_client.MobileCommand.RESET;23import static io.appium.java_client.MobileCommand.RUN_APP_IN_BACKGROUND;24import static io.appium.java_client.MobileCommand.prepareArguments;25import com.google.common.collect.ImmutableMap;26import java.time.Duration;27import java.util.AbstractMap;28public interface InteractsWithApps extends ExecutesMethod {29 /**30 * Launch the app which was provided in the capabilities at session creation.31 */32 default void launchApp() {33 execute(LAUNCH_APP);34 }35 /**36 * Install an app on the mobile device.37 *38 * @param appPath path to app to install....

Full Screen

Full Screen

SampleAppiumDriverTest.java

Source:SampleAppiumDriverTest.java Github

copy

Full Screen

1import io.appium.java_client.MobileBy;2import io.appium.java_client.MobileCommand;3import io.appium.java_client.MobileElement;4import io.appium.java_client.TouchAction;5import io.appium.java_client.ios.IOSDriver;6import io.appium.java_client.remote.AppiumCommandExecutor;7import io.appium.java_client.touch.TapOptions;8import io.appium.java_client.touch.offset.ElementOption;9import org.junit.Test;10import org.openqa.selenium.MutableCapabilities;11import org.openqa.selenium.WebElement;12import java.net.MalformedURLException;13import java.net.URL;14public class SampleAppiumDriverTest {15 public static final String SAUCE_USERNAME = System.getenv("SAUCE_USERNAME");16 public static final String SAUCE_ACCESS_KEY = System.getenv("SAUCE_ACCESS_KEY");17 public static final String SAUCE_URL = String.format("https://%s:%s@ondemand.us-west-1.saucelabs.com/wd/hub",SAUCE_USERNAME,SAUCE_ACCESS_KEY);18 @Test19 public void myTest() throws MalformedURLException {20// Enable these to proxy all traffic21// System.setProperty("http.proxyHost", "localhost");22// System.setProperty("https.proxyHost", "localhost");23// System.setProperty("http.proxyPort", "8889");24// System.setProperty("https.proxyPort", "8889");25 try {26 HTTPFactory factory = new HTTPFactory();27 AppiumCommandExecutor executor = new AppiumCommandExecutor(MobileCommand.commandRepository, new URL(SAUCE_URL), factory);28 MutableCapabilities caps = new MutableCapabilities();29 caps.setCapability("platformName", "iOS");30 //TODO: Change to your Sauce Storage ID31 caps.setCapability("appium:app", "storage:81438268-f41e-429c-bcb4-c8f0047c13e7");32 caps.setCapability("appium:deviceName", "iPhone 13 Simulator");33 caps.setCapability("appium:platformVersion", "15.0");34 MutableCapabilities sauceOptions = new MutableCapabilities();35 sauceOptions.setCapability("appiumVersion", "1.22.0");36 caps.setCapability("sauce:options", sauceOptions);37 IOSDriver driver = new IOSDriver<MobileElement>(executor, caps);38 WebElement user = driver.findElement(MobileBy.AccessibilityId("test-Username"));39 user.sendKeys("test-user");40 MobileElement loginBtn = (MobileElement) driver.findElement(MobileBy.AccessibilityId("test-LOGIN"));41 TapOptions tapOptions = new TapOptions();...

Full Screen

Full Screen

TapOnelement.java

Source:TapOnelement.java Github

copy

Full Screen

...7import org.openqa.selenium.WebElement;8import org.openqa.selenium.remote.DesiredCapabilities;9import org.openqa.selenium.remote.internal.ApacheHttpClient;10import org.openqa.selenium.remote.internal.HttpClientFactory;11import io.appium.java_client.MobileCommand;12import io.appium.java_client.MobileElement;13import io.appium.java_client.android.AndroidDriver;14import io.appium.java_client.remote.AppiumCommandExecutor;15public class TapOnelement {16 public static AndroidDriver driver;17 public static void main(String[] args) throws MalformedURLException 18 {19 20 DesiredCapabilities cap = new DesiredCapabilities();21 cap.setCapability("deviceName", "Redmi");22 cap.setCapability("automationName", "Appium");23 cap.setCapability("platformName", "Android");24 cap.setCapability("platformVersion", "7.0");25 cap.setCapability("UDID", "d6c768cf9804");26 cap.setCapability("appPackage", "io.appium.android.apis");27 cap.setCapability("appActivity", "ApiDemos");28 int con_timeout = 1200000;29 int soc_timeout = 90000;30 ApacheHttpClient.Factory clientFactory = new ApacheHttpClient.Factory(new31 HttpClientFactory(con_timeout, soc_timeout));32 AppiumCommandExecutor executor = new AppiumCommandExecutor(MobileCommand.commandRepository, new URL("http://localhost:4723/wd/hub"), clientFactory);33 34 URL url = new URL("http://localhost:4723/wd/hub");35 driver = new AndroidDriver(url,cap);36 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);37 38 MobileElement content = (MobileElement) driver.findElement(By.xpath("//android.widget.TextView[@content-desc=\"Content\"]"));39 40 taponElement(content);41 42 tapbyCoordinates(277, 1037);43 44 //AppiumCommandExecutor executor = new AppiumCommandExecutor(MobileCommand.commandRepository, new URL("http://localhost:4723/wd/hub"));45 }46 47 public static void taponElement(WebElement element) {48 driver.tap(1,element,500);49 }50 51 public static void tapbyCoordinates(int x,int y) {52 driver.tap(1, x, y, 500);53 }54 55 56 57}...

Full Screen

Full Screen

IOSElement.java

Source:IOSElement.java Github

copy

Full Screen

1package io.appium.java_client.ios;2import io.appium.java_client.FindsByIosUIAutomation;3import io.appium.java_client.MobileCommand;4import io.appium.java_client.MobileElement;5import io.appium.java_client.ScrollsTo;6import org.openqa.selenium.WebElement;7import com.google.common.collect.ImmutableMap;8import java.util.List;9public class IOSElement extends MobileElement implements FindsByIosUIAutomation, ScrollsTo {10 11 @Override12 public IOSElement findElementByIosUIAutomation(String using) {13 return (IOSElement) findElement("-ios uiautomation", using);14 }15 @Override16 public List<WebElement> findElementsByIosUIAutomation(String using) {17 return findElements("-ios uiautomation", using);18 }19 /**20 * Scroll to the element whose 'text' attribute contains the input text.21 * Scrolling happens within this element22 * @param text input text contained in text attribute23 */24 @Override25 public MobileElement scrollTo(String text) {26 return (MobileElement) findElementByIosUIAutomation(".scrollToElementWithPredicate(\"name CONTAINS '" + text + "'\")");27 }28 /**29 * Scroll to the element whose 'text' attribute matches the input text.30 * Scrolling happens within this element31 * @param text input text contained in text attribute32 */33 @Override34 public MobileElement scrollToExact(String text) {35 return (MobileElement) findElementByIosUIAutomation(".scrollToElementWithName(\"" + text + "\")");36 }37 @SuppressWarnings({ "rawtypes", "unchecked" })38 public void setValue(String value) { 39 ImmutableMap.Builder builder = ImmutableMap.builder();40 builder.put("id", id).put("value", value);41 execute(MobileCommand.SET_VALUE, builder.build());42 }43}...

Full Screen

Full Screen

MonkeyHomeKeyEvent.java

Source:MonkeyHomeKeyEvent.java Github

copy

Full Screen

1package com.ett.monkey;2import io.appium.java_client.MobileCommand;3import io.appium.java_client.ios.IOSDriver;4import java.io.IOException;5import com.ett.monkey.util.Shell;6/**7 * Created by mff on 17/09/12.8 */9public class MonkeyHomeKeyEvent extends MonkeyEvent{10 private String UDID, BUNDLEID; 11 private IOSDriver driver;12 public MonkeyHomeKeyEvent(IOSDriver driver, String udid, String bundleid) {13 super(MonkeyEvent.EVENT_TYPE_HOMEKEY);14 this.driver = driver;15 this.UDID = udid;16 this.BUNDLEID = bundleid;17 }18 public int injectEvent() throws Exception {19 System.out.println("sending HOMEKEY Event.");20 driver.execute(MobileCommand.RUN_APP_IN_BACKGROUND);21 new Thread(new Runnable() {22 public void run() {23 try {24 Shell.exec("pkill idevicedebug");25 System.out.println("idevicedebug stop");26 } catch (IOException e) {27 e.printStackTrace();28 } catch (InterruptedException e) {29 e.printStackTrace();30 }31 }32 }).start();33 System.out.println("launch App:" + BUNDLEID);34 try {...

Full Screen

Full Screen

MobileCommand

Using AI Code Generation

copy

Full Screen

1package appium;2import java.net.URL;3import org.openqa.selenium.remote.DesiredCapabilities;4import io.appium.java_client.MobileCommand;5import io.appium.java_client.MobileElement;6import io.appium.java_client.android.AndroidDriver;7public class Appium {8 public static void main(String[] args) throws Exception {9 DesiredCapabilities caps = new DesiredCapabilities();10 caps.setCapability("deviceName", "Pixel_2_API_29");11 caps.setCapability("platformName", "Android");12 caps.setCapability("platformVersion", "10.0");13 caps.setCapability("noReset", true);14 caps.setCapability("chromedriverExecutable", "C:\\Users\\User\\Downloads\\chromedriver_win32\\chromedriver.exe");15 caps.setCapability("appPackage", "com.android.chrome");16 caps.setCapability("appActivity", "com.google.android.apps.chrome.Main");

Full Screen

Full Screen

MobileCommand

Using AI Code Generation

copy

Full Screen

1MobileCommand command = new MobileCommand("getGeoLocation");2AndroidMobileCommand command = new AndroidMobileCommand("getGeoLocation");3IOSMobileCommand command = new IOSMobileCommand("getGeoLocation");4MobileCommand command = new MobileCommand("setGeoLocation");5AndroidMobileCommand command = new AndroidMobileCommand("setGeoLocation");6IOSMobileCommand command = new IOSMobileCommand("setGeoLocation");7MobileCommand command = new MobileCommand("getNetworkConnection");8AndroidMobileCommand command = new AndroidMobileCommand("getNetworkConnection");9IOSMobileCommand command = new IOSMobileCommand("getNetworkConnection");10MobileCommand command = new MobileCommand("setNetworkConnection");11AndroidMobileCommand command = new AndroidMobileCommand("setNetworkConnection");12IOSMobileCommand command = new IOSMobileCommand("setNetworkConnection");13MobileCommand command = new MobileCommand("getAvailableImeEngines");14AndroidMobileCommand command = new AndroidMobileCommand("getAvailableImeEngines");15IOSMobileCommand command = new IOSMobileCommand("getAvailableImeEngines");16MobileCommand command = new MobileCommand("isImeActivated");

Full Screen

Full Screen

MobileCommand

Using AI Code Generation

copy

Full Screen

1import io.appium.java_client.MobileCommand;2import io.appium.java_client.android.AndroidDriver;3import java.net.URL;4import org.openqa.selenium.remote.DesiredCapabilities;5public class Appium {6public static void main(String[] args) throws Exception {7DesiredCapabilities capabilities = new DesiredCapabilities();8capabilities.setCapability("deviceName", "emulator-5554");9capabilities.setCapability("browserName", "Chrome");10capabilities.setCapability("platformVersion", "7.1.1");11capabilities.setCapability("platformName", "Android");12capabilities.setCapability("appPackage", "com.android.chrome");13capabilities.setCapability("appActivity", "com.google.android.apps.chrome.Main");

Full Screen

Full Screen

MobileCommand

Using AI Code Generation

copy

Full Screen

1MobileCommand command = new MobileCommand("findElement");2command.addParameter("using", "xpath");3command.addParameter("sessionId", "7b3b2c9c-3b6d-4e11-8a8a-6d1e6d0c6e52");4System.out.println(command.execute(driver, driver.getSessionId()));5MobileCommand command = new MobileCommand("findElement");6command.addParameter("using", "xpath");7command.addParameter("sessionId", "7b3b2c9c-3b6d-4e11-8a8a-6d1e6d0c6e52");8System.out.println(command.execute(driver, driver.getSessionId()));9MobileCommand command = new MobileCommand("findElement");10command.addParameter("using", "xpath");11command.addParameter("sessionId", "7b3b2c9c-3b6d-4e11-8a8a-6d1e6d0c6e52");12System.out.println(command.execute(driver, driver.getSessionId()));13MobileCommand command = new MobileCommand("findElement");14command.addParameter("using", "xpath");15command.addParameter("sessionId", "7b3b2c9c-3b6d-4e11-8a8a-6d1e6d0c6e52");16System.out.println(command.execute(driver, driver.getSessionId()));17MobileCommand command = new MobileCommand("findElement");18command.addParameter("using", "

Full Screen

Full Screen

MobileCommand

Using AI Code Generation

copy

Full Screen

1import io.appium.java_client.MobileCommand;2import io.appium.java_client.android.AndroidDriver;3import io.appium.java_client.android.AndroidElement;4import io.appium.java_client.remote.MobileCapabilityType;5import java.net.MalformedURLException;6import java.net.URL;7import org.openqa.selenium.remote.DesiredCapabilities;8public class AppiumTest {9public static void main(String[] args) throws MalformedURLException, InterruptedException {10DesiredCapabilities caps = new DesiredCapabilities();11caps.setCapability("deviceName", "Galaxy S6");12caps.setCapability("platformName", "Android");13caps.setCapability("platformVersion", "7.0");14caps.setCapability("appPackage", "com.android.calculator2");15caps.setCapability("appActivity", "com.android.calculator2.Calculator");

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful