Best io.appium code snippet using io.appium.java_client.touch.WaitOptions
Mobile.java
Source:Mobile.java
...33import io.appium.java_client.android.nativekey.AndroidKey;34import io.appium.java_client.ios.IOSTouchAction;35import io.appium.java_client.touch.LongPressOptions;36import io.appium.java_client.touch.TapOptions;37import io.appium.java_client.touch.WaitOptions;38import io.appium.java_client.touch.offset.ElementOption;39import io.appium.java_client.touch.offset.PointOption;40import org.openqa.selenium.ScreenOrientation;41import org.openqa.selenium.WebElement;42import java.time.Duration;43import java.util.ArrayList;44import java.util.List;45//Update report logs. Scroll strategy etc.46/**47 * @author nauman.shahid48 * Handles mobile based libraries including Appium , Android and IOS49 */50public final class Mobile {51 private Android android;52 private IOS ios;53 int pressX, bottomY, topY;54 private MobileScrolls mobileScrolls;55 private Tap tap;56 private MobileAccessories mobileAccessories;57 public Mobile() {58 }59 /**60 * reach out android specific library and instance61 *62 * @return63 */64 public Android usingAndroidSpecials() {65 if ("android".equalsIgnoreCase(EnvironmentFactory.getDevice()))66 this.android = new Android();67 return android;68 }69 /**70 * reach out IOS specific library and instance71 *72 * @return73 */74 public IOS iosSpecials() {75 if ("ios".equalsIgnoreCase(EnvironmentFactory.getDevice()))76 this.ios = new IOS();77 return ios;78 }79 public MobileAccessories MobileAccessories() {80 if (mobileAccessories == null) mobileAccessories = new MobileAccessories();81 return mobileAccessories;82 }83 public Tap tap() {84 if (tap == null) tap = new Tap();85 return tap;86 }87 public MobileScrolls mobileScrolls() {88 if (mobileScrolls == null) mobileScrolls = new MobileScrolls();89 return mobileScrolls;90 }91 /**92 * Access mobile elements93 *94 * @param locator : xapth,name,id,accessiblityid,linktext,classname,css,tagname : String of locator95 * @return96 */97 public WebElement getMobileElement(MobileBy locator, Boolean processing) {98 return driver().findElement(locator);99 }100 /**101 * Access mobile elements102 *103 * @param locator : xapth,name,id,accessiblityid,linktext,classname,css,tagname : String of locator104 * @return105 */106 public List<WebElement> getMobileElements(MobileBy locator, Boolean processing) {107 return driver().findElements(locator);108 }109 @SuppressWarnings("unchecked") // If statement ensures unchecked cast is safe110 private AppiumDriver<WebElement> driver() {111 if (!"android".equalsIgnoreCase(EnvironmentFactory.getDevice())112 && !"ios".equalsIgnoreCase(EnvironmentFactory.getDevice())) {113 throw new TestingBlazeRunTimeException("In order to use 'Mobile' library, System parameter 'device' must be set to 'android' or 'ios'.\n" +114 "Parameter 'device' was found to be '" + EnvironmentFactory.getDevice() + "'");115 }116 return (AppiumDriver<WebElement>) InstanceRecording.getInstance(DeviceBucket.class).getDriver();117 }118 private TouchAction<?> touch() {119 if ("android".equalsIgnoreCase(EnvironmentFactory.getDevice())) {120 return new TouchAction<AndroidTouchAction>(driver());121 } else if ("ios".equalsIgnoreCase(EnvironmentFactory.getDevice())) {122 return new TouchAction<IOSTouchAction>(driver());123 } else {124 return new TouchAction<>(driver());125 }126 }127 private MultiTouchAction multiTouch() {128 return new MultiTouchAction(driver());129 }130 public class MobileAccessories {131 /**132 * @return current context133 */134 public String getCurrentContext() {135 //Console log Getting Current context of app ");136 return driver().getContext();137 }138 /**139 * @return array of contexts140 */141 public ArrayList<String> getContextHandlers() {142 //Console log Getting list of contexts of app ");143 return new ArrayList<String>(driver().getContextHandles());144 }145 /**146 * switch to a context147 *148 * @param context149 */150 public void switchContext(String context) {151 driver().context(context);152 }153 /**154 * close the current app155 */156 public void closeApp() {157 //Console log closing app");158 driver().closeApp();159 }160 /**161 * Device time162 *163 * @return164 */165 public String getDeviceTime() {166 //Console log Getting Current Device time");167 return driver().getDeviceTime();168 }169 /**170 * Get keyboard on mobile screen171 */172 public void showKeyboard() {173 //Console log Hidding keyboard from screen ");174 driver().getKeyboard();175 }176 /**177 * @return screen orientation library178 */179 public ScreenOrientation getScreenOrientation() {180 //Console log Fetching screen orinetation ");181 return driver().getOrientation();182 }183 /**184 * gives screen page source185 */186 public void getScreenSource() {187 //Console log Reading page source code ");188 driver().getPageSource();189 }190 /**191 * Hide keyboard from screen192 */193 public void hideKeyboard() {194 //Console log Hidding keyboard ");195 driver().hideKeyboard();196 }197 /**198 * Install any app on mobile199 *200 * @param path201 */202 public void installApp(String path) {203 //Console log Installing app from " + path);204 driver().installApp(path);205 }206 /**207 * boolean app is installed208 *209 * @param bundleId210 * @return true/false211 */212 public boolean isAppInstall(String bundleId) {213 return driver().isAppInstalled(bundleId);214 }215 /**216 * open the App217 */218 public void openApp() {219 //Console log Getting App launched ");220 driver().launchApp();221 }222 /**223 * run app in background224 *225 * @param seconds226 */227 public void runAppInBackGround(int seconds) {228 //Console log Enable app execution in background");229 driver().runAppInBackground(Duration.ofSeconds(seconds));230 }231 /**232 * change screen orientation to landscape233 */234 public void changeScreenOrientationToLandScape() {235 //Console log Chnaging screen resolution to Landscape");236 driver().rotate(ScreenOrientation.LANDSCAPE);237 }238 /**239 * change screen resolution to portrait240 */241 public void changeScreenOrientationToPortrait() {242 //Console log Chnaging screen resolution to Portrait");243 driver().rotate(ScreenOrientation.PORTRAIT);244 }245 public AndroidBatteryInfo androidBatteryInfo() {246 return usingAndroidSpecials().toGetBatteryInfo();247 }248 public void openAndroidNotifications() {249 usingAndroidSpecials().openNotifications();250 }251 }252 public class Tap {253 public void longPressElement(WebElement element, long seconds) {254 getScreenDimensions();255 touch().longPress(LongPressOptions.longPressOptions()256 .withElement(ElementOption.element(element)))257 .waitAction(WaitOptions.waitOptions(Duration.ofSeconds(seconds)))258 .release().perform();259 }260 /**261 * tap on specific element262 *263 * @param element264 */265 public void multipleTimesOnElement(WebElement element, int numberOfTaps) {266 try {267 //Console log Performing TAP on : " + element);268 } catch (Exception e) {269 //Console log Performing TAP on specific element");270 }271 touch().tap(TapOptions.tapOptions()272 .withElement(ElementOption.element(element))273 .withTapsCount(numberOfTaps))274 .release().perform();275 }276 /**277 * tap at specific axis278 *279 * @param xAxis280 * @param yAxis281 */282 public void onAxis(int xAxis, int yAxis) {283 //Console log Performing TAP on axis");284 touch().tap(TapOptions.tapOptions()285 .withPosition(PointOption.point(xAxis, yAxis)))286 .release().perform();287 }288 public void nativeAndroidKey(AndroidKey androidKey) {289 usingAndroidSpecials().toPressNativeKey(androidKey);290 }291 private void getScreenDimensions() {292 //Console log Fetching screen dimensions");293 pressX = driver().manage().window().getSize().width / 2;294 bottomY = driver().manage().window().getSize().height * 4 / 5;295 topY = driver().manage().window().getSize().height / 8;296 }297 }298 public class MobileScrolls {299 /**300 * Swipe from one element to other301 *302 * @param startElement303 * @param endElement304 */305 public void swipeByElements(WebElement startElement, WebElement endElement) {306 int startX = startElement.getLocation().getX() + (startElement.getSize().getWidth() / 2);307 int startY = startElement.getLocation().getY() + (startElement.getSize().getHeight() / 2);308 int endX = endElement.getLocation().getX() + (endElement.getSize().getWidth() / 2);309 int endY = endElement.getLocation().getY() + (endElement.getSize().getHeight() / 2);310 touch().press(PointOption.point(startX, startY))311 .waitAction(WaitOptions.waitOptions(Duration.ofMillis(500)))312 .moveTo(PointOption.point(endX, endY))313 .release().perform();314 }315 /**316 * scroll on the screen317 *318 * @param startX319 * @param startY320 * @param endX321 * @param endY322 * @param seconds323 */324 public void screen(int startX, int startY, int endX, int endY, long seconds) {325 //Console log Performing scroll action");326 touch().press(PointOption.point(startX, startY))327 .waitAction(WaitOptions.waitOptions(Duration.ofSeconds(seconds)))328 .moveTo(PointOption.point(endX, endY))329 .release().perform();330 }331 /**332 * scroll on the screen -IOS333 *334 * @param startX335 * @param startY336 * @param endX337 * @param endY338 * @param seconds339 */340 public void onIOS(int startX, int startY, int endX, int endY, long seconds) {341 //Console log Performing scroll action for IOS");342 touch().press(PointOption.point(startX, startY))343 .waitAction(WaitOptions.waitOptions(Duration.ofSeconds(seconds)))344 .moveTo(PointOption.point(endX - startX, endY - startY))345 .release().perform();346 }347 /**348 * swipe down till end349 */350 public void swipeDown() {351 //Console log Performing swipte down");352 getScreenDimensions();353 touch().press(PointOption.point(pressX, bottomY))354 .waitAction(WaitOptions.waitOptions(Duration.ofMillis(500)))355 .moveTo(PointOption.point(pressX, topY))356 .release().perform();357 }358 /**359 * scroll down to a specific element360 *361 * @param element362 */363 public void downToElement(WebElement element) {364 try {365 //Console log Performing scroll to specific element : " + element);366 } catch (Exception e) {367 //Console log Performing scroll to a specific element");368 }369 getScreenDimensions();370 touch().press(PointOption.point(pressX, bottomY))371 .waitAction(WaitOptions.waitOptions(Duration.ofMillis(500)))372 .moveTo(ElementOption.element(element))373 .release().perform();374 }375 public void usingAndroidResourceID(String resourceId) {376 usingAndroidSpecials().toScrollUsingResourceID(resourceId);377 }378 public void usingAndroidText(String text) {379 usingAndroidSpecials().toScrollUsingText(text);380 }381 public void usingAndroidContentContains(String contentContains) {382 usingAndroidSpecials().toSpecialScrollToContentContains(contentContains);383 }384 private void getScreenDimensions() {385 //Console log Fetching screen dimensions");...
AppiumTest3.java
Source:AppiumTest3.java
...23import io.appium.java_client.service.local.AppiumServiceBuilder;24import io.appium.java_client.service.local.flags.GeneralServerFlag;25import io.appium.java_client.touch.LongPressOptions;26import io.appium.java_client.touch.TapOptions;27import io.appium.java_client.touch.WaitOptions;28import io.appium.java_client.touch.offset.ElementOption;29import io.appium.java_client.touch.offset.PointOption;30import static io.appium.java_client.touch.LongPressOptions.longPressOptions;31public class AppiumTest3 {32 public static void main(String[] args) throws MalformedURLException, InterruptedException {33 // TODO Auto-generated method stub34 35 36 37 AppiumDriverLocalService service = AppiumDriverLocalService.buildService(new AppiumServiceBuilder()38 .usingDriverExecutable(new File("C:\\Program Files\\nodejs\\node.exe"))39 .withAppiumJS(new File("C:\\Users\\Sanjay\\AppData\\Local\\Programs\\Appium\\resources\\app\\node_modules\\appium\\build\\lib\\main.js"))40 .withLogFile(new File("C:\\Users\\Sanjay\\Appium\\eclipse-workspace\\AppiumTest1\\src\\test\\resources\\Logs\\AppiumLogs\\Logs.log"))41 .withArgument(GeneralServerFlag.LOCAL_TIMEZONE));42 43 service.start();44 45 DesiredCapabilities dc = new DesiredCapabilities();46 dc.setCapability("deviceName","65f651f31e00");47 dc.setCapability("platformName","Android");48 dc.setCapability("automationName", "UiAutomator2");49 dc.setCapability("appPackage","in.amazon.mShop.android.shopping");50 dc.setCapability("appActivity","com.amazon.mShop.home.HomeActivity");51 52 //AppiumDriver<AndroidElement> driver = new AppiumDriver<AndroidElement>(new URL("https://137.0.0.1:4723/wd/hub"),dc);53 AndroidDriver<AndroidElement> driver = new AndroidDriver<AndroidElement>(new URL("http://127.0.0.1:4723/wd/hub"),dc);54 55 56 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);57 driver.findElement(By.xpath("//android.widget.ImageView[@content-desc=\"Continue in English\"]")).click();58 driver.findElement(By.id("in.amazon.mShop.android.shopping:id/skip_sign_in_button")).click();;59 driver.findElement(By.id("in.amazon.mShop.android.shopping:id/rs_search_src_text")).sendKeys("Mobile");60 driver.findElement(By.id("in.amazon.mShop.android.shopping:id/search_right_cam_img")).click();61 62 driver.pressKey(new KeyEvent(AndroidKey.BACK));63 64 65 66 driver.findElement(By.id("in.amazon.mShop.android.shopping:id/rs_search_src_text")).click();67 Actions action = new Actions(driver);68 action.sendKeys("Mobile Phones").perform();69 70 driver.pressKey(new KeyEvent(AndroidKey.BACK));71 Thread.sleep(2000);72 73 //Using Mobile By74 driver.findElement(MobileBy.id("in.amazon.mShop.android.shopping:id/glow_subnav_label")).click();75 driver.pressKey(new KeyEvent(AndroidKey.BACK));76 77 78 79 AndroidElement element= driver.findElement(By.xpath("//android.view.View[@content-desc='Fresh Fresh']"));80 System.out.println(element.getAttribute("enabled"));81 element.click();82 Thread.sleep(3000);83 driver.quit();84 85 86 dc.setCapability("appPackage","com.google.android.dialer");87 dc.setCapability("appActivity","com.google.android.dialer.extensions.GoogleDialtactsActivity");88 driver = new AndroidDriver<AndroidElement>(new URL("http://127.0.0.1:4723/wd/hub"),dc);89 90 Thread.sleep(1000);91 driver.findElement(By.id("com.google.android.dialer:id/dialpad_fab")).click();92 Thread.sleep(1000);93 94 //AndroidElement dialerFrame = driver.findElement(By.className("android.widget.FrameLayout"));95 String phoneNumber ="9790594970";96 String[] numbersText = {"zero","one","two","three","four","five","six","seven","eight","nine"};97 98 99 for(int i=0;i<=9;i++)100 {101 102 char digit = phoneNumber.charAt(i);103 int digitInt = Integer.parseInt(Character.toString(digit));104 System.out.println("com.google.android.dialer:id/"+numbersText[digitInt]);105 driver.findElement(By.id("com.google.android.dialer:id/"+numbersText[digitInt])).click();106 Thread.sleep(500);107 108 }109 110 //click Call button111 //driver.findElement(By.id("com.google.android.dialer:id/dialpad_voice_call_button")).click();112 113 AndroidElement clearDiallerDigits = driver.findElement(By.id("com.google.android.dialer:id/deleteButton"));114 115 AndroidTouchAction touchAction = new AndroidTouchAction(driver);116 touchAction.press( ElementOption.element(clearDiallerDigits)).waitAction(WaitOptions.waitOptions(Duration.ofSeconds(2))).moveTo(ElementOption.element(element));117 118 119 120 touchAction.longPress(LongPressOptions.longPressOptions().withElement(ElementOption.element(clearDiallerDigits)))121 .waitAction(WaitOptions.waitOptions(Duration.ofSeconds(2))).release().perform();122 123 /*124 125 AndroidTouchAction touchAction2 = new AndroidTouchAction(driver)126 .longPress(LongPressOptions.longPressOptions().withElement(ElementOption.element(clearDiallerDigits)))127 .waitAction(WaitOptions.waitOptions(Duration.ofSeconds(1))).perform();128 129 */130 131 AndroidElement diapPadView = driver.findElement(By.id("com.google.android.dialer:id/dialpad_view"));132 for(int i=0;i<=9;i++)133 {134 135 char digit = phoneNumber.charAt(i);136 int digitInt = Integer.parseInt(Character.toString(digit));137 System.out.println("com.google.android.dialer:id/"+numbersText[digitInt]);138 diapPadView.findElement(By.id("com.google.android.dialer:id/"+numbersText[digitInt])).click();139 Thread.sleep(500);140 141 }...
TouchActionUtils.java
Source:TouchActionUtils.java
1package stepdefinitions;2import static stepdefinitions.InitializeTest.driver;3import static io.appium.java_client.touch.TapOptions.tapOptions;4import static io.appium.java_client.touch.WaitOptions.waitOptions;5import static io.appium.java_client.touch.offset.ElementOption.element;6import static io.appium.java_client.touch.offset.PointOption.point;7import static java.time.Duration.ofMillis;8import static java.time.Duration.ofSeconds;9import io.appium.java_client.MobileElement;10import io.appium.java_client.MultiTouchAction;11import io.appium.java_client.TouchAction;12import java.time.Duration;13import org.openqa.selenium.Dimension;14public class TouchActionUtils {15 //Tap to an element for 250 milliseconds16 public void tapByElement(MobileElement mobileElement) {17 new TouchAction(driver)18 .tap(tapOptions().withElement(element(mobileElement)))...
BaseAction.java
Source:BaseAction.java
...11import io.appium.java_client.android.AndroidDriver;12import io.appium.java_client.android.AndroidElement;13import io.appium.java_client.android.AndroidTouchAction;14import io.appium.java_client.touch.LongPressOptions;15import io.appium.java_client.touch.WaitOptions;16import io.appium.java_client.touch.offset.ElementOption;17import io.appium.java_client.touch.offset.PointOption;18public class BaseAction {19 public AndroidDriver<AndroidElement> driver;20 public AndroidTouchAction action;21 public BaseAction(AndroidDriver<AndroidElement> driver) {22 this.driver = driver;23 action = new AndroidTouchAction(driver);24 }25 public void click(By by) {26 driver.findElement(by).click();27 }28 public void click(WebElement elemnet) {29 elemnet.click();30 }31 public void claer(WebElement element) {32 element.clear();33 }34 public void type(By by, String value) {35 driver.findElement(by).clear();36 driver.findElement(by).sendKeys(value);37 }38 public void type(WebElement element, String context) {39 element.sendKeys(context);40 }41 // ³¤°´42 public void longPress(WebElement element) {43 LongPressOptions longPressOptions = LongPressOptions.longPressOptions();44 longPressOptions.withElement(ElementOption.element(element));45 action.longPress(longPressOptions).release().perform();46 }47 // ×ø±êµãµÄ»¬¶¯48 public void swip(PointOption fromOption, PointOption toOption) {49 action.press(fromOption).waitAction(WaitOptions.waitOptions(Duration.ofSeconds(1))).moveTo(toOption)50 .waitAction(WaitOptions.waitOptions(Duration.ofSeconds(1))).release().perform();51 }52 // ÔªËؼäµÄ»¬¶¯53 public void swip(WebElement fromEle, WebElement toEle) {54 PointOption fromOption = PointOption.point(fromEle.getLocation().getX(), fromEle.getLocation().getY());55 PointOption toOption = PointOption.point(toEle.getLocation().getX(), toEle.getLocation().getY());56 swip(fromOption, toOption);57 }58 public void DragAndSwip(AndroidElement element) {59 LongPressOptions longPressOptions = LongPressOptions.longPressOptions();60 longPressOptions.withElement(ElementOption.element(element));61 action.longPress(longPressOptions).waitAction(WaitOptions.waitOptions(Duration.ofSeconds(1)))62 .moveTo(PointOption.point(100, element.getLocation().getY()))63 .waitAction(WaitOptions.waitOptions(Duration.ofSeconds(1))).release().perform();64 }65 public void multiTouch(int x1, int y1, int x2, int y2, int x3, int y3) {66 MultiTouchAction multiAction = new MultiTouchAction(driver);67 AndroidTouchAction action1 = new AndroidTouchAction(driver);68 AndroidTouchAction action2 = new AndroidTouchAction(driver);69 AndroidTouchAction action3 = new AndroidTouchAction(driver);70 AndroidTouchAction action4 = new AndroidTouchAction(driver);71 AndroidTouchAction action5 = new AndroidTouchAction(driver);72 action1.longPress(PointOption.point(x1, y1)).waitAction(WaitOptions.waitOptions(Duration.ofSeconds(1)))73 .release();74 action2.longPress(PointOption.point(x2, y2)).waitAction(WaitOptions.waitOptions(Duration.ofSeconds(1)))75 .release();76 action3.longPress(PointOption.point(x3, y3)).waitAction(WaitOptions.waitOptions(Duration.ofSeconds(1)))77 .release();78 multiAction.add(action1).add(action2).add(action3).add(action4).add(action5).perform();79 }80 81 public String getToast() {82 return driver.findElementByXPath("//*[@class='android.widget.Toast']").getText();83 }84}...
BasePage.java
Source:BasePage.java
...5import io.appium.java_client.MobileBy;6import io.appium.java_client.TouchAction;7import io.appium.java_client.android.AndroidDriver;8import io.appium.java_client.pagefactory.AppiumFieldDecorator;9import io.appium.java_client.touch.WaitOptions;10import io.appium.java_client.touch.offset.ElementOption;11import io.appium.java_client.touch.offset.PointOption;12import org.openqa.selenium.*;13import org.openqa.selenium.interactions.touch.TouchActions;14import org.openqa.selenium.remote.RemoteWebElement;15import org.openqa.selenium.support.PageFactory;16import org.openqa.selenium.support.ui.ExpectedConditions;17import org.openqa.selenium.support.ui.WebDriverWait;18import java.time.Duration;19import java.util.HashMap;20import static io.appium.java_client.touch.WaitOptions.waitOptions;21public class BasePage extends Test_Base {22 private static final int KEYBOARD_ANIMATION_DELAY = 1000;23 private static final int XML_REFRESH_DELAY = 1000;24 public static final String app_package = env + ":id/";25 protected final AppiumDriver driver;26 private WebElement element;27 protected BasePage(AppiumDriver driver) {28 this.driver = driver;29 // PageFactory.initElements(new AppiumFieldDecorator(driver, 120, TimeUnit.SECONDS), this);30 PageFactory.initElements(new AppiumFieldDecorator(driver, Duration.ofSeconds(120)), this);31 }32 public WebElement scroll_text_contains(String text) {33 return driver.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true)).scrollIntoView(new UiSelector().textContains(\"" + text + "\"));"));34 }35 public WebElement verify_text(String Text) {36 return driver.findElement(MobileBy.xpath("//android.widget.TextView[@text =" + "\"" + Text + "\"]"));37 }38 public void touchActionPointer() {39 int heightOfScreen = driver.manage().window().getSize().getHeight();40 int widthOfScreen = driver.manage().window().getSize().getWidth();41 int x = (int) (widthOfScreen * 0.115);42 // System.out.println(x);43 int y = (int) (heightOfScreen * 0.92);44 // System.out.println(y);45 int end_x = (int) (widthOfScreen * 0.916);46 // System.out.println(end_x);47 int end_y = y;48 TouchAction action = new TouchAction(driver);49 action.press(PointOption.point(x, y))50 .waitAction(waitOptions(Duration.ofMillis(800)))51 .moveTo(PointOption.point(end_x, end_y))52 .release()53 .perform();54 }55 public void swipetobottom(int n) {56 Dimension size = driver.manage().window().getSize();57 TouchAction action = new TouchAction(driver);58 int startX = size.width / 2;59 int startY = (int) (size.height * 0.5);60 int endY = (int) (size.width * 0.2);61 for (int i = 1; i <= n; i++) {62 action.press(PointOption.point(startX, startY)).waitAction(WaitOptions.waitOptions(Duration.ofMillis(1000)))63 .moveTo(PointOption.point(startX, endY)).release().perform();64 }65 }66}...
EnrollmentID.java
Source:EnrollmentID.java
2import io.appium.java_client.android.AndroidDriver;3import io.appium.java_client.android.AndroidTouchAction;4import io.appium.java_client.remote.AndroidMobileCapabilityType;5import io.appium.java_client.remote.MobileCapabilityType;6import io.appium.java_client.touch.WaitOptions;7import io.appium.java_client.touch.offset.PointOption;8import org.openqa.selenium.By;9import org.openqa.selenium.remote.DesiredCapabilities;10import org.testng.annotations.BeforeTest;11import org.testng.annotations.Test;12import java.net.URL;13import java.time.Duration;14import java.util.concurrent.TimeUnit;15public class EnrollmentID {16 private static final String App = "C://Users//pmalviya//Downloads//snappqa_3_2_0_Dev_Build_1502.apk";17 private static final String AppiumServerUrl = "http://localhost:4723/wd/hub";18 private AndroidDriver driver;19 private AndroidTouchAction touchAction;20 @BeforeTest21 public void SetUP() throws Exception {22 DesiredCapabilities dc = new DesiredCapabilities();23 dc.setCapability(MobileCapabilityType.APP,App);24 dc.setCapability(MobileCapabilityType.FULL_RESET, true);25 dc.setCapability(MobileCapabilityType.NO_RESET, false);26 dc.setCapability(MobileCapabilityType.UDID, "emulator-5554");27 dc.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "net.soti.snap");28 dc.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, ".ui.activities.SplashActivity");29 driver = new AndroidDriver<>(new URL(AppiumServerUrl), dc);30 driver.manage().timeouts().implicitlyWait(5000, TimeUnit.SECONDS);31 Thread.sleep(2000);32 }33 @Test(priority = 0)34 public void SwipeLandingPage() {35 touchAction = new AndroidTouchAction(driver);36 touchAction.press(PointOption.point(824, 1080)).waitAction(WaitOptions.waitOptions(Duration.ofMillis(536))).moveTo(PointOption.point(63, 1080)).release().perform();37 touchAction.press(PointOption.point(957, 1080)).waitAction(WaitOptions.waitOptions(Duration.ofMillis(536))).moveTo(PointOption.point(63, 993)).release().perform();38 touchAction.press(PointOption.point(948, 1100)).waitAction(WaitOptions.waitOptions(Duration.ofMillis(536))).moveTo(PointOption.point(63, 993)).release().perform();39 touchAction.press(PointOption.point(957, 1100)).waitAction(WaitOptions.waitOptions(Duration.ofMillis(536))).moveTo(PointOption.point(63, 993)).release().perform();40 }41 @Test (priority = 1)42 public void EnrollDevice() {43 driver.findElement(By.id("input_user_name")).sendKeys("10AF86332E");44 driver.findElement(By.id("layout_continue_Button")).click();45 }46 @Test(priority = 2)47 public void UnEnrollDevice()48 {49 driver.findElement(By.id("more")).click();50 driver.findElement(By.xpath("//*[@text='Manage Channels']")).click();51 driver.findElement(By.id("deleteTenantButton")).click();52 driver.findElement(By.id("text_button_positive")).click();53 }...
commonbase.java
Source:commonbase.java
1package base;2import static io.appium.java_client.touch.TapOptions.tapOptions;3import static io.appium.java_client.touch.WaitOptions.waitOptions;4import static io.appium.java_client.touch.offset.ElementOption.element;5import static io.appium.java_client.touch.offset.PointOption.point;6import static java.time.Duration.ofMillis;7import org.openqa.selenium.Dimension;8import org.openqa.selenium.support.PageFactory;9import io.appium.java_client.AppiumDriver;10import io.appium.java_client.MobileElement;11import io.appium.java_client.TouchAction;12import io.appium.java_client.pagefactory.AppiumFieldDecorator;13/////////14/////////////////////////////////////15// common tap & swipe functionality for the screens16////////////////////17public class commonbase {...
BaseFactory.java
Source:BaseFactory.java
1package factories;2import io.appium.java_client.TouchAction;3import io.appium.java_client.android.AndroidDriver;4import io.appium.java_client.touch.WaitOptions;5import io.appium.java_client.touch.offset.PointOption;6import org.openqa.selenium.Dimension;7import pages.BasePage;8import java.time.Duration;9import static constants.Constants.DIRECTION_NAME_DOWN;10public class BaseFactory extends BasePage {11 public void navigateBack(AndroidDriver driver) {12 driver.navigate().back();13 }14 public void navigateForward(AndroidDriver driver) {15 driver.navigate().forward();16 }17 public void closeApp(AndroidDriver driver) {18 driver.closeApp();19 }20 public void scroll(String direction, int times, AndroidDriver driver) {21 if (direction.equals(DIRECTION_NAME_DOWN)) {22 Dimension dimension = driver.manage().window().getSize();23 int width = dimension.getWidth() / 2;24 for (int i = 0; i < times; i++) {25 int startY = (int) (dimension.getHeight() * 0.7);26 int endY = (int) (dimension.getHeight() * 0.5);27 new TouchAction(driver).press(PointOption.point(width, startY)).waitAction(WaitOptions.waitOptions(Duration.ofSeconds(1))).moveTo(PointOption.point(width, endY)).release().perform();28 }29 } else {30 Dimension dimension = driver.manage().window().getSize();31 int width = dimension.getWidth() / 2;32 for (int i = 0; i < times; i++) {33 int startY = (int) (dimension.getHeight() * 0.7);34 int endY = (int) (dimension.getHeight() * 0.5);35 new TouchAction(driver).press(PointOption.point(width, endY)).waitAction(WaitOptions.waitOptions(Duration.ofSeconds(1))).moveTo(PointOption.point(width, startY)).release().perform();36 }37 }38 }39 public void sleepTheThread(long milisec) {40 try {41 Thread.sleep(milisec);42 } catch (InterruptedException e) {43 e.printStackTrace();44 }45 }46}...
WaitOptions
Using AI Code Generation
1TouchAction touchAction = new TouchAction(driver);2touchAction.press(PointOption.point(100, 200)).waitAction(WaitOptions.waitOptions(Duration.ofSeconds(2))).moveTo(PointOption.point(100, 400)).release().perform();3TouchAction touchAction = new TouchAction(driver);4touchAction.press(PointOption.point(100, 200)).waitAction(WaitOptions.waitOptions(Duration.ofSeconds(2))).moveTo(PointOption.point(100, 400)).release().perform();5TouchAction touchAction = new TouchAction(driver);6touchAction.press(PointOption.point(100, 200)).waitAction(WaitOptions.waitOptions(Duration.ofSeconds(2))).moveTo(PointOption.point(100, 400)).release().perform();7TouchAction touchAction = new TouchAction(driver);8touchAction.press(PointOption.point(100, 200)).waitAction(WaitOptions.waitOptions(Duration.ofSeconds(2))).moveTo(PointOption.point(100, 400)).release().perform();9TouchAction touchAction = new TouchAction(driver);10touchAction.press(PointOption.point(100, 200)).waitAction(WaitOptions.waitOptions(Duration.ofSeconds(2))).moveTo(PointOption.point(100, 400)).release().perform();11TouchAction touchAction = new TouchAction(driver);12touchAction.press(PointOption.point(100, 200)).waitAction(WaitOptions.waitOptions(Duration.ofSeconds(2))).moveTo(PointOption.point(100, 400)).release().perform();13TouchAction touchAction = new TouchAction(driver);14touchAction.press(PointOption.point(100, 200)).waitAction(WaitOptions.waitOptions(Duration.ofSeconds(2))).moveTo(PointOption.point(100, 400)).release().perform();
WaitOptions
Using AI Code Generation
1import static io.appium.java_client.touch.WaitOptions.waitOptions;2import static io.appium.java_client.touch.offset.PointOption.point;3import static java.time.Duration.ofSeconds;4import java.time.Duration;5import org.openqa.selenium.By;6import org.openqa.selenium.WebElement;7import io.appium.java_client.android.AndroidDriver;8import io.appium.java_client.android.AndroidElement;9import io.appium.java_client.touch.TapOptions;10import io.appium.java_client.touch.offset.PointOption;11import io.appium.java_client.touch.WaitOptions;12public class SwipeDemo extends Base {13 public static void main(String[] args) throws Exception {14 AndroidDriver<AndroidElement> driver = capabilities();15 driver.findElementByAndroidUIAutomator("text(\"Views\")").click();16 driver.findElementByAndroidUIAutomator("text(\"Date Widgets\")").click();17 driver.findElementByAndroidUIAutomator("text(\"2. Inline\")").click();18 driver.findElementByAndroidUIAutomator("text(\"9\")").click();19 driver.findElementByAndroidUIAutomator("text(\"15\")").click();20 driver.findElementByAndroidUIAutomator("text(\"45\")").click();21 driver.findElementByAndroidUIAutomator("text(\"2\")").click();22 driver.findElementByAndroidUIAutomator("text(\"OK\")").click();23 }24}25package appium;26import java.io.File;27import java.net.MalformedURLException;28import java.net.URL;29import java.util.concurrent.TimeUnit;30import org.openqa.selenium.remote.DesiredCapabilities;31import io.appium.java_client.android.AndroidDriver;32import io.appium.java_client.android.AndroidElement;33import io.appium.java_client.remote.MobileCapabilityType;34public class Base {35 public static AndroidDriver<AndroidElement> capabilities() throws MalformedURLException {36 AndroidDriver<AndroidElement> driver;37 File f = new File("src");38 File fs = new File(f, "ApiDemos-debug.apk");39 DesiredCapabilities cap = new DesiredCapabilities();40 cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Device");41 cap.setCapability(MobileCapabilityType.APP, fs.getAbsolutePath());
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!!