Best io.appium code snippet using io.appium.java_client.InteractsWithApps
WebDriverWrapper.java
Source:WebDriverWrapper.java
...35import io.appium.java_client.HasDeviceTime;36import io.appium.java_client.HasSessionDetails;37import io.appium.java_client.HidesKeyboard;38import io.appium.java_client.HidesKeyboardWithKeyName;39import io.appium.java_client.InteractsWithApps;40import io.appium.java_client.InteractsWithFiles;41import io.appium.java_client.MobileDriver;42import io.appium.java_client.MultiTouchAction;43import io.appium.java_client.PerformsActions;44import io.appium.java_client.PerformsTouchActions;45import io.appium.java_client.PressesKeyCode;46import io.appium.java_client.TouchAction;47import io.appium.java_client.android.AndroidDriver;48import io.appium.java_client.android.Connection;49import io.appium.java_client.android.HasNetworkConnection;50import io.appium.java_client.android.PushesFiles;51import io.appium.java_client.android.StartsActivity;52import io.appium.java_client.ios.ShakesDevice;53import io.appium.java_client.windows.WindowsKeyCode;54/**55 * This class is a "simple" extension of Selenium's EventFiringWebDriver that56 * additionally implements several useful interfaces.57 * 58 * @author Sachin Kumar 12 [skumar213@sapient.com]59 */60public class WebDriverWrapper extends EventFiringWebDriver implements FindsById, FindsByClassName, FindsByLinkText,61 FindsByName, FindsByCssSelector, FindsByTagName, FindsByXPath, HasCapabilities, MobileDriver, Rotatable,62 LocationContext, ContextAware, InteractsWithApps, HasAppStrings, HasNetworkConnection, PushesFiles,63 StartsActivity, FindsByAndroidUIAutomator, HasDeviceTime, HidesKeyboard, HidesKeyboardWithKeyName,64 PressesKeyCode, ShakesDevice, HasSessionDetails, FindsByIosUIAutomation, HasIdentity, PerformsTouchActions,65 FindsByFluentSelector, FindsByAccessibilityId, PerformsActions, FindsByWindowsAutomation, WindowsKeyCode {66 /**67 * Constructs WebDriverWrapper.68 *69 * @param driver70 * instance of WebDriver.71 * @param frameSwitcher72 * instance of FrameSwitcher.73 */74 public WebDriverWrapper(WebDriver driver) {75 super(driver);76 }77 /**78 * @return The capabilities of the current driver.79 */80 @Override81 public Capabilities getCapabilities() {82 return ((HasCapabilities) super.getWrappedDriver()).getCapabilities();83 }84 /**85 * Finds element by xpath.86 */87 @Override88 public WebElement findElementByXPath(String xPath) {89 return ((FindsByXPath) super.getWrappedDriver()).findElementByXPath(xPath);90 }91 /**92 * Finds elements by xpath.93 */94 @Override95 public List<WebElement> findElementsByXPath(String xPath) {96 return ((FindsByXPath) super.getWrappedDriver()).findElementsByXPath(xPath);97 }98 /**99 * Finds element by tag name.100 */101 @Override102 public WebElement findElementByTagName(String tagName) {103 return ((FindsByTagName) super.getWrappedDriver()).findElementByTagName(tagName);104 }105 /**106 * Finds elements by tag name.107 */108 @Override109 public List<WebElement> findElementsByTagName(String tagName) {110 return ((FindsByTagName) super.getWrappedDriver()).findElementsByTagName(tagName);111 }112 /**113 * Finds element by css selector.114 */115 @Override116 public WebElement findElementByCssSelector(String cssSelector) {117 return ((FindsByCssSelector) super.getWrappedDriver()).findElementByCssSelector(cssSelector);118 }119 /**120 * Finds elements by css selector.121 */122 @Override123 public List<WebElement> findElementsByCssSelector(String cssSelector) {124 return ((FindsByCssSelector) super.getWrappedDriver()).findElementsByCssSelector(cssSelector);125 }126 /**127 * Finds element by name.128 */129 @Override130 public WebElement findElementByName(String name) {131 return ((FindsByName) super.getWrappedDriver()).findElementByName(name);132 }133 /**134 * Finds elements by name.135 */136 @Override137 public List<WebElement> findElementsByName(String name) {138 return ((FindsByName) super.getWrappedDriver()).findElementsByName(name);139 }140 /**141 * Finds element by link text.142 */143 @Override144 public WebElement findElementByLinkText(String linkText) {145 return ((FindsByLinkText) super.getWrappedDriver()).findElementByLinkText(linkText);146 }147 /**148 * Finds elements by link text.149 */150 @Override151 public List<WebElement> findElementsByLinkText(String linkText) {152 return ((FindsByLinkText) super.getWrappedDriver()).findElementsByLinkText(linkText);153 }154 /**155 * Finds element by partial link text.156 */157 @Override158 public WebElement findElementByPartialLinkText(String partialLinkText) {159 return ((FindsByLinkText) super.getWrappedDriver()).findElementByPartialLinkText(partialLinkText);160 }161 /**162 * Finds elements by partial link text.163 */164 @Override165 public List<WebElement> findElementsByPartialLinkText(String partialLinkText) {166 return ((FindsByLinkText) super.getWrappedDriver()).findElementsByPartialLinkText(partialLinkText);167 }168 /**169 * Finds element by class name.170 */171 @Override172 public WebElement findElementByClassName(String className) {173 return ((FindsByClassName) super.getWrappedDriver()).findElementByClassName(className);174 }175 /**176 * Finds elements by class name.177 */178 @Override179 public List<WebElement> findElementsByClassName(String className) {180 return ((FindsByClassName) super.getWrappedDriver()).findElementsByClassName(className);181 }182 /**183 * Finds element by id.184 */185 @Override186 public WebElement findElementById(String id) {187 return ((FindsById) super.getWrappedDriver()).findElementById(id);188 }189 /**190 * Finds elements by id.191 */192 @Override193 public List<WebElement> findElementsById(String id) {194 return ((FindsById) super.getWrappedDriver()).findElementsById(id);195 }196 @Override197 public TouchAction performTouchAction(TouchAction touchAction) {198 return ((PerformsTouchActions) super.getWrappedDriver()).performTouchAction(touchAction);199 }200 @Override201 public void performMultiTouchAction(MultiTouchAction multiAction) {202 ((PerformsTouchActions) super.getWrappedDriver()).performMultiTouchAction(multiAction);203 }204 @Override205 public void launchApp() {206 ((InteractsWithApps) super.getWrappedDriver()).launchApp();207 }208 @Override209 public void installApp(String appPath) {210 ((InteractsWithApps) super.getWrappedDriver()).installApp(appPath);211 }212 @Override213 public boolean isAppInstalled(String bundleId) {214 return ((InteractsWithApps) super.getWrappedDriver()).isAppInstalled(bundleId);215 }216 @Override217 public void resetApp() {218 ((InteractsWithApps) super.getWrappedDriver()).resetApp();219 }220 @Override221 public void runAppInBackground(int seconds) {222 ((InteractsWithApps) super.getWrappedDriver()).runAppInBackground(seconds);223 }224 @Override225 public void removeApp(String bundleId) {226 ((InteractsWithApps) super.getWrappedDriver()).removeApp(bundleId);227 }228 @Override229 public void closeApp() {230 ((InteractsWithApps) super.getWrappedDriver()).closeApp();231 }232 @Override233 public byte[] pullFile(String remotePath) {234 return ((InteractsWithFiles) super.getWrappedDriver()).pullFile(remotePath);235 }236 @Override237 public byte[] pullFolder(String remotePath) {238 return ((InteractsWithFiles) super.getWrappedDriver()).pullFolder(remotePath);239 }240 @Override241 public Location location() {242 return ((LocationContext) super.getWrappedDriver()).location();243 }244 @Override...
BaseTestDriver.java
Source:BaseTestDriver.java
...17import org.testng.annotations.AfterTest;18import org.testng.annotations.BeforeMethod;19import org.testng.annotations.Parameters;20import io.appium.java_client.AppiumDriver;21import io.appium.java_client.InteractsWithApps;22import io.appium.java_client.MobileElement;23import io.appium.java_client.android.AndroidDriver;24import io.appium.java_client.android.nativekey.AndroidKey;25import io.appium.java_client.android.nativekey.KeyEvent;26import io.appium.java_client.functions.ExpectedCondition;27import io.appium.java_client.pagefactory.AppiumFieldDecorator;28import qa.utils.TestUtils;29public class BaseTestDriver {30 31 public static AppiumDriver<MobileElement> driver;32 public static TestUtils utilss;33 public static Properties pros;34 InputStream inputstream;35 InputStream Stringsis; 36 public static String dateTime;37 public static Actions action;38 public static HashMap<String, String> stringss=new HashMap<String, String>();39 40 41 public BaseTestDriver() {42 PageFactory.initElements(new AppiumFieldDecorator(driver), this);43 }44 45 46 47@Parameters({"deviceName","udid","platformName","platformVersion"})48 @BeforeMethod49 public void beforeTest(String deviceName, String udid,String platformName, String platformVersion ) throws IOException {50 51 try {52 utilss=new TestUtils();53 dateTime=utilss.getDateTime();54 String propFileName="config.properties";55 pros=new Properties();56 inputstream=getClass().getClassLoader().getResourceAsStream(propFileName);57 pros.load(inputstream);58 59 String xmlFileName="Strings/strings.xml";60 Stringsis=getClass().getClassLoader().getResourceAsStream(xmlFileName);61 stringss=utilss.parseStringXML(Stringsis);62 63 64 65 DesiredCapabilities cap= new DesiredCapabilities(); 66 cap.setCapability("deviceName", deviceName);67 cap.setCapability("platformName", platformName);68 cap.setCapability("platformVersion",platformVersion );69 cap.setCapability("udid", udid);70 cap.setCapability("appPackage", pros.getProperty("appPackage"));71 cap.setCapability("appActivity", pros.getProperty("appActivity"));72 cap.setCapability("noReset", true);73 cap.setCapability("fullRest", false);74 75 URL url=new URL(pros.getProperty("appiumurl"));76 driver=new AndroidDriver<MobileElement>(url,cap);77 // ((InteractsWithApps) driver).resetApp();78 driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);79 }catch(Exception e) {80 e.printStackTrace();81 }82 finally {83 if(inputstream !=null) {84 inputstream.close();85 }86 if(stringss !=null) {87 Stringsis.close();88 }89 } 90 }91 public void waitforVisibility(MobileElement e) {92 93 WebDriverWait wait=new WebDriverWait(driver, 40);94 wait.until(ExpectedConditions.visibilityOf(e));95 96 }97 98 public void waitelementToBeClickable(MobileElement e) {99 100 WebDriverWait wait=new WebDriverWait(driver, 30);101 wait.until(ExpectedConditions.elementToBeClickable(e));102 103 }104 105 public void click(MobileElement e) {106 waitforVisibility(e);107 e.click();108 }109 110 public void clickElement(MobileElement e) {111 waitelementToBeClickable(e);112 e.click();113 }114 115 public void IsEnabled(MobileElement e) {116 waitforVisibility(e);117 e.isEnabled();118 119 }120 public void sendkeys(MobileElement e, String text) {121 waitforVisibility(e); 122// e.sendKeys(text);123 e.sendKeys(text);124 }125 126 public void keboardHide() {127 try {128 driver.hideKeyboard();129 }catch(Exception e) {130 131 }132 }133 134 135 136 public String getAttribute(MobileElement e, String attribute) {137 waitforVisibility(e); 138 return e.getAttribute(attribute);139 }140 141 public String getAttributetext(MobileElement e, String attribute) {142 waitforVisibility(e); 143 return e.getText();144 }145 public String getErrTxt(MobileElement e, String msg) {146 waitforVisibility(e); 147 return e.getAttribute(msg);148 }149 150 151 152 public void backNavigation() {153 driver.navigate().back();154 155 }156 public void forwardNavigation() {157 driver.navigate().forward();158 }159 160 public void actions(MobileElement e,AndroidKey AndroidKey) {161 ((AndroidDriver<MobileElement>) driver).pressKey(new KeyEvent(AndroidKey));162 163 }164 165//** Finding the element and scrolling "UP and DOWN" ***//166 public static void scrollToElement(MobileElement e, String direction) {167 for (int i = 0; i <= 3; i++) {168 if (isDisplayed(e)) {169 break;170 } else {171 if (direction.equalsIgnoreCase("up")) {172 utilss.ScrollDownUp(driver, "up");173 } else {174 utilss.ScrollDownUp(driver, "down");175 }176 }177 }178 }179 public static boolean isDisplayed(final MobileElement e) {180 driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);181 try {182 WebDriverWait wait = new WebDriverWait(driver, 2);183 return wait.until(new ExpectedCondition<Boolean>() {184 public Boolean apply(WebDriver driver) {185 if (e.isDisplayed()) {186 return true;187 } else {188 return false;189 }190 }191 });192 } catch (Exception ex) {193 return false;194 }195 } 196 //******* TestUtils element is End***********197 public void closeApp() {198 ((InteractsWithApps) driver).closeApp();199 }200 201 /*202 * public void launchApp() { ((InteractsWithApps) driver).closeApp();203 * ((InteractsWithApps) driver).launchApp(); }204 */205 206 @AfterTest207 public void afterTest() {208 /*209 * ((InteractsWithApps) driver).closeApp(); ((InteractsWithApps)210 * driver).closeApp();211 */212 driver.quit();213 }214 public AppiumDriver gerDriver() {215 return driver;216 }217 public String getDateTime() {218 return dateTime;219 }220}...
BasePage.java
Source:BasePage.java
...14import org.openqa.selenium.support.ui.ExpectedConditions;15import org.openqa.selenium.support.ui.WebDriverWait;16import io.appium.java_client.AppiumDriver;17import io.appium.java_client.FindsByAndroidUIAutomator;18import io.appium.java_client.InteractsWithApps;19import io.appium.java_client.MobileBy;20import io.appium.java_client.MobileElement;21import io.appium.java_client.TouchAction;22import io.appium.java_client.pagefactory.AppiumFieldDecorator;23import utils.DriverManager;24import utils.GlobalParams;25import utils.TestUtils;26public class BasePage {27 private AppiumDriver<?> driver;28 29 TestUtils utils = new TestUtils();30 public BasePage(){31 this.driver = new DriverManager().getDriver();32 // return driver;33 PageFactory.initElements(new AppiumFieldDecorator(this.driver), this);34 35 }36 public void waitForVisibility(MobileElement e) {37 WebDriverWait wait = new WebDriverWait(driver, TestUtils.WAIT);38 wait.until(ExpectedConditions.visibilityOf(e));39 }40 public void clear(MobileElement e) {41 waitForVisibility(e);42 e.clear();43 }44 public void click(MobileElement e) {45 waitForVisibility(e);46 e.click();47 }48 public void click(MobileElement e, String msg) {49 waitForVisibility(e);50 utils.log().info(msg);51 e.click();52 }53 public void sendKeys(MobileElement e, String txt) {54 waitForVisibility(e);55 e.sendKeys(txt);56 }57 public void sendKeys(MobileElement e, String txt, String msg) {58 waitForVisibility(e);59 utils.log().info(msg);60 e.sendKeys(txt);61 }62 public String getAttribute(MobileElement e, String attribute) {63 waitForVisibility(e);64 return e.getAttribute(attribute);65 }66 public String getText(MobileElement e, String msg) {67 String txt;68 txt = getAttribute(e, "text");69 utils.log().info(msg + txt);70 return txt;71 }72 73 public void closeApp() {74 ((InteractsWithApps) driver).closeApp();75 }76 public void launchApp() {77 ((InteractsWithApps) driver).launchApp();78 }79 public MobileElement andScrollToElementUsingUiScrollable(String childLocAttr, String childLocValue) {80 return (MobileElement) ((FindsByAndroidUIAutomator) driver).findElementByAndroidUIAutomator(81 "new UiScrollable(new UiSelector()" + ".scrollable(true)).scrollIntoView("82 + "new UiSelector()."+ childLocAttr +"(\"" + childLocValue + "\"));");83 }84 public MobileElement scrollToElement(MobileElement element, String direction) throws Exception {85 Dimension size = driver.manage().window().getSize();86 int startX = (int) (size.width * 0.5);87 int endX = (int) (size.width * 0.5);88 int startY = 0;89 int endY = 0;90 boolean isFound = false;91 switch (direction) {...
BaseClass.java
Source:BaseClass.java
1package blu;2import blu.utils.TestUtils;3import io.appium.java_client.AppiumDriver;4import io.appium.java_client.InteractsWithApps;5import io.appium.java_client.MobileElement;6import io.appium.java_client.TouchAction;7import io.appium.java_client.pagefactory.AppiumFieldDecorator;8import io.appium.java_client.touch.WaitOptions;9import io.appium.java_client.touch.offset.PointOption;10import org.openqa.selenium.Dimension;11import org.openqa.selenium.remote.DesiredCapabilities;12import org.openqa.selenium.support.PageFactory;13import org.openqa.selenium.support.ui.ExpectedConditions;14import org.openqa.selenium.support.ui.WebDriverWait;15import org.testng.annotations.*;16import java.io.InputStream;17import java.net.URL;18import java.time.Duration;19import java.util.HashMap;20import java.util.Properties;21import java.util.concurrent.TimeUnit;22public class BaseClass {23 protected static AppiumDriver<MobileElement> driver;24 protected static Properties props;25 protected static HashMap<String, String> strings = new HashMap<String, String>();26 InputStream inputStream;27 InputStream stringsis;28 TestUtils utils;29 public BaseClass() {30 PageFactory.initElements(new AppiumFieldDecorator(driver), this);31 }32 @Parameters({"DeviceName", "PlatformName", "PlatformVersion", "udid"})33 @BeforeTest34 public void beforeTest(String DeviceName, String PlatformName, String PlatformVersion, String udid) throws Exception {35 try {36 props = new Properties();37 String propFileName = "config.properties";38 String xmlFileName = "strings/strings.xml";39 inputStream = getClass().getClassLoader().getResourceAsStream(propFileName);40 props.load(inputStream);41 stringsis = getClass().getClassLoader().getResourceAsStream(xmlFileName);42 utils = new TestUtils();43 strings = utils.parseStringXML(stringsis);44 DesiredCapabilities cap = new DesiredCapabilities();45 cap.setCapability("deviceName", DeviceName);46 cap.setCapability("platformName", PlatformName);47 cap.setCapability("platformVersion", PlatformVersion);48 cap.setCapability("udid", udid);49 //cap.setCapability("systemPort","systemPort");50 cap.setCapability("automationName", props.getProperty("androidAutomationName"));51 cap.setCapability("appPackage", props.getProperty("androidAppPackageName"));52 cap.setCapability("appActivity", props.getProperty("androidAppActivityName"));53 URL appUrl = getClass().getClassLoader().getResource(props.getProperty("androidAppLocation"));54 cap.setCapability("app", appUrl);55 URL url = new URL(props.getProperty("appiumURL"));56 driver = new AppiumDriver<MobileElement>(url, cap);57 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);58 } catch (Exception e) {59 e.printStackTrace();60 } finally {61 if (inputStream != null) {62 inputStream.close();63 }64 if (stringsis != null) {65 stringsis.close();66 }67 }68 }69 public void waitForVisibility(MobileElement e) {70 WebDriverWait wait = new WebDriverWait(driver, TestUtils.WAIT);71 wait.until(ExpectedConditions.visibilityOf(e));72 }73 public void click(MobileElement e) {74 waitForVisibility(e);75 e.click();76 }77 public void sendKeys(MobileElement e, String txt) {78 waitForVisibility(e);79 e.sendKeys(txt);80 }81 public String getAttribute(MobileElement e, String attribute) {82 waitForVisibility(e);83 return e.getAttribute(attribute);84 }85 public void clear(MobileElement e) {86 waitForVisibility(e);87 e.clear();88 }89 public void scroll(AppiumDriver<MobileElement> driver, double start_xd,double start_yd, double end_xd, double end_yd) {90 Dimension dimension = driver.manage().window().getSize();91 int start_x = (int) (dimension.width * start_xd);92 int start_y = (int) (dimension.height * start_yd);93 int end_x = (int) (dimension.width * end_xd);94 int end_y = (int) (dimension.height * end_yd);95 TouchAction touch = new TouchAction(driver);96 touch.press(PointOption.point(start_x, start_y))97 .waitAction(WaitOptions.waitOptions(Duration.ofSeconds(1)))98 .moveTo(PointOption.point(end_x,end_y)).release().perform();99 }100 public void hideKeyboard() {101 driver.hideKeyboard();102 }103 public void closeApp(){104 ((InteractsWithApps) driver).closeApp();105 }106 public void launchApp(){107 ((InteractsWithApps) driver).launchApp();108 }109 @AfterTest110 public void afterTest() {111 driver.quit();112 }113}...
BaseTest.java
Source:BaseTest.java
...11import org.testng.annotations.BeforeSuite;12import com.qa.utils.TestUtils;13import io.appium.java_client.AppiumDriver;14import io.appium.java_client.FindsByAndroidUIAutomator;15import io.appium.java_client.InteractsWithApps;16import io.appium.java_client.MobileElement;17import io.appium.java_client.android.AndroidDriver;18import io.appium.java_client.pagefactory.AppiumFieldDecorator;19import io.appium.java_client.remote.MobileCapabilityType;20public class BaseTest {21 @SuppressWarnings("rawtypes")22 public static AppiumDriver driver;23 protected static Properties prop;24 InputStream inputStream;25 public BaseTest() {26 PageFactory.initElements(new AppiumFieldDecorator(driver), this);27 }28 @SuppressWarnings("rawtypes")29 @BeforeSuite30 public void setup() {31 prop = new Properties();32 inputStream = getClass().getClassLoader().getResourceAsStream("config.properties");33 try {34 prop.load(inputStream);35 DesiredCapabilities caps = new DesiredCapabilities();36 caps.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");37 caps.setCapability(MobileCapabilityType.DEVICE_NAME, "Pixel_4");38 caps.setCapability(MobileCapabilityType.UDID, "emulator-5554");39 caps.setCapability(MobileCapabilityType.AUTOMATION_NAME, prop.getProperty("androidAutomationName"));40 URL appURL = getClass().getClassLoader().getResource(prop.getProperty("androidAppLocation"));41 caps.setCapability(MobileCapabilityType.APP, "C:\\Users\\VallisriTolety\\git\\MyTDDProject\\src\\test\\resources\\app\\Android.SauceLabs.Mobile.Sample.app.2.7.1.apk");42 caps.setCapability("appPackage", prop.getProperty("androidAppPackage"));43 caps.setCapability("appActivity", prop.getProperty("androidAppActivity"));44 URL url = new URL(prop.getProperty("appiumURL"));45 driver = new AndroidDriver(url, caps);46 } catch (IOException e) {47 e.printStackTrace();48 }49 }50 public void waitForVisibility(MobileElement e) {51 WebDriverWait wait = new WebDriverWait(driver, TestUtils.WAIT);52 wait.until(ExpectedConditions.visibilityOf(e));53 }54 public void clear(MobileElement e) {55 waitForVisibility(e);56 e.clear();57 }58 public void click(MobileElement e) {59 waitForVisibility(e);60 e.click();61 }62 public void sendKeys(MobileElement e, String txt) {63 waitForVisibility(e);64 e.sendKeys(txt);65 }66 public String getAttribute(MobileElement e, String attribute) {67 waitForVisibility(e);68 return e.getAttribute(attribute);69 }70 71 public String getText(MobileElement e) {72 String txt = null;73 txt = getAttribute(e, "text");74 return txt;75 }76 77 public MobileElement scrollToElement() { 78 return (MobileElement) ((FindsByAndroidUIAutomator) driver).findElementByAndroidUIAutomator(79 "new UiScrollable(new UiSelector()" + ".scrollable(true)).scrollIntoView("80 + "new UiSelector().description(\"test-Price\"));");81 }82 83 public void closeApp() {84 ((InteractsWithApps) driver).closeApp();85 }86 87 public void launchApp() {88 ((InteractsWithApps) driver).launchApp();89 }90 @AfterSuite91 public void tearDown() {92 }93}...
MobileActionUtil.java
Source:MobileActionUtil.java
...11import org.testng.annotations.AfterTest;12import com.oswal.android.init.PathConstants;13import com.oswal.android.lib.BaseLib;14import io.appium.java_client.FindsByAndroidUIAutomator;15import io.appium.java_client.InteractsWithApps;16import io.appium.java_client.MobileElement;17import io.appium.java_client.android.AndroidDriver;18public class MobileActionUtil extends BaseLib19{20 AndroidDriver driver;21 public static void waitForVisibility(MobileElement e) {22 WebDriverWait wait = new WebDriverWait(gv.driver, 15);23 wait.until(ExpectedConditions.visibilityOf(e));24 }25 public static void clear(MobileElement e) {26 waitForVisibility(e);27 e.clear();28 }29 public static void click(MobileElement e) {30 waitForVisibility(e);31 e.click();32 }33 public static void click(MobileElement e, String msg) {34 waitForVisibility(e);35 e.click();36 }37 public static void sendKeys(MobileElement e, String txt) {38 waitForVisibility(e);39 e.sendKeys(txt);40 }41 public static void sendKeys(MobileElement e, String txt, String msg) {42 waitForVisibility(e);43 44 e.sendKeys(txt);45 }46 public static String getAttribute(MobileElement e, String attribute) {47 waitForVisibility(e);48 return e.getAttribute(attribute);49 }50 51 public static String getText(MobileElement e) {52 waitForVisibility(e);53 return e.getText();54 }55// public static void closeApp() {56// ((InteractsWithApps) getDriver()).closeApp();57// }58// public static void launchApp() {59// ((InteractsWithApps) getDriver()).launchApp();60// }61//62// public static MobileElement scrollToElement() { 63// return (MobileElement) ((FindsByAndroidUIAutomator) getDriver()).findElementByAndroidUIAutomator(64// "new UiScrollable(new UiSelector()" + ".scrollable(true)).scrollIntoView("65// + "new UiSelector().description(\"test-Price\"));");66// }67 public static String capture(AndroidDriver driver, String screenShotName) throws IOException {68 File source = driver.getScreenshotAs(OutputType.FILE);69 String dest = PathConstants.screenShotPath +" " +screenShotName + ".png";70 File destination = new File(dest);71 FileUtils.copyFile(source, destination);72 return dest;73 }...
AppManager.java
Source:AppManager.java
1package com.epam.jdi.light.mobile.elements.common;2import com.epam.jdi.light.common.JDIAction;3import io.appium.java_client.InteractsWithApps;4import io.appium.java_client.appmanagement.ApplicationState;5import java.time.Duration;6import static com.epam.jdi.light.mobile.MobileUtils.executeDriverMethod;7public class AppManager {8 // current app (AUT)9 @JDIAction("Launch the app under test")10 public static void launchApp() {11 executeDriverMethod(InteractsWithApps.class, InteractsWithApps::launchApp);12 }13 @JDIAction("Close the app under test")14 public static void closeApp() {15 executeDriverMethod(InteractsWithApps.class, InteractsWithApps::closeApp);16 }17 @JDIAction("Reset the app under test")18 public static void resetApp() {19 executeDriverMethod(InteractsWithApps.class, InteractsWithApps::resetApp);20 }21 @JDIAction("Run the app under test in background")22 public static void runAppInBackground(Duration duration) {23 executeDriverMethod(InteractsWithApps.class, (InteractsWithApps driver) -> driver.runAppInBackground(duration));24 }25 // some other app26 @JDIAction("Activate the '{0}' app")27 public static void activateApp(String bundleId) {28 executeDriverMethod(InteractsWithApps.class, (InteractsWithApps driver) -> driver.activateApp(bundleId));29 }30 @JDIAction("Terminate the '{0}' app")31 public static boolean terminateApp(String bundleId) {32 return executeDriverMethod(InteractsWithApps.class, (InteractsWithApps driver) -> driver.terminateApp(bundleId));33 }34 @JDIAction("Query the state of the '{0}' app")35 public static ApplicationState queryAppState(String bundleId) {36 return executeDriverMethod(InteractsWithApps.class, (InteractsWithApps driver) -> driver.queryAppState(bundleId));37 }38 @JDIAction("Install the '{0}' app")39 public static void installApp(String appPath) {40 executeDriverMethod(InteractsWithApps.class, (InteractsWithApps driver) -> driver.installApp(appPath));41 }42 @JDIAction("Remove the '{0}' app")43 public static boolean removeApp(String bundleId) {44 return executeDriverMethod(InteractsWithApps.class, (InteractsWithApps driver) -> driver.removeApp(bundleId));45 }46 @JDIAction("Check whether the '{0}' app is installed")47 public static boolean isAppInstalled(String bundleId) {48 return executeDriverMethod(InteractsWithApps.class, (InteractsWithApps driver) -> driver.isAppInstalled(bundleId));49 }50}...
DriverManager.java
Source:DriverManager.java
1package com.qa.utils;2import io.appium.java_client.AppiumDriver;3import io.appium.java_client.InteractsWithApps;4import io.appium.java_client.android.AndroidDriver;5import io.appium.java_client.ios.IOSDriver;6import java.io.IOException;7public class DriverManager {8 public static ThreadLocal<AppiumDriver> driver = new ThreadLocal<>();9 TestUtils utils = new TestUtils();10 public AppiumDriver getDriver()11 {12 return driver.get();13 }14 public void setDriver(AppiumDriver driver)15 {16 DriverManager.driver.set(driver);17 }18 public void initializeDriver() throws Exception {19 AppiumDriver localDriver =null;20 GlobalParams params = new GlobalParams();21 PropertyManager propertyManager = new PropertyManager();22 try{23 utils.log().info("Initializing appium driver...");24 switch (params.getPlatformName())25 {26 case "Android" :27 localDriver = new AndroidDriver(new ServerManager().getServer().getUrl(),new CapabilitiesManager().getCapabilities());28 break;29 case "iOS" :30 localDriver = new IOSDriver(new ServerManager().getServer().getUrl(),new CapabilitiesManager().getCapabilities());31 break;32 }33 if(localDriver==null)34 {35 throw new Exception("driver is null...ABOT!!!");36 }37 utils.log().info("Driver is initialized...");38 driver.set(localDriver);39 } catch (IOException e) {40 e.printStackTrace();41 } catch (Exception e) {42 e.printStackTrace();43 utils.log().fatal("Driver initialization failed.. ABORT !!! "+e.toString());44 throw e;45 }46 }47 /**48 * This method will close the app and quit the driver session49 */50 public void closeApp() {51 ((InteractsWithApps) getDriver()).closeApp();52 }53 /**54 * This method will launch the app and re-start the driver session55 */56 public void launchApp() {57 ((InteractsWithApps) getDriver()).launchApp();58 }59}
InteractsWithApps
Using AI Code Generation
1package appium.java;2import io.appium.java_client.android.AndroidDriver;3import io.appium.java_client.android.AndroidElement;4import io.appium.java_client.remote.MobileCapabilityType;5import java.net.MalformedURLException;6import java.net.URL;7import org.openqa.selenium.remote.DesiredCapabilities;8public class Appium {9public static void main(String[] args) throws MalformedURLException {10DesiredCapabilities cap = new DesiredCapabilities();11cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Device");12cap.setCapability(MobileCapabilityType.APP, "C:\\Users\\Admin\\Desktop\\selendroid-test-app-0.17.0.apk");
InteractsWithApps
Using AI Code Generation
1InteractsWithApps interactsWithApps = new AppiumDriver();2interactsWithApps.closeApp();3interactsWithApps.launchApp();4interactsWithApps.resetApp();5interactsWithApps.runAppInBackground(Duration.ofSeconds(10));6interactsWithApps.startActivity("com.android.package", ".ActivityClass");7InteractsWithFiles interactsWithFiles = new AppiumDriver();8interactsWithFiles.pushFile("path/to/remote/file", "file content");9interactsWithFiles.pullFile("path/to/remote/file");10InteractsWithElements interactsWithElements = new AppiumDriver();11interactsWithElements.clear();12interactsWithElements.click();13interactsWithElements.findElementByAndroidUIAutomator("new UiSelector().text(\"text\")");14interactsWithElements.findElementsByAndroidUIAutomator("new UiSelector().text(\"text\")");15interactsWithElements.findElementByClassName("android.widget.TextView");16interactsWithElements.findElementsByClassName("android.widget.TextView");17interactsWithElements.findElementByCssSelector("android.widget.TextView");18interactsWithElements.findElementsByCssSelector("android.widget.TextView");19interactsWithElements.findElementByAccessibilityId("accessibilityId");20interactsWithElements.findElementsByAccessibilityId("accessibilityId");21interactsWithElements.findElementById("id");22interactsWithElements.findElementsById("id");23interactsWithElements.findElementByImage("image");24interactsWithElements.findElementsByImage("image");25interactsWithElements.findElementByIosUIAutomation("UIAutomation");26interactsWithElements.findElementsByIosUIAutomation("UIAutomation");27interactsWithElements.findElementByLinkText("Link");28interactsWithElements.findElementsByLinkText("Link");29interactsWithElements.findElementByName("name");30interactsWithElements.findElementsByName("name");31interactsWithElements.findElementByPartialLinkText("Link");32interactsWithElements.findElementsByPartialLinkText("Link");33interactsWithElements.findElementByTagName("tag");34interactsWithElements.findElementsByTagName("tag");35interactsWithElements.findElementByXPath("xpath");36interactsWithElements.findElementsByXPath("xpath");37interactsWithElements.getTagName();38interactsWithElements.getText();39interactsWithElements.isDisplayed();40interactsWithElements.isEnabled();41interactsWithElements.isSelected();
InteractsWithApps
Using AI Code Generation
1InteractsWithApps interactsWithApps = (InteractsWithApps) driver;2interactsWithApps.closeApp();3InteractsWithApps interactsWithApps = (InteractsWithApps) driver;4interactsWithApps.launchApp();5InteractsWithApps interactsWithApps = (InteractsWithApps) driver;6interactsWithApps.resetApp();7InteractsWithApps interactsWithApps = (InteractsWithApps) driver;8interactsWithApps.runAppInBackground(Duration.ofSeconds(5));9InteractsWithApps interactsWithApps = (InteractsWithApps) driver;10interactsWithApps.runAppInBackground(Duration.ofSeconds(5));11InteractsWithApps interactsWithApps = (InteractsWithApps) driver;12interactsWithApps.runAppInBackground(Duration.ofSeconds(5));13InteractsWithApps interactsWithApps = (InteractsWithApps) driver;14interactsWithApps.runAppInBackground(Duration.ofSeconds(5));15InteractsWithApps interactsWithApps = (InteractsWithApps) driver;
InteractsWithApps
Using AI Code Generation
1appiumDriver.launchApp();2appiumDriver.closeApp();3appiumDriver.resetApp();4appiumDriver.isAppInstalled("com.android.calculator2");5appiumDriver.removeApp("com.android.calculator2");6appiumDriver.installApp("path/to/the/apk");7appiumDriver.activateApp("com.android.calculator2");8appiumDriver.launchApp();9appiumDriver.closeApp();10appiumDriver.resetApp();11appiumDriver.isAppInstalled("com.android.calculator2");12appiumDriver.removeApp("com.android.calculator2");13appiumDriver.installApp("path/to/the/apk");14appiumDriver.activateApp("com.android.calculator2");15appiumDriver.launchApp();16appiumDriver.closeApp();17appiumDriver.resetApp();18appiumDriver.isAppInstalled("com.android.calculator2");19appiumDriver.removeApp("com.android.calculator2");20appiumDriver.installApp("path/to/the/apk");21appiumDriver.activateApp("com.android.calculator2");22appiumDriver.launchApp();23appiumDriver.closeApp();24appiumDriver.resetApp();25appiumDriver.isAppInstalled("com.android.calculator2");26appiumDriver.removeApp("com.android.calculator2");27appiumDriver.installApp("path/to/the/apk");28appiumDriver.activateApp("com.android.calculator2");29appiumDriver.launchApp();30appiumDriver.closeApp();31appiumDriver.resetApp();32appiumDriver.isAppInstalled("com.android.calculator2");33appiumDriver.removeApp("com.android.calculator2");34appiumDriver.installApp("path/to/the/apk");35appiumDriver.activateApp("com.android.calculator2");36appiumDriver.launchApp();37appiumDriver.closeApp();38appiumDriver.resetApp();39appiumDriver.isAppInstalled("com.android.calculator2");40appiumDriver.removeApp("com.android.calculator2");
InteractsWithApps
Using AI Code Generation
1DesiredCapabilities capabilities = new DesiredCapabilities();2capabilities.setCapability("platformName", "Android");3capabilities.setCapability("platformVersion", "6.0.1");4capabilities.setCapability("deviceName", "Android Emulator");5capabilities.setCapability("appPackage", "com.android.calculator2");6capabilities.setCapability("appActivity", "com.android.calculator2.Calculator");7capabilities.setCapability("automationName", "UiAutomator2");
InteractsWithApps
Using AI Code Generation
1public class Appium {2 public static void main(String[] args) {3 DesiredCapabilities caps = new DesiredCapabilities();4 caps.setCapability("deviceName", "Pixel 2 API 28");5 caps.setCapability("platformName", "Android");6 caps.setCapability("platformVersion", "9.0");7 caps.setCapability("appPackage", "com.android.calculator2");8 caps.setCapability("appActivity", "com.android.calculator2.Calculator");9 caps.setCapability("noReset", "true");
InteractsWithApps
Using AI Code Generation
1import io.appium.java_client.android.AndroidDriver;2import io.appium.java_client.android.AndroidElement;3import io.appium.java_client.remote.MobileCapabilityType;4import io.appium.java_client.service.local.AppiumDriverLocalService;5import io.appium.java_client.service.local.AppiumServiceBuilder;6import io.appium.java_client.service.local.flags.GeneralServerFlag;7import org.openqa.selenium.remote.DesiredCapabilities;8import java.io.File;9import java.net.MalformedURLException;10import java.net.URL;11import java.util.concurrent.TimeUnit;12public class Appium {13public static void main(String[] args) throws MalformedURLException {14.buildService(new AppiumServiceBuilder()15.usingDriverExecutable(new File("C:\\Program Files\\nodejs\\node.exe"))16.withAppiumJS(new File("C:\\Program Files (x86)\\Appium\\node_modules\\appium\\build\\lib\\main.js"))17.withLogFile(new File("C:\\Users\\Saurabh\\Desktop\\AppiumLogs\\logs.txt"))18.withArgument(GeneralServerFlag.LOCAL_TIMEZONE));19service.start();20DesiredCapabilities cap = new DesiredCapabilities();21cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Device");22cap.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");23cap.setCapability(MobileCapabilityType.PLATFORM_VERSION, "7.0");24cap.setCapability(MobileCapabilityType.AUTOMATION_NAME, "uiautomator2");25cap.setCapability(MobileCapabilityType.APP, "C:\\Users\\Saurabh\\Desktop\\APK\\ApiDemos-debug.apk");
InteractsWithApps
Using AI Code Generation
1driver.launchApp(); 2driver.closeApp(); 3driver.runAppInBackground(Duration.ofSeconds(5)); 4driver.activateApp("com.android.calculator2"); 5driver.terminateApp("com.android.calculator2"); 6driver.installApp("/Users/username/Downloads/ApiDemos-debug.apk"); 7driver.removeApp("com.android.calculator2"); 8driver.isAppInstalled("com.android.calculator2"); 9driver.resetApp(); 10driver.hideKeyboard(); 11driver.hideKeyboard(HideKeyboardStrategy.PRESS_KEY, "Done"); 12driver.hideKeyboard(HideKeyboardStrategy.PRESS_KEY, "Done", "key"); 13driver.hideKeyboard(HideKeyboardStrategy.PRESS_KEY, "Done", "key", "label"); 14driver.hideKeyboard(HideKeyboardStrategy.PRESS_KEY, "Done", "key", "label", "name"); 15driver.hideKeyboard(HideKeyboardStrategy.PRESS_KEY, "Done", "key", "label", "name", "xpath"); 16driver.hideKeyboard(HideKeyboardStrategy.PRESS_KEY, "Done", "key", "label", "name", "xpath", "className"); 17driver.hideKeyboard(HideKeyboardStrategy.PRESS_KEY, "Done", "key", "label",
InteractsWithApps
Using AI Code Generation
1InteractsWithApps gestures = (InteractsWithApps) driver;2gestures.closeApp();3gestures.launchApp();4gestures.resetApp();5var gestures = new Appium.TouchAction();6gestures.closeApp();7gestures.launchApp();8gestures.resetApp();9gestures = Appium.TouchAction()10gestures.close_app()11gestures.launch_app()12gestures.reset_app()13$gestures = new Appium\TouchAction();14$gestures->closeApp();15$gestures->launchApp();16$gestures->resetApp();17gestures := Appium.TouchAction()18gestures.CloseApp()19gestures.LaunchApp()20gestures.ResetApp()21InteractsWithApps gestures = (InteractsWithApps) driver;22gestures.closeApp();23gestures.launchApp();24gestures.resetApp();
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!!