Best io.appium code snippet using io.appium.java_client.touch.ActionOptions.build
TouchAction.java
Source:TouchAction.java
...14 * limitations under the License.15 */16package io.appium.java_client;17import static com.google.common.base.Preconditions.checkNotNull;18import static com.google.common.collect.ImmutableList.builder;19import static java.util.stream.Collectors.toList;20import com.google.common.collect.ImmutableList;21import com.google.common.collect.ImmutableMap;22import io.appium.java_client.touch.ActionOptions;23import io.appium.java_client.touch.LongPressOptions;24import io.appium.java_client.touch.TapOptions;25import io.appium.java_client.touch.WaitOptions;26import io.appium.java_client.touch.offset.ElementOption;27import io.appium.java_client.touch.offset.PointOption;28import java.util.List;29import java.util.Map;30/**31 * Used for Webdriver 3 touch actions32 * See the Webriver 3 spec33 * https://dvcs.w3.org/hg/webdriver/raw-file/default/webdriver-spec.html34 * The flow is to chain individual touch actions into an entire gesture. e.g.35 * TouchAction action = new TouchAction(performsTouchActions);36 * action.press(element).waitAction(300).moveTo(element1).release().perform();37 * Calling perform() sends the action command to the Mobile Driver. Otherwise,38 * more and more actions can be chained.39 */40public class TouchAction<T extends TouchAction<T>> implements PerformsActions<T> {41 protected ImmutableList.Builder<ActionParameter> parameterBuilder;42 private PerformsTouchActions performsTouchActions;43 public TouchAction(PerformsTouchActions performsTouchActions) {44 this.performsTouchActions = checkNotNull(performsTouchActions);45 parameterBuilder = builder();46 }47 /**48 * Press action on the screen.49 *50 * @param pressOptions see {@link PointOption} and {@link ElementOption}.51 * @return this TouchAction, for chaining.52 */53 public T press(PointOption pressOptions) {54 parameterBuilder.add(new ActionParameter("press", pressOptions));55 //noinspection unchecked56 return (T) this;57 }58 /**59 * Remove the current touching implement from the screen (withdraw your touch).60 *61 * @return this TouchAction, for chaining.62 */63 public T release() {64 ActionParameter action = new ActionParameter("release");65 parameterBuilder.add(action);66 //noinspection unchecked67 return (T) this;68 }69 /**70 * Moves current touch to a new position.71 *72 * @param moveToOptions see {@link PointOption} and {@link ElementOption}73 * Important: some older Appium drivers releases have a bug when moveTo74 * coordinates are calculated as relative to the recent pointer position75 * in the chain instead of being absolute.76 * @see <a href="https://github.com/appium/appium/issues/7486">Appium Issue #748677 * for more details.</a>78 * @return this TouchAction, for chaining.79 */80 public T moveTo(PointOption moveToOptions) {81 ActionParameter action = new ActionParameter("moveTo", moveToOptions);82 parameterBuilder.add(action);83 return (T) this;84 }85 /**86 * Tap on an element.87 *88 * @param tapOptions see {@link TapOptions}.89 * @return this TouchAction, for chaining.90 */91 public T tap(TapOptions tapOptions) {92 ActionParameter action = new ActionParameter("tap", tapOptions);93 parameterBuilder.add(action);94 return (T) this;95 }96 /**97 * Tap on a position.98 *99 * @param tapOptions see {@link PointOption} and {@link ElementOption}100 * @return this TouchAction, for chaining.101 */102 public T tap(PointOption tapOptions) {103 ActionParameter action = new ActionParameter("tap", tapOptions);104 parameterBuilder.add(action);105 return (T) this;106 }107 /**108 * A wait action, used as a NOP in multi-chaining.109 *110 * @return this TouchAction, for chaining.111 */112 public T waitAction() {113 ActionParameter action = new ActionParameter("wait");114 parameterBuilder.add(action);115 //noinspection unchecked116 return (T) this;117 }118 /**119 * Waits for specified amount of time to pass before continue to next touch action.120 *121 * @param waitOptions see {@link WaitOptions}.122 * @return this TouchAction, for chaining.123 */124 public T waitAction(WaitOptions waitOptions) {125 ActionParameter action = new ActionParameter("wait", waitOptions);126 parameterBuilder.add(action);127 //noinspection unchecked128 return (T) this;129 }130 /**131 * Press and hold the at the center of an element until the context menu event has fired.132 *133 * @param longPressOptions see {@link LongPressOptions}.134 * @return this TouchAction, for chaining.135 */136 public T longPress(LongPressOptions longPressOptions) {137 ActionParameter action = new ActionParameter("longPress", longPressOptions);138 parameterBuilder.add(action);139 //noinspection unchecked140 return (T) this;141 }142 /**143 * Press and hold the at the center of an element until the context menu event has fired.144 *145 * @param longPressOptions see {@link PointOption} and {@link ElementOption}.146 * @return this TouchAction, for chaining.147 */148 public T longPress(PointOption longPressOptions) {149 ActionParameter action = new ActionParameter("longPress", longPressOptions);150 parameterBuilder.add(action);151 //noinspection unchecked152 return (T) this;153 }154 /**155 * Cancel this action, if it was partially completed by the performsTouchActions.156 */157 public void cancel() {158 ActionParameter action = new ActionParameter("cancel");159 parameterBuilder.add(action);160 this.perform();161 }162 /**163 * Perform this chain of actions on the performsTouchActions.164 *165 * @return this TouchAction, for possible segmented-touches.166 */167 public T perform() {168 performsTouchActions.performTouchAction(this);169 //noinspection unchecked170 return (T) this;171 }172 /**173 * Get the mjsonwp parameters for this Action.174 *175 * @return A map of parameters for this touch action to pass as part of mjsonwp.176 */177 protected Map<String, List<Object>> getParameters() {178 List<ActionParameter> actionList = parameterBuilder.build();179 return ImmutableMap.of("actions", actionList.stream()180 .map(ActionParameter::getParameterMap).collect(toList()));181 }182 /**183 * Clears all the existing action parameters and resets the instance to the initial state.184 *185 * @return this TouchAction, for possible segmented-touches.186 */187 protected T clearParameters() {188 parameterBuilder = builder();189 //noinspection unchecked190 return (T) this;191 }192 /**193 * Just holds values to eventually return the parameters required for the mjsonwp.194 */195 protected class ActionParameter {196 private String actionName;197 private ImmutableMap.Builder<String, Object> optionsBuilder;198 public ActionParameter(String actionName) {199 this.actionName = actionName;200 optionsBuilder = ImmutableMap.builder();201 }202 public ActionParameter(String actionName, ActionOptions opts) {203 checkNotNull(opts);204 this.actionName = actionName;205 optionsBuilder = ImmutableMap.builder();206 //noinspection unchecked207 optionsBuilder.putAll(opts.build());208 }209 public ImmutableMap<String, Object> getParameterMap() {210 ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();211 builder.put("action", actionName).put("options", optionsBuilder.build());212 return builder.build();213 }214 }215}...
PointOption.java
Source:PointOption.java
...55 ofNullable(coordinates).orElseThrow(() -> new IllegalArgumentException(56 "Coordinate values must be defined"));57 }58 @Override59 public Map<String, Object> build() {60 final Map<String, Object> result = super.build();61 result.put("x", coordinates.x);62 result.put("y", coordinates.y);63 return result;64 }65}...
AbstractOptionCombinedWithPosition.java
Source:AbstractOptionCombinedWithPosition.java
...33 new IllegalArgumentException("Some coordinates or an offset from an element should "34 + "be defined. Use withPosition or withElement methods"));35 }36 @Override37 public Map<String, Object> build() {38 final Map<String, Object> result = super.build();39 result.putAll(positionOption.build());40 return result;41 }42}...
ActionOptions.java
Source:ActionOptions.java
...17import java.util.HashMap;18import java.util.Map;19public abstract class ActionOptions<T extends ActionOptions<T>> {20 /**21 * This method is automatically called before building22 * options map to verify the consistency of the instance.23 *24 * @throws IllegalArgumentException if there are problems with this options map.25 */26 protected abstract void verify();27 /**28 * Creates a map based on the provided options.29 *30 * @return options mapping.31 */32 public Map<String, Object> build() {33 verify();34 return new HashMap<>();35 }36}...
build
Using AI Code Generation
1TouchAction action = new TouchAction(driver);2action.press(PointOption.point(100, 200)).moveTo(PointOption.point(100, 400)).release().perform();3TouchAction action = new TouchAction(driver);4action.press(PointOption.point(100, 200)).moveTo(PointOption.point(100, 400)).release().perform();5TouchAction action = new TouchAction(driver);6action.press(PointOption.point(100, 200)).moveTo(PointOption.point(100, 400)).release().perform();7TouchAction action = new TouchAction(driver);8action.press(PointOption.point(100, 200)).moveTo(PointOption.point(100, 400)).release().perform();9TouchAction action = new TouchAction(driver);10action.press(PointOption.point(100, 200)).moveTo(PointOption.point(100, 400)).release().perform();11TouchAction action = new TouchAction(driver);12action.press(PointOption.point(100, 200)).moveTo(PointOption.point(100, 400)).release().perform();13TouchAction action = new TouchAction(driver);14action.press(PointOption.point(100, 200)).moveTo(PointOption.point(100, 400)).release().perform();15TouchAction action = new TouchAction(driver);16action.press(PointOption.point(100, 200)).moveTo(PointOption.point(100, 400)).release().perform();17TouchAction action = new TouchAction(driver);18action.press(PointOption.point(100,
build
Using AI Code Generation
1TouchAction touchAction = new TouchAction(driver);2touchAction.press(PointOption.point(100, 200)).moveTo(PointOption.point(200, 300)).release().perform();3TouchAction touchAction = new TouchAction(driver);4touchAction.press(PointOption.point(100, 200)).moveTo(PointOption.point(200, 300)).release().perform();5TouchAction touchAction = new TouchAction(driver);6touchAction.press(PointOption.point(100, 200)).moveTo(PointOption.point(200, 300)).release().perform();7TouchAction touchAction = new TouchAction(driver);8touchAction.press(PointOption.point(100, 200)).moveTo(PointOption.point(200, 300)).release().perform();9TouchAction touchAction = new TouchAction(driver);10touchAction.press(PointOption.point(100, 200)).moveTo(PointOption.point(200, 300)).release().perform();11TouchAction touchAction = new TouchAction(driver);12touchAction.press(PointOption.point(100, 200)).moveTo(PointOption.point(200, 300)).release().perform();13TouchAction touchAction = new TouchAction(driver);14touchAction.press(PointOption.point(100, 200)).moveTo(PointOption.point(200, 300)).release().perform();15TouchAction touchAction = new TouchAction(driver);16touchAction.press(PointOption.point(100, 200)).moveTo(PointOption.point(200, 300)).release().perform();17TouchAction touchAction = new TouchAction(driver
build
Using AI Code Generation
1TouchAction touchAction = new TouchAction(driver);2touchAction.press(PointOption.point(500, 500)).waitAction(WaitOptions.waitOptions(Duration.ofMillis(1000))).moveTo(PointOption.point(500, 0)).release().perform();3TouchAction touchAction = new TouchAction(driver);4touchAction.press(PointOption.point(500, 500)).waitAction(WaitOptions.waitOptions(Duration.ofMillis(1000))).moveTo(PointOption.point(500, 0)).release().perform();5TouchAction touchAction = new TouchAction(driver);6touchAction.press(PointOption.point(500, 500)).waitAction(WaitOptions.waitOptions(Duration.ofMillis(1000))).moveTo(PointOption.point(500, 0)).release().perform();7TouchAction touchAction = new TouchAction(driver);8touchAction.press(PointOption.point(500, 500)).waitAction(WaitOptions.waitOptions(Duration.ofMillis(1000))).moveTo(PointOption.point(500, 0)).release().perform();9TouchAction touchAction = new TouchAction(driver);10touchAction.press(PointOption
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!!