How to use execute method of io.appium.java_client.AppiumExecutionMethod class

Best io.appium code snippet using io.appium.java_client.AppiumExecutionMethod.execute

AppiumDriver_4.1.2.java

Source:AppiumDriver_4.1.2.java Github

copy

Full Screen

...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 }226 /**227 * @see InteractsWithApps#removeApp(String).228 */229 @Override public void removeApp(String bundleId) {230 execute(REMOVE_APP, ImmutableMap.of("bundleId", bundleId));231 }232 /**233 * @see InteractsWithApps#launchApp().234 */235 @Override public void launchApp() {236 execute(LAUNCH_APP);237 }238 /**239 * @see InteractsWithApps#closeApp().240 */241 @Override public void closeApp() {242 execute(CLOSE_APP);243 }244 /**245 * @see InteractsWithApps#runAppInBackground(int).246 */247 @Override public void runAppInBackground(int seconds) {248 execute(RUN_APP_IN_BACKGROUND, ImmutableMap.of("seconds", seconds));249 }250 /**251 * @see DeviceActionShortcuts#getDeviceTime().252 */253 @Override public String getDeviceTime() {254 Response response = execute(GET_DEVICE_TIME);255 return response.getValue().toString();256 }257 /**258 * @see DeviceActionShortcuts#hideKeyboard().259 */260 @Override public void hideKeyboard() {261 execute(HIDE_KEYBOARD);262 }263 /**264 * @see InteractsWithFiles#pullFile(String).265 */266 @Override public byte[] pullFile(String remotePath) {267 Response response = execute(PULL_FILE, ImmutableMap.of("path", remotePath));268 String base64String = response.getValue().toString();269 return DatatypeConverter.parseBase64Binary(base64String);270 }271 /**272 * @see InteractsWithFiles#pullFolder(String).273 */274 @Override275 public byte[] pullFolder(String remotePath) {276 Response response = execute(PULL_FOLDER, ImmutableMap.of("path", remotePath));277 String base64String = response.getValue().toString();278 return DatatypeConverter.parseBase64Binary(base64String);279 }280 /**281 * @see PerformsTouchActions#performTouchAction(TouchAction).282 */283 @SuppressWarnings("rawtypes")284 @Override public TouchAction performTouchAction(285 TouchAction touchAction) {286 ImmutableMap<String, ImmutableList> parameters = touchAction.getParameters();287 execute(PERFORM_TOUCH_ACTION, parameters);288 return touchAction;289 }290 /**291 * @see PerformsTouchActions#performMultiTouchAction(MultiTouchAction).292 */293 @Override294 @SuppressWarnings({"rawtypes"})295 public void performMultiTouchAction(296 MultiTouchAction multiAction) {297 ImmutableMap<String, ImmutableList> parameters = multiAction.getParameters();298 execute(PERFORM_MULTI_TOUCH, parameters);299 }300 /**301 * @see TouchShortcuts#tap(int, WebElement, int).302 */303 @Override public void tap(int fingers, WebElement element, int duration) {304 MultiTouchAction multiTouch = new MultiTouchAction(this);305 for (int i = 0; i < fingers; i++) {306 multiTouch.add(createTap(element, duration));307 }308 multiTouch.perform();309 }310 /**311 * @see TouchShortcuts#tap(int, int, int, int).312 */313 @Override public void tap(int fingers, int x, int y, int duration) {314 MultiTouchAction multiTouch = new MultiTouchAction(this);315 for (int i = 0; i < fingers; i++) {316 multiTouch.add(createTap(x, y, duration));317 }318 multiTouch.perform();319 }320 protected void doSwipe(int startx, int starty, int endx, int endy, int duration) {321 TouchAction touchAction = new TouchAction(this);322 // appium converts press-wait-moveto-release to a swipe action323 touchAction.press(startx, starty).waitAction(duration).moveTo(endx, endy).release();324 touchAction.perform();325 }326 /**327 * @see TouchShortcuts#swipe(int, int, int, int, int).328 */329 @Override public abstract void swipe(int startx, int starty, int endx, int endy, int duration);330 /**331 * Convenience method for pinching an element on the screen.332 * "pinching" refers to the action of two appendages pressing the333 * screen and sliding towards each other.334 * NOTE:335 * This convenience method places the initial touches around the element, if this would336 * happen to place one of them off the screen, appium with return an outOfBounds error.337 * In this case, revert to using the MultiTouchAction api instead of this method.338 *339 * @param el The element to pinch.340 */341 public void pinch(WebElement el) {342 MultiTouchAction multiTouch = new MultiTouchAction(this);343 Dimension dimensions = el.getSize();344 Point upperLeft = el.getLocation();345 Point center = new Point(upperLeft.getX() + dimensions.getWidth() / 2,346 upperLeft.getY() + dimensions.getHeight() / 2);347 int yOffset = center.getY() - upperLeft.getY();348 TouchAction action0 =349 new TouchAction(this).press(el, center.getX(), center.getY() - yOffset).moveTo(el)350 .release();351 TouchAction action1 =352 new TouchAction(this).press(el, center.getX(), center.getY() + yOffset).moveTo(el)353 .release();354 multiTouch.add(action0).add(action1);355 multiTouch.perform();356 }357 /**358 * Convenience method for pinching an element on the screen.359 * "pinching" refers to the action of two appendages pressing the screen and360 * sliding towards each other.361 * NOTE:362 * This convenience method places the initial touches around the element at a distance,363 * if this would happen to place one of them off the screen, appium will return an364 * outOfBounds error. In this case, revert to using the MultiTouchAction api instead of this365 * method.366 *367 * @param x x coordinate to terminate the pinch on.368 * @param y y coordinate to terminate the pinch on.369 */370 public void pinch(int x, int y) {371 MultiTouchAction multiTouch = new MultiTouchAction(this);372 int scrHeight = manage().window().getSize().getHeight();373 int yOffset = 100;374 if (y - 100 < 0) {375 yOffset = y;376 } else if (y + 100 > scrHeight) {377 yOffset = scrHeight - y;378 }379 TouchAction action0 = new TouchAction(this).press(x, y - yOffset).moveTo(x, y).release();380 TouchAction action1 = new TouchAction(this).press(x, y + yOffset).moveTo(x, y).release();381 multiTouch.add(action0).add(action1);382 multiTouch.perform();383 }384 /**385 * Convenience method for "zooming in" on an element on the screen.386 * "zooming in" refers to the action of two appendages pressing the screen and sliding387 * away from each other.388 * NOTE:389 * This convenience method slides touches away from the element, if this would happen390 * to place one of them off the screen, appium will return an outOfBounds error.391 * In this case, revert to using the MultiTouchAction api instead of this method.392 *393 * @param el The element to pinch.394 */395 public void zoom(WebElement el) {396 MultiTouchAction multiTouch = new MultiTouchAction(this);397 Dimension dimensions = el.getSize();398 Point upperLeft = el.getLocation();399 Point center = new Point(upperLeft.getX() + dimensions.getWidth() / 2,400 upperLeft.getY() + dimensions.getHeight() / 2);401 int yOffset = center.getY() - upperLeft.getY();402 TouchAction action0 = new TouchAction(this).press(center.getX(), center.getY())403 .moveTo(el, center.getX(), center.getY() - yOffset).release();404 TouchAction action1 = new TouchAction(this).press(center.getX(), center.getY())405 .moveTo(el, center.getX(), center.getY() + yOffset).release();406 multiTouch.add(action0).add(action1);407 multiTouch.perform();408 }409 /**410 * Convenience method for "zooming in" on an element on the screen.411 * "zooming in" refers to the action of two appendages pressing the screen412 * and sliding away from each other.413 * NOTE:414 * This convenience method slides touches away from the element, if this would happen to415 * place one of them off the screen, appium will return an outOfBounds error. In this case,416 * revert to using the MultiTouchAction api instead of this method.417 *418 * @param x x coordinate to start zoom on.419 * @param y y coordinate to start zoom on.420 */421 public void zoom(int x, int y) {422 MultiTouchAction multiTouch = new MultiTouchAction(this);423 int scrHeight = manage().window().getSize().getHeight();424 int yOffset = 100;425 if (y - 100 < 0) {426 yOffset = y;427 } else if (y + 100 > scrHeight) {428 yOffset = scrHeight - y;429 }430 TouchAction action0 = new TouchAction(this).press(x, y).moveTo(0, -yOffset).release();431 TouchAction action1 = new TouchAction(this).press(x, y).moveTo(0, yOffset).release();432 multiTouch.add(action0).add(action1);433 multiTouch.perform();434 }435 /**436 * Get settings stored for this test session It's probably better to use a437 * convenience function, rather than use this function directly. Try finding438 * the method for the specific setting you want to read.439 *440 * @return JsonObject, a straight-up hash of settings.441 */442 public JsonObject getSettings() {443 Response response = execute(GET_SETTINGS);444 JsonParser parser = new JsonParser();445 return (JsonObject) parser.parse(response.getValue().toString());446 }447 /**448 * Set settings for this test session It's probably better to use a449 * convenience function, rather than use this function directly. Try finding450 * the method for the specific setting you want to change.451 *452 * @param settings Map of setting keys and values.453 */454 private void setSettings(ImmutableMap<?, ?> settings) {455 execute(SET_SETTINGS, prepareArguments("settings", settings));456 }457 /**458 * Set a setting for this test session It's probably better to use a459 * convenience function, rather than use this function directly. Try finding460 * the method for the specific setting you want to change.461 *462 * @param setting AppiumSetting you wish to set.463 * @param value value of the setting.464 */465 protected void setSetting(AppiumSetting setting, Object value) {466 setSettings(prepareArguments(setting.toString(), value));467 }468 @Override public WebDriver context(String name) {469 checkNotNull(name, "Must supply a context name");470 execute(DriverCommand.SWITCH_TO_CONTEXT, ImmutableMap.of("name", name));471 return this;472 }473 @Override public Set<String> getContextHandles() {474 Response response = execute(DriverCommand.GET_CONTEXT_HANDLES);475 Object value = response.getValue();476 try {477 List<String> returnedValues = (List<String>) value;478 return new LinkedHashSet<>(returnedValues);479 } catch (ClassCastException ex) {480 throw new WebDriverException(481 "Returned value cannot be converted to List<String>: " + value, ex);482 }483 }484 @Override public String getContext() {485 String contextName =486 String.valueOf(execute(DriverCommand.GET_CURRENT_CONTEXT_HANDLE).getValue());487 if (contextName.equals("null")) {488 return null;489 }490 return contextName;491 }492 @Override public void rotate(ScreenOrientation orientation) {493 execute(DriverCommand.SET_SCREEN_ORIENTATION,494 ImmutableMap.of("orientation", orientation.value().toUpperCase()));495 }496 @Override public ScreenOrientation getOrientation() {497 Response response = execute(DriverCommand.GET_SCREEN_ORIENTATION);498 String orientation = response.getValue().toString().toLowerCase();499 if (orientation.equals(ScreenOrientation.LANDSCAPE.value())) {500 return ScreenOrientation.LANDSCAPE;501 } else if (orientation.equals(ScreenOrientation.PORTRAIT.value())) {502 return ScreenOrientation.PORTRAIT;503 } else {504 throw new WebDriverException("Unexpected orientation returned: " + orientation);505 }506 }507 @Override public Location location() {508 return locationContext.location();509 }510 @Override public void setLocation(Location location) {511 locationContext.setLocation(location);512 }513 /**514 * @return a map with localized strings defined in the app.515 * @see HasAppStrings#getAppStringMap().516 */517 @Override public Map<String, String> getAppStringMap() {518 Response response = execute(GET_STRINGS);519 return (Map<String, String>) response.getValue();520 }521 /**522 * @param language strings language code.523 * @return a map with localized strings defined in the app.524 * @see HasAppStrings#getAppStringMap(String).525 */526 @Override public Map<String, String> getAppStringMap(String language) {527 Response response = execute(GET_STRINGS, prepareArguments("language", language));528 return (Map<String, String>) response.getValue();529 }530 /**531 * @param language strings language code.532 * @param stringFile strings filename.533 * @return a map with localized strings defined in the app.534 * @see HasAppStrings#getAppStringMap(String, String).535 */536 @Override public Map<String, String> getAppStringMap(String language, String stringFile) {537 String[] parameters = new String[] {"language", "stringFile"};538 Object[] values = new Object[] {language, stringFile};539 Response response = execute(GET_STRINGS, prepareArguments(parameters, values));540 return (Map<String, String>) response.getValue();541 }542 private TouchAction createTap(WebElement element, int duration) {543 TouchAction tap = new TouchAction(this);544 return tap.press(element).waitAction(duration).release();545 }546 private TouchAction createTap(int x, int y, int duration) {547 TouchAction tap = new TouchAction(this);548 return tap.press(x, y).waitAction(duration).release();549 }550 public URL getRemoteAddress() {551 return remoteAddress;552 }553 /**554 * @return a map with values that hold session details.555 *556 */557 public Map<String, Object> getSessionDetails() {558 Response response = execute(GET_SESSION);559 return (Map<String, Object>) response.getValue();560 }561}...

Full Screen

Full Screen

AppiumDriver.java

Source:AppiumDriver.java Github

copy

Full Screen

...60 private static final ErrorHandler errorHandler = new ErrorHandler(new ErrorCodesMobile(), true);61 // frequently used command parameters62 private URL remoteAddress;63 private RemoteLocationContext locationContext;64 private ExecuteMethod executeMethod;65 private final String platformName;66 private final String automationName;67 /**68 * @param executor is an instance of {@link org.openqa.selenium.remote.HttpCommandExecutor}69 * or class that extends it. Default commands or another vendor-specific70 * commands may be specified there.71 * @param capabilities take a look72 * at {@link org.openqa.selenium.Capabilities}73 */74 public AppiumDriver(AppiumCommandExecutor executor, Capabilities capabilities) {75 super(executor, capabilities);76 this.executeMethod = new AppiumExecutionMethod(this);77 locationContext = new RemoteLocationContext(executeMethod);78 super.setErrorHandler(errorHandler);79 this.remoteAddress = executor.getAddressOfRemoteServer();80 Object capabilityPlatform1 = getCapabilities().getCapability(PLATFORM_NAME);81 Object capabilityAutomation1 = getCapabilities().getCapability(AUTOMATION_NAME);82 Object capabilityPlatform2 = capabilities.getCapability(PLATFORM_NAME);83 Object capabilityAutomation2 = capabilities.getCapability(AUTOMATION_NAME);84 platformName = ofNullable(ofNullable(super.getPlatformName())85 .orElse(capabilityPlatform1 != null ? String.valueOf(capabilityPlatform1) : null))86 .orElse(capabilityPlatform2 != null ? String.valueOf(capabilityPlatform2) : null);87 automationName = ofNullable(ofNullable(super.getAutomationName())88 .orElse(capabilityAutomation1 != null ? String.valueOf(capabilityAutomation1) : null))89 .orElse(capabilityAutomation2 != null ? String.valueOf(capabilityAutomation2) : null);90 this.setElementConverter(new JsonToMobileElementConverter(this, this));91 }92 public AppiumDriver(URL remoteAddress, Capabilities desiredCapabilities) {93 this(new AppiumCommandExecutor(MobileCommand.commandRepository, remoteAddress),94 desiredCapabilities);95 }96 public AppiumDriver(URL remoteAddress, HttpClient.Factory httpClientFactory,97 Capabilities desiredCapabilities) {98 this(new AppiumCommandExecutor(MobileCommand.commandRepository, remoteAddress,99 httpClientFactory), desiredCapabilities);100 }101 public AppiumDriver(AppiumDriverLocalService service, Capabilities desiredCapabilities) {102 this(new AppiumCommandExecutor(MobileCommand.commandRepository, service),103 desiredCapabilities);104 }105 public AppiumDriver(AppiumDriverLocalService service, HttpClient.Factory httpClientFactory,106 Capabilities desiredCapabilities) {107 this(new AppiumCommandExecutor(MobileCommand.commandRepository, service, httpClientFactory),108 desiredCapabilities);109 }110 public AppiumDriver(AppiumServiceBuilder builder, Capabilities desiredCapabilities) {111 this(builder.build(), desiredCapabilities);112 }113 public AppiumDriver(AppiumServiceBuilder builder, HttpClient.Factory httpClientFactory,114 Capabilities desiredCapabilities) {115 this(builder.build(), httpClientFactory, desiredCapabilities);116 }117 public AppiumDriver(HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities) {118 this(AppiumDriverLocalService.buildDefaultService(), httpClientFactory,119 desiredCapabilities);120 }121 public AppiumDriver(Capabilities desiredCapabilities) {122 this(AppiumDriverLocalService.buildDefaultService(), desiredCapabilities);123 }124 /**125 * @param originalCapabilities the given {@link Capabilities}.126 * @param newPlatform a {@link MobileCapabilityType#PLATFORM_NAME} value which has127 * to be set up128 * @return {@link Capabilities} with changed mobile platform value129 */130 protected static Capabilities substituteMobilePlatform(Capabilities originalCapabilities,131 String newPlatform) {132 DesiredCapabilities dc = new DesiredCapabilities(originalCapabilities);133 dc.setCapability(PLATFORM_NAME, newPlatform);134 return dc;135 }136 @Override public List<T> findElements(By by) {137 return super.findElements(by);138 }139 @Override public List<T> findElements(String by, String using) {140 return super.findElements(by, using);141 }142 @Override public List<T> findElementsById(String id) {143 return super.findElementsById(id);144 }145 public List<T> findElementsByLinkText(String using) {146 return super.findElementsByLinkText(using);147 }148 public List<T> findElementsByPartialLinkText(String using) {149 return super.findElementsByPartialLinkText(using);150 }151 public List<T> findElementsByTagName(String using) {152 return super.findElementsByTagName(using);153 }154 public List<T> findElementsByName(String using) {155 return super.findElementsByName(using);156 }157 public List<T> findElementsByClassName(String using) {158 return super.findElementsByClassName(using);159 }160 public List<T> findElementsByCssSelector(String using) {161 return super.findElementsByCssSelector(using);162 }163 public List<T> findElementsByXPath(String using) {164 return super.findElementsByXPath(using);165 }166 @Override public List<T> findElementsByAccessibilityId(String using) {167 return super.findElementsByAccessibilityId(using);168 }169 @Override public ExecuteMethod getExecuteMethod() {170 return executeMethod;171 }172 @Override public WebDriver context(String name) {173 checkNotNull(name, "Must supply a context name");174 execute(DriverCommand.SWITCH_TO_CONTEXT, ImmutableMap.of("name", name));175 return this;176 }177 @Override public Set<String> getContextHandles() {178 Response response = execute(DriverCommand.GET_CONTEXT_HANDLES);179 Object value = response.getValue();180 try {181 List<String> returnedValues = (List<String>) value;182 return new LinkedHashSet<>(returnedValues);183 } catch (ClassCastException ex) {184 throw new WebDriverException(185 "Returned value cannot be converted to List<String>: " + value, ex);186 }187 }188 @Override public String getContext() {189 String contextName =190 String.valueOf(execute(DriverCommand.GET_CURRENT_CONTEXT_HANDLE).getValue());191 if ("null".equalsIgnoreCase(contextName)) {192 return null;193 }194 return contextName;195 }196 @Override public DeviceRotation rotation() {197 Response response = execute(DriverCommand.GET_SCREEN_ROTATION);198 DeviceRotation deviceRotation =199 new DeviceRotation((Map<String, Number>) response.getValue());200 if (deviceRotation.getX() < 0 || deviceRotation.getY() < 0 || deviceRotation.getZ() < 0) {201 throw new WebDriverException("Unexpected orientation returned: " + deviceRotation);202 }203 return deviceRotation;204 }205 @Override public void rotate(DeviceRotation rotation) {206 execute(DriverCommand.SET_SCREEN_ROTATION, rotation.parameters());207 }208 @Override public void rotate(ScreenOrientation orientation) {209 execute(DriverCommand.SET_SCREEN_ORIENTATION,210 ImmutableMap.of("orientation", orientation.value().toUpperCase()));211 }212 @Override public ScreenOrientation getOrientation() {213 Response response = execute(DriverCommand.GET_SCREEN_ORIENTATION);214 String orientation = response.getValue().toString().toLowerCase();215 if (orientation.equals(ScreenOrientation.LANDSCAPE.value())) {216 return ScreenOrientation.LANDSCAPE;217 } else if (orientation.equals(ScreenOrientation.PORTRAIT.value())) {218 return ScreenOrientation.PORTRAIT;219 } else {220 throw new WebDriverException("Unexpected orientation returned: " + orientation);221 }222 }223 @Override public Location location() {224 return locationContext.location();225 }226 @Override public void setLocation(Location location) {227 locationContext.setLocation(location);...

Full Screen

Full Screen

AppiumExecutionMethod.java

Source:AppiumExecutionMethod.java Github

copy

Full Screen

...7 private final AppiumDriver driver;8 public AppiumExecutionMethod(AppiumDriver driver) {9 this.driver = driver;10 }11 public Object execute(String commandName, Map<String, ?> parameters) {12 Response response;13 if (parameters == null || parameters.isEmpty()) {14 response = driver.execute(commandName, ImmutableMap.<String, Object>of());15 } else {16 response = driver.execute(commandName, parameters);17 }18 return response.getValue();19 }20}...

Full Screen

Full Screen

execute

Using AI Code Generation

copy

Full Screen

1import io.appium.java_client.AppiumDriver;2import io.appium.java_client.MobileElement;3import io.appium.java_client.android.AndroidDriver;4import io.appium.java_client.remote.MobileCapabilityType;5import java.net.MalformedURLException;6import java.net.URL;7import org.openqa.selenium.remote.DesiredCapabilities;8public class Execute {9 public static void main(String[] args) throws MalformedURLException, InterruptedException {10 DesiredCapabilities cap = new DesiredCapabilities();11 cap.setCapability(MobileCapabilityType.DEVICE_NAME, "emulator-5554");12 cap.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");13 cap.setCapability(MobileCapabilityType.PLATFORM_VERSION, "7.0");14 cap.setCapability("appPackage", "com.android.calculator2");15 cap.setCapability("appActivity", "com.android.calculator2.Calculator");

Full Screen

Full Screen

execute

Using AI Code Generation

copy

Full Screen

1driver.execute(AppiumExecutionMethod.EXECUTE_SCRIPT, "alert('Hello World!');");2driver.executeScript("alert('Hello World!');");3driver.execute(:execute_script, "alert('Hello World!');")4driver.execute_script("alert('Hello World!');")5driver.execute("execute_script", "alert('Hello World!');");6driver.executeScript("alert('Hello World!');");7driver.execute("execute_script", "alert('Hello World!');")8driver.execute_script("alert('Hello World!');")9driver.execute("execute_script", "alert('Hello World!');");10driver.executeScript("alert('Hello World!');");11$driver->execute("execute_script", "alert('Hello World!');");12$driver->executeScript("alert('Hello World!');");13driver.ExecuteScript("alert('Hello World!');");14driver.ExecuteScript("alert('Hello World!');");15driver.execute("execute_script", "alert('Hello World!');");16driver.executeScript("alert('Hello World!');");17driver.ExecuteScript("alert('Hello World!');");18driver.ExecuteScript("alert('Hello World!');");

Full Screen

Full Screen

execute

Using AI Code Generation

copy

Full Screen

1import io.appium.java_client.AppiumDriver;2import io.appium.java_client.AppiumExecutionMethod;3import io.appium.java_client.android.AndroidDriver;4import org.openqa.selenium.remote.DesiredCapabilities;5import java.net.URL;6import java.net.MalformedURLException;7public class Appium {8 public static void main(String[] args) throws MalformedURLException {9 DesiredCapabilities capabilities = new DesiredCapabilities();10 capabilities.setCapability("deviceName","Android Emulator");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");15 AppiumDriver driver = AppiumExecutionMethod.getAndroidDriver(capabilities);16 driver.findElementById("com.android.calculator2:id/digit_1").click();17 driver.findElementById("com.android.calculator2:id/op_add").click();18 driver.findElementById("com.android.calculator2:id/digit_9").click();19 driver.findElementById("com.android.calculator2:id/eq").click();20 System.out.println("Actual value is : "+driver.findElementById("com.android.calculator2:id/formula").getText()+" did not match with expected value: 10");21 driver.quit();22 }23}

Full Screen

Full Screen

execute

Using AI Code Generation

copy

Full Screen

1driver.executeScript("mobile: swipe", swipeObject);2self.driver.execute_script("mobile: swipe", swipeObject)3driver.execute("mobile: swipe", swipeObject);4driver.execute_script('mobile: swipe', swipeObject)5$driver->executeScript('mobile: swipe', $swipeObject);6driver.execute_script('mobile: swipe', swipeObject)7driver.ExecuteScript("mobile: swipe", swipeObject);8driver.ExecuteScript("mobile: swipe", swipeObject)9driver.executeScript("mobile: swipe", swipeObject)10$driver->execute_script('mobile: swipe', $swipeObject);11driver->execute_script("mobile: swipe", swipeObject);12driver.execute_script('mobile: swipe', swipeObject)

Full Screen

Full Screen

execute

Using AI Code Generation

copy

Full Screen

1package appium;2import java.net.MalformedURLException;3import java.net.URL;4import java.util.concurrent.TimeUnit;5import org.openqa.selenium.By;6import org.openqa.selenium.WebDriver;7import org.openqa.selenium.WebElement;8import org.openqa.selenium.remote.DesiredCapabilities;9import io.appium.java_client.AppiumDriver;10import io.appium.java_client.AppiumExecutionMethod;11import io.appium.java_client.MobileElement;12import io.appium.java_client.android.AndroidDriver;13public class ExecuteJavascript {14 public static void main(String[] args) throws MalformedURLException {15 DesiredCapabilities caps = new DesiredCapabilities();16 caps.setCapability("deviceName", "emulator-5554");17 caps.setCapability("platformName", "Android");18 caps.setCapability("platformVersion", "7.1.1");19 caps.setCapability("appPackage", "com.android.calculator2");20 caps.setCapability("appActivity", "com.android.calculator2.Calculator");21 caps.setCapability("noReset", true);22 caps.setCapability("automationName", "UiAutomator2");

Full Screen

Full Screen

execute

Using AI Code Generation

copy

Full Screen

1AppiumDriver driver;2AppiumExecutionMethod execute = new AppiumExecutionMethod(driver);3execute.executeScript("javascript code");4AppiumDriver driver;5AppiumExecutionMethod execute = new AppiumExecutionMethod(driver);6execute.executeScript("javascript code");7AppiumDriver driver;8AppiumExecutionMethod execute = new AppiumExecutionMethod(driver);9execute.executeScript("javascript code");10AppiumDriver driver;11AppiumExecutionMethod execute = new AppiumExecutionMethod(driver);12execute.executeScript("javascript code");13AppiumDriver driver;14AppiumExecutionMethod execute = new AppiumExecutionMethod(driver);15execute.executeScript("javascript code");16AppiumDriver driver;17AppiumExecutionMethod execute = new AppiumExecutionMethod(driver);

Full Screen

Full Screen

execute

Using AI Code Generation

copy

Full Screen

1((AppiumDriver) driver).executeScript("javascript", "window.location.reload()");2((AppiumDriver) driver).executeScript("javascript", "window.location.reload()");3((AppiumDriver) driver).executeScript("javascript", "window.location.reload()");4((AppiumDriver) driver).executeScript("javascript", "window.location.reload()");5((AppiumDriver) driver).executeScript("javascript", "window.location.reload()");6((AppiumDriver) driver).executeScript("javascript", "window.location.reload()");7((AppiumDriver) driver).executeScript("javascript", "window.location.reload()");8((AppiumDriver) driver).executeScript("javascript", "window.location.reload()");9((AppiumDriver) driver).executeScript("javascript", "window.location.reload()");10((AppiumDriver) driver).executeScript("javascript", "window.location.reload()");11((AppiumDriver) driver).executeScript("javascript", "window.location.reload()");12((AppiumDriver) driver).executeScript("javascript", "window.location.reload()");

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.

Run io.appium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in AppiumExecutionMethod

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful