Best io.appium code snippet using io.appium.java_client.remote.AppiumCommandExecutor
AppiumDriver.java
Source:AppiumDriver.java
...18import static io.appium.java_client.remote.MobileCapabilityType.AUTOMATION_NAME;19import static io.appium.java_client.remote.MobileCapabilityType.PLATFORM_NAME;20import static org.apache.commons.lang3.StringUtils.isBlank;21import io.appium.java_client.internal.CapabilityHelpers;22import io.appium.java_client.remote.AppiumCommandExecutor;23import io.appium.java_client.remote.AppiumNewSessionCommandPayload;24import io.appium.java_client.remote.MobileCapabilityType;25import io.appium.java_client.remote.options.BaseOptions;26import io.appium.java_client.service.local.AppiumDriverLocalService;27import io.appium.java_client.service.local.AppiumServiceBuilder;28import org.openqa.selenium.Capabilities;29import org.openqa.selenium.ImmutableCapabilities;30import org.openqa.selenium.MutableCapabilities;31import org.openqa.selenium.SessionNotCreatedException;32import org.openqa.selenium.WebDriverException;33import org.openqa.selenium.remote.CapabilityType;34import org.openqa.selenium.remote.DriverCommand;35import org.openqa.selenium.remote.ErrorHandler;36import org.openqa.selenium.remote.ExecuteMethod;37import org.openqa.selenium.remote.HttpCommandExecutor;38import org.openqa.selenium.remote.RemoteWebDriver;39import org.openqa.selenium.remote.Response;40import org.openqa.selenium.remote.html5.RemoteLocationContext;41import org.openqa.selenium.remote.http.HttpClient;42import org.openqa.selenium.remote.http.HttpMethod;43import java.lang.reflect.Field;44import java.net.URL;45import java.util.Arrays;46import java.util.Collections;47import java.util.Map;48/**49 * Default Appium driver implementation.50 */51public class AppiumDriver extends RemoteWebDriver implements52 ExecutesMethod,53 ComparesImages,54 ExecutesDriverScript,55 LogsEvents,56 HasBrowserCheck,57 HasSettings {58 private static final ErrorHandler errorHandler = new ErrorHandler(new ErrorCodesMobile(), true);59 // frequently used command parameters60 private final URL remoteAddress;61 protected final RemoteLocationContext locationContext;62 private final ExecuteMethod executeMethod;63 /**64 * Creates a new instance based on command {@code executor} and {@code capabilities}.65 *66 * @param executor is an instance of {@link HttpCommandExecutor}67 * or class that extends it. Default commands or another vendor-specific68 * commands may be specified there.69 * @param capabilities take a look at {@link Capabilities}70 */71 public AppiumDriver(HttpCommandExecutor executor, Capabilities capabilities) {72 super(executor, capabilities);73 this.executeMethod = new AppiumExecutionMethod(this);74 locationContext = new RemoteLocationContext(executeMethod);75 super.setErrorHandler(errorHandler);76 this.remoteAddress = executor.getAddressOfRemoteServer();77 }78 public AppiumDriver(URL remoteAddress, Capabilities capabilities) {79 this(new AppiumCommandExecutor(MobileCommand.commandRepository, remoteAddress),80 capabilities);81 }82 public AppiumDriver(URL remoteAddress, HttpClient.Factory httpClientFactory,83 Capabilities capabilities) {84 this(new AppiumCommandExecutor(MobileCommand.commandRepository, remoteAddress,85 httpClientFactory), capabilities);86 }87 public AppiumDriver(AppiumDriverLocalService service, Capabilities capabilities) {88 this(new AppiumCommandExecutor(MobileCommand.commandRepository, service),89 capabilities);90 }91 public AppiumDriver(AppiumDriverLocalService service, HttpClient.Factory httpClientFactory,92 Capabilities capabilities) {93 this(new AppiumCommandExecutor(MobileCommand.commandRepository, service, httpClientFactory),94 capabilities);95 }96 public AppiumDriver(AppiumServiceBuilder builder, Capabilities capabilities) {97 this(builder.build(), capabilities);98 }99 public AppiumDriver(AppiumServiceBuilder builder, HttpClient.Factory httpClientFactory,100 Capabilities capabilities) {101 this(builder.build(), httpClientFactory, capabilities);102 }103 public AppiumDriver(HttpClient.Factory httpClientFactory, Capabilities capabilities) {104 this(AppiumDriverLocalService.buildDefaultService(), httpClientFactory,105 capabilities);106 }107 public AppiumDriver(Capabilities capabilities) {108 this(AppiumDriverLocalService.buildDefaultService(), capabilities);109 }110 /**111 * Changes platform name if it is not set and returns merged capabilities.112 *113 * @param originalCapabilities the given {@link Capabilities}.114 * @param defaultName a {@link MobileCapabilityType#PLATFORM_NAME} value which has115 * to be set up116 * @return {@link Capabilities} with changed platform name value or the original capabilities117 */118 protected static Capabilities ensurePlatformName(119 Capabilities originalCapabilities, String defaultName) {120 String currentName = (String) originalCapabilities.getCapability(PLATFORM_NAME);121 return isBlank(currentName)122 ? originalCapabilities.merge(new ImmutableCapabilities(PLATFORM_NAME, defaultName))123 : originalCapabilities;124 }125 /**126 * Changes automation name if it is not set and returns merged capabilities.127 *128 * @param originalCapabilities the given {@link Capabilities}.129 * @param defaultName a {@link MobileCapabilityType#AUTOMATION_NAME} value which has130 * to be set up131 * @return {@link Capabilities} with changed mobile automation name value or the original capabilities132 */133 protected static Capabilities ensureAutomationName(134 Capabilities originalCapabilities, String defaultName) {135 String currentAutomationName = CapabilityHelpers.getCapability(136 originalCapabilities, AUTOMATION_NAME, String.class);137 if (isBlank(currentAutomationName)) {138 String capabilityName = originalCapabilities.getCapabilityNames()139 .contains(AUTOMATION_NAME) ? AUTOMATION_NAME : APPIUM_PREFIX + AUTOMATION_NAME;140 return originalCapabilities.merge(new ImmutableCapabilities(capabilityName, defaultName));141 }142 return originalCapabilities;143 }144 /**145 * Changes platform and automation names if they are not set146 * and returns merged capabilities.147 *148 * @param originalCapabilities the given {@link Capabilities}.149 * @param defaultPlatformName a {@link MobileCapabilityType#PLATFORM_NAME} value which has150 * to be set up151 * @param defaultAutomationName The default automation name to set up for this class152 * @return {@link Capabilities} with changed platform/automation name value or the original capabilities153 */154 protected static Capabilities ensurePlatformAndAutomationNames(155 Capabilities originalCapabilities, String defaultPlatformName, String defaultAutomationName) {156 Capabilities capsWithPlatformFixed = ensurePlatformName(originalCapabilities, defaultPlatformName);157 return ensureAutomationName(capsWithPlatformFixed, defaultAutomationName);158 }159 @Override160 public ExecuteMethod getExecuteMethod() {161 return executeMethod;162 }163 /**164 * This method is used to get build version status of running Appium server.165 *166 * @return map containing version details167 */168 public Map<String, Object> getStatus() {169 //noinspection unchecked170 return (Map<String, Object>) execute(DriverCommand.STATUS).getValue();171 }172 /**173 * This method is used to add custom appium commands in Appium 2.0.174 *175 * @param httpMethod the available {@link HttpMethod}.176 * @param url The url to URL template as https://www.w3.org/TR/webdriver/#endpoints.177 * @param methodName The name of custom appium command.178 */179 public void addCommand(HttpMethod httpMethod, String url, String methodName) {180 switch (httpMethod) {181 case GET:182 MobileCommand.commandRepository.put(methodName, MobileCommand.getC(url));183 break;184 case POST:185 MobileCommand.commandRepository.put(methodName, MobileCommand.postC(url));186 break;187 case DELETE:188 MobileCommand.commandRepository.put(methodName, MobileCommand.deleteC(url));189 break;190 default:191 throw new WebDriverException(String.format("Unsupported HTTP Method: %s. Only %s methods are supported",192 httpMethod,193 Arrays.toString(HttpMethod.values())));194 }195 ((AppiumCommandExecutor) getCommandExecutor()).refreshAdditionalCommands();196 }197 public URL getRemoteAddress() {198 return remoteAddress;199 }200 @Override201 protected void startSession(Capabilities capabilities) {202 Response response = execute(new AppiumNewSessionCommandPayload(capabilities));203 if (response == null) {204 throw new SessionNotCreatedException(205 "The underlying command executor returned a null response.");206 }207 Object responseValue = response.getValue();208 if (responseValue == null) {209 throw new SessionNotCreatedException(...
AppiumSteps.java
Source:AppiumSteps.java
...53import io.appium.java_client.MultiTouchAction;54import io.appium.java_client.TouchAction;55import io.appium.java_client.android.AndroidDriver;56import io.appium.java_client.ios.IOSDriver;57import io.appium.java_client.remote.AppiumCommandExecutor;58import io.appium.java_client.touch.WaitOptions;59import io.appium.java_client.touch.offset.PointOption;60import io.appium.java_client.windows.WindowsDriver;61/**62 * com.qmetry.qaf.automation.step.AppiumSteps.java63 * 64 * @author chirag.jayswal65 */66@SuppressWarnings("rawtypes")67public final class AppiumSteps {68 public static int PRESS_TIME = 200; // ms69 public static final WaitOptions watiOpt = WaitOptions.waitOptions(Duration.ofMillis(PRESS_TIME));70 /**71 * Swipe from Bottom to Top.72 */73 public static void swipeUp() {74 PointOption[] points = getXYtoVSwipe();75 new TouchAction(getAppiumDriver()).press(points[0]).waitAction(watiOpt)76 .moveTo(points[1]).release().perform();77 }78 /**79 * Swipe from Top to Bottom.80 */81 public static void swipeDown() {82 PointOption[] points = getXYtoVSwipe();83 new TouchAction(getAppiumDriver()).press(points[1]).waitAction(watiOpt)84 .moveTo(points[0]).release().perform();85 }86 /**87 * Swipe from Right to Left.88 */89 public static void swipeLeft() {90 PointOption[] points = getXYtoHSwipe();91 new TouchAction(getAppiumDriver()).press(points[0]).waitAction(watiOpt)92 .moveTo(points[1]).release().perform();93 }94 /**95 * Swipe from Left to Right96 */97 public static void swipeRight() {98 PointOption[] points = getXYtoHSwipe();99 new TouchAction(getAppiumDriver()).press(points[1]).waitAction(watiOpt)100 .moveTo(points[0]).release().perform();101 }102 /**103 * @return start and end points for vertical(top-bottom) swipe104 */105 private static PointOption[] getXYtoVSwipe() {106 // Get screen size.107 Dimension size = getAppiumDriver().manage().window().getSize();108 // Find x which is in middle of screen width.109 int startEndx = size.width / 2;110 // Find starty point which is at bottom side of screen.111 int starty = (int) (size.height * 0.70);112 // Find endy point which is at top side of screen.113 int endy = (int) (size.height * 0.30);114 //return PointOption.115 return new PointOption[]{PointOption.point(startEndx, starty), PointOption.point(startEndx, endy)};116 }117 /**118 * @return start and end points for horizontal(left-right) swipe119 */120 private static PointOption[] getXYtoHSwipe() {121 // Get screen size.122 Dimension size = getAppiumDriver().manage().window().getSize();123 // Find starting point x which is at right side of screen.124 int startx = (int) (size.width * 0.70);125 // Find ending point x which is at left side of screen.126 int endx = (int) (size.width * 0.30);127 // Find y which is in middle of screen height.128 int startEndy = size.height / 2;129 return new PointOption[]{PointOption.point(startx, startEndy), PointOption.point(endx, startEndy)};130 }131 /**132 * Press and hold the at an absolute position on the screen until the133 * context menu event has fired.134 *135 * @param x136 * x coordinate.137 * @param y138 * y coordinate.139 * @param duration140 * of the long-press, in milliseconds.141 */142 @QAFTestStep(stepName = "longPress", description = "longPress on {x} {y} for {duration} duration")143 public static void longPress(int x, int y, int duration) {144 MultiTouchAction multiTouch = new MultiTouchAction(getAppiumDriver());145 for (int i = 0; i < 1; i++) {146 TouchAction tap = new TouchAction(getAppiumDriver());147 multiTouch.add(tap.press(PointOption.point(x, y)).waitAction(WaitOptions.waitOptions(Duration.ofMillis(duration))).release());148 }149 multiTouch.perform();150 }151 /**152 * Creates the swiping action. It is supposed to be performed inside the153 * given element.154 *155 * @param startX156 * @param startY157 * @param endX158 * @param endY159 * @param duration160 * of the swipe, in milliseconds.161 */162 @QAFTestStep(stepName = "swipe", description = "swipe from {startX},{startY} to {endX},{endY} in {duration} duration")163 public static void swipe(int startX, int startY, int endX, int endY, int duration) {164 new TouchAction(getAppiumDriver()).press(PointOption.point(startX, startY)).waitAction(WaitOptions.waitOptions(Duration.ofMillis(duration)))165 .moveTo(PointOption.point(endX, endY)).release().perform();166 }167 @QAFTestStep(description = "switch driver to the {contextName} context ")168 public void switchContext(String contextName) {169 getAppiumDriver().context(contextName);170 }171 172 @SuppressWarnings("unchecked")173 public static AppiumDriver<WebElement> getAppiumDriver() {174 WebDriver driver = new WebDriverTestBase().getDriver().getUnderLayingDriver();175 if (driver instanceof AppiumDriver)176 return (AppiumDriver<WebElement>) new WebDriverTestBase().getDriver().getUnderLayingDriver();177 if (driver instanceof QAFExtendedWebDriver) {178 try {179 Capabilities capabilities = ((QAFExtendedWebDriver) driver).getCapabilities();180 HttpCommandExecutor executor = (HttpCommandExecutor) ((QAFExtendedWebDriver) driver)181 .getCommandExecutor();182 AppiumCommandExecutor appiumCommandExecutor = new AppiumCommandExecutor(MobileCommand.commandRepository,183 executor.getAddressOfRemoteServer()) {184 public Response execute(Command command) throws WebDriverException {185 if (DriverCommand.NEW_SESSION.equals(command.getName())) {186 setCommandCodec((CommandCodec<HttpRequest>) ClassUtil.getField("commandCodec", executor));187 setResponseCodec((ResponseCodec<HttpResponse>) ClassUtil.getField("responseCodec", executor));188 getAdditionalCommands().forEach(this::defineCommand);189 Response response = new Response(((QAFExtendedWebDriver) driver).getSessionId());190 response.setValue(JSONUtil.toMap(JSONUtil.toString(capabilities.asMap())));191 response.setStatus(ErrorCodes.SUCCESS);192 response.setState(ErrorCodes.SUCCESS_STRING);193 return response;194 } else {195 return super.execute(command);196 }...
IOSDriver.java
Source:IOSDriver.java
...20import io.appium.java_client.FindsByIosClassChain;21import io.appium.java_client.FindsByIosNSPredicate;22import io.appium.java_client.FindsByIosUIAutomation;23import io.appium.java_client.HidesKeyboardWithKeyName;24import io.appium.java_client.remote.AppiumCommandExecutor;25import io.appium.java_client.remote.MobilePlatform;26import io.appium.java_client.service.local.AppiumDriverLocalService;27import io.appium.java_client.service.local.AppiumServiceBuilder;28import org.openqa.selenium.Alert;29import org.openqa.selenium.Capabilities;30import org.openqa.selenium.WebElement;31import org.openqa.selenium.remote.DriverCommand;32import org.openqa.selenium.remote.Response;33import org.openqa.selenium.remote.http.HttpClient;34import org.openqa.selenium.security.Credentials;35import java.net.URL;36import java.time.Duration;37/**38 * @param <T> the required type of class which implement39 * {@link org.openqa.selenium.WebElement}.40 * Instances of the defined type will be returned via findElement* and findElements*.41 * Warning (!!!). Allowed types:42 * {@link org.openqa.selenium.WebElement}43 * {@link org.openqa.selenium.remote.RemoteWebElement}44 * {@link io.appium.java_client.MobileElement}45 * {@link io.appium.java_client.ios.IOSElement}46 */47public class IOSDriver<T extends WebElement>48 extends AppiumDriver<T>49 implements HidesKeyboardWithKeyName, ShakesDevice, HasIOSSettings,50 FindsByIosUIAutomation<T>, LocksIOSDevice, PerformsTouchID, FindsByIosNSPredicate<T>,51 FindsByIosClassChain<T> {52 private static final String IOS_PLATFORM = MobilePlatform.IOS;53 /**54 * @param executor is an instance of {@link org.openqa.selenium.remote.HttpCommandExecutor}55 * or class that extends it. Default commands or another vendor-specific56 * commands may be specified there.57 * @param capabilities take a look58 * at {@link org.openqa.selenium.Capabilities}59 */60 public IOSDriver(AppiumCommandExecutor executor, Capabilities capabilities) {61 super(executor, substituteMobilePlatform(capabilities, IOS_PLATFORM));62 }63 /**64 * @param remoteAddress is the address65 * of remotely/locally started Appium server66 * @param desiredCapabilities take a look67 * at {@link org.openqa.selenium.Capabilities}68 */69 public IOSDriver(URL remoteAddress, Capabilities desiredCapabilities) {70 super(remoteAddress, substituteMobilePlatform(desiredCapabilities, IOS_PLATFORM));71 }72 /**73 * @param remoteAddress is the address74 * of remotely/locally started Appium server...
AndroidDriver.java
Source:AndroidDriver.java
...20import io.appium.java_client.AppiumDriver;21import io.appium.java_client.CommandExecutionHelper;22import io.appium.java_client.FindsByAndroidUIAutomator;23import io.appium.java_client.PressesKeyCode;24import io.appium.java_client.remote.AppiumCommandExecutor;25import io.appium.java_client.remote.MobilePlatform;26import io.appium.java_client.service.local.AppiumDriverLocalService;27import io.appium.java_client.service.local.AppiumServiceBuilder;28import org.openqa.selenium.Capabilities;29import org.openqa.selenium.WebElement;30import org.openqa.selenium.remote.http.HttpClient;31import java.net.URL;32/**33 * @param <T> the required type of class which implement {@link org.openqa.selenium.WebElement}.34 * Instances of the defined type will be returned via findElement* and findElements*.35 * Warning (!!!). Allowed types:36 * {@link org.openqa.selenium.WebElement}37 * {@link org.openqa.selenium.remote.RemoteWebElement}38 * {@link io.appium.java_client.MobileElement}39 * {@link io.appium.java_client.android.AndroidElement}40 */41public class AndroidDriver<T extends WebElement>42 extends AppiumDriver<T>43 implements PressesKeyCode, HasNetworkConnection, PushesFiles, StartsActivity,44 FindsByAndroidUIAutomator<T>, LocksAndroidDevice, HasAndroidSettings, HasDeviceDetails,45 HasSupportedPerformanceDataType {46 private static final String ANDROID_PLATFORM = MobilePlatform.ANDROID;47 /**48 * @param executor is an instance of {@link org.openqa.selenium.remote.HttpCommandExecutor}49 * or class that extends it. Default commands or another vendor-specific50 * commands may be specified there.51 * @param capabilities take a look52 * at {@link org.openqa.selenium.Capabilities}53 */54 public AndroidDriver(AppiumCommandExecutor executor, Capabilities capabilities) {55 super(executor, substituteMobilePlatform(capabilities, ANDROID_PLATFORM));56 }57 /**58 * @param remoteAddress is the address of remotely/locally59 * started Appium server60 * @param desiredCapabilities take a look61 * at {@link org.openqa.selenium.Capabilities}62 */63 public AndroidDriver(URL remoteAddress, Capabilities desiredCapabilities) {64 super(remoteAddress, substituteMobilePlatform(desiredCapabilities, ANDROID_PLATFORM));65 }66 /**67 * @param remoteAddress is the address of remotely/locally68 * started Appium server...
AppiumCommandExecutor.java
Source:AppiumCommandExecutor.java
...41import java.io.IOException;42import java.net.ConnectException;43import java.net.URL;44import java.util.Map;45public class AppiumCommandExecutor implements CommandExecutor {46 private final URL remoteServer;47 private final HttpClient client;48 private final Map<String, AppiumCommandInfo> additionalCommands;49 private CommandCodec<HttpRequest> commandCodec;50 private ResponseCodec<HttpResponse> responseCodec;51 private DriverService service;52 /**53 * Cretes an instance that sends requests and receives responses.54 * 55 * @param additionalCommands is the mapped command repository56 * @param addressOfRemoteServer is the url to connect to the Appium remote/local server57 * @param httpClientFactory is the http client factory58 */59 public AppiumCommandExecutor(Map<String, AppiumCommandInfo> additionalCommands,60 URL addressOfRemoteServer, HttpClient.Factory httpClientFactory) {61 checkNotNull(addressOfRemoteServer);62 remoteServer = addressOfRemoteServer;63 this.additionalCommands = additionalCommands;64 this.client = httpClientFactory.createClient(remoteServer);65 }66 public AppiumCommandExecutor(Map<String, AppiumCommandInfo> additionalCommands, DriverService service,67 HttpClient.Factory httpClientFactory) {68 this(additionalCommands, service.getUrl(), httpClientFactory);69 this.service = service;70 }71 public AppiumCommandExecutor(Map<String, AppiumCommandInfo> additionalCommands,72 URL addressOfRemoteServer) {73 this(additionalCommands, addressOfRemoteServer, new ApacheHttpClient.Factory());74 }75 public AppiumCommandExecutor(Map<String, AppiumCommandInfo> additionalCommands,76 DriverService service) {77 this(additionalCommands, service, new ApacheHttpClient.Factory());78 }79 public URL getAddressOfRemoteServer() {80 return remoteServer;81 }82 private Response doExecute(Command command) throws IOException, WebDriverException {83 if (command.getSessionId() == null) {84 if (QUIT.equals(command.getName())) {85 return new Response();86 }87 if (!GET_ALL_SESSIONS.equals(command.getName())88 && !NEW_SESSION.equals(command.getName())) {89 throw new NoSuchSessionException(...
WindowsDriver.java
Source:WindowsDriver.java
...18import io.appium.java_client.AppiumDriver;19import io.appium.java_client.FindsByWindowsAutomation;20import io.appium.java_client.HidesKeyboardWithKeyName;21import io.appium.java_client.PressesKeyCode;22import io.appium.java_client.remote.AppiumCommandExecutor;23import io.appium.java_client.service.local.AppiumDriverLocalService;24import io.appium.java_client.service.local.AppiumServiceBuilder;25import org.openqa.selenium.Capabilities;26import org.openqa.selenium.WebElement;27import org.openqa.selenium.remote.http.HttpClient;28import java.net.URL;29public class WindowsDriver<T extends WebElement>30 extends AppiumDriver<T> implements PressesKeyCode, HidesKeyboardWithKeyName,31 FindsByWindowsAutomation<T> {32 public WindowsDriver(AppiumCommandExecutor executor, Capabilities capabilities) {33 super(executor, substituteMobilePlatform(capabilities, WINDOWS));34 }35 public WindowsDriver(URL remoteAddress, Capabilities desiredCapabilities) {36 super(remoteAddress, substituteMobilePlatform(desiredCapabilities, WINDOWS));37 }38 public WindowsDriver(URL remoteAddress, HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities) {39 super(remoteAddress, httpClientFactory, substituteMobilePlatform(desiredCapabilities, WINDOWS));40 }41 public WindowsDriver(AppiumDriverLocalService service, Capabilities desiredCapabilities) {42 super(service, substituteMobilePlatform(desiredCapabilities, WINDOWS));43 }44 public WindowsDriver(AppiumDriverLocalService service, HttpClient.Factory httpClientFactory,45 Capabilities desiredCapabilities) {46 super(service, httpClientFactory, substituteMobilePlatform(desiredCapabilities, WINDOWS));...
SampleAppiumDriverTest.java
Source:SampleAppiumDriverTest.java
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();...
TapOnelement.java
Source:TapOnelement.java
...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}...
AppiumCommandExecutor
Using AI Code Generation
1package appium.java;2import io.appium.java_client.android.AndroidDriver;3import io.appium.java_client.remote.AppiumCommandExecutor;4import io.appium.java_client.remote.MobileCapabilityType;5import java.net.MalformedURLException;6import java.net.URL;7import java.util.concurrent.TimeUnit;8import org.openqa.selenium.remote.DesiredCapabilities;9public class Appium {10public static void main(String[] args) throws MalformedURLException {11DesiredCapabilities cap = new DesiredCapabilities();12cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Android");13cap.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");14cap.setCapability(MobileCapabilityType.BROWSER_NAME, "Chrome");15cap.setCapability(MobileCapabilityType.VERSION, "6.0.1");16cap.setCapability(MobileCapabilityType.UDID, "emulator-5554");17cap.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, "100");
AppiumCommandExecutor
Using AI Code Generation
1AppiumDriverLocalService service = AppiumDriverLocalService.buildDefaultService();2service.start();3URL url = service.getUrl();4AppiumCommandExecutor executor = new AppiumCommandExecutor(url);5driver = new AndroidDriver<>(executor, capabilities);6AppiumDriverLocalService service = AppiumDriverLocalService.buildDefaultService();7service.start();8URL url = service.getUrl();9AppiumCommandExecutor executor = new AppiumCommandExecutor(url);10driver = new IOSDriver<>(executor, capabilities);11AppiumDriverLocalService service = AppiumDriverLocalService.buildDefaultService();12service.start();13URL url = service.getUrl();14AppiumCommandExecutor executor = new AppiumCommandExecutor(url);15driver = new WindowsDriver<>(executor, capabilities);16AppiumDriverLocalService service = AppiumDriverLocalService.buildDefaultService();17service.start();18URL url = service.getUrl();19AppiumCommandExecutor executor = new AppiumCommandExecutor(url);20driver = new RemoteWebDriver(executor, capabilities);21AppiumDriverLocalService service = AppiumDriverLocalService.buildDefaultService();22service.start();23URL url = service.getUrl();24AppiumCommandExecutor executor = new AppiumCommandExecutor(url);25driver = new AppiumDriver<>(executor, capabilities);26AppiumDriverLocalService service = AppiumDriverLocalService.buildDefaultService();27service.start();28URL url = service.getUrl();29AppiumCommandExecutor executor = new AppiumCommandExecutor(url);30driver = new AppiumDriver<>(executor, capabilities);31AppiumDriverLocalService service = AppiumDriverLocalService.buildDefaultService();32service.start();33URL url = service.getUrl();34AppiumCommandExecutor executor = new AppiumCommandExecutor(url);35driver = new AppiumDriver<>(executor, capabilities);
AppiumCommandExecutor
Using AI Code Generation
1import io.appium.java_client.remote.AppiumCommandExecutor;2import io.appium.java_client.remote.AppiumCommandExecutorFactory;3import org.openqa.selenium.remote.CommandExecutor;4import org.openqa.selenium.remote.DesiredCapabilities;5import org.openqa.selenium.remote.RemoteWebDriver;6import java.net.URL;7public class AppiumJavaClient {8 public static void main(String[] args) throws Exception {
AppiumCommandExecutor
Using AI Code Generation
1import io.appium.java_client.AppiumDriver;2import io.appium.java_client.remote.AppiumCommandExecutor;3import org.openqa.selenium.remote.DesiredCapabilities;4import java.net.URL;5public class appium {6public static void main(String[] args) throws Exception {7AppiumDriver driver;8DesiredCapabilities capabilities = new DesiredCapabilities();9capabilities.setCapability("deviceName", "Android Emulator");10capabilities.setCapability("platformName", "Android");11capabilities.setCapability("platformVersion", "4.4");12capabilities.setCapability("app", "C:UsersDownloadsCalculator.apk");13capabilities.setCapability("appPackage", "com.android.calculator2");14capabilities.setCapability("appActivity", "Calculator");15capabilities.setCapability("appWaitActivity", "Calculator");16capabilities.setCapability("appium-version", "1.2.3");17capabilities.setCapability("appWaitPackage", "com.android.calculator2");18capabilities.setCapability("appWaitActivity", "Calculator");19capabilities.setCapability("automationName", "Selendroid");20capabilities.setCapability("browserName", "Chrome");21capabilities.setCapability("udid", "emulator-5554");22capabilities.setCapability("newCommandTimeout", "60");23capabilities.setCapability("platform", "MAC");
AppiumCommandExecutor
Using AI Code Generation
1import org.openqa.selenium.WebDriver;2import org.openqa.selenium.remote.CommandExecutor;3import org.openqa.selenium.remote.DesiredCapabilities;4import org.openqa.selenium.remote.RemoteWebDriver;5import io.appium.java_client.AppiumDriver;6import io.appium.java_client.remote.AppiumCommandExecutor;7import io.appium.java_client.remote.AppiumParameter;8public class AppiumCommandExecutorExample {9 public static void main(String[] args) {10 DesiredCapabilities capabilities = new DesiredCapabilities();11 capabilities.setCapability("deviceName", "Android Emulator");12 capabilities.setCapability("platformName", "Android");13 capabilities.setCapability("appPackage", "com.example.android.contactmanager");14 capabilities.setCapability("appActivity", ".ContactManager");
AppiumCommandExecutor
Using AI Code Generation
1package appium.java;2import java.net.URL;3import java.util.concurrent.TimeUnit;4import org.openqa.selenium.remote.DesiredCapabilities;5import io.appium.java_client.AppiumDriver;6import io.appium.java_client.android.AndroidDriver;7import io.appium.java_client.remote.MobileCapabilityType;8import io.appium.java_client.remote.MobilePlatform;9public class AppiumJava {10 public static void main(String[] args) {11 AppiumDriver driver;12 DesiredCapabilities capabilities = new DesiredCapabilities();13 capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID);14 capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Device");15 capabilities.setCapability(MobileCapabilityType.APP, "C:\\Users\\Sudhakar\\Downloads\\Calculator_v7.4_apkpure.com.apk");16 try {
AppiumCommandExecutor
Using AI Code Generation
1import io.appium.java_client.remote.AppiumCommandExecutor;2import java.net.URL;3import org.openqa.selenium.remote.DesiredCapabilities;4import org.openqa.selenium.remote.RemoteWebDriver;5public class Appium {6public static void main(String[] args) throws MalformedURLException {7DesiredCapabilities capabilities = new DesiredCapabilities();8capabilities.setCapability("deviceName", "Android Emulator");9capabilities.setCapability(CapabilityType.BROWSER_NAME, "Android");10capabilities.setCapability(CapabilityType.VERSION, "4.2");11capabilities.setCapability("platformName", "Android");12capabilities.setCapability("appPackage", "com.android.calculator2");13capabilities.setCapability("appActivity", ".Calculator");
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!!