How to use StartsActivity class of io.appium.java_client.android package

Best io.appium code snippet using io.appium.java_client.android.StartsActivity

WebDriverWrapper.java

Source:WebDriverWrapper.java Github

copy

Full Screen

...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 @Override245 public void setLocation(Location arg0) {246 ((LocationContext) super.getWrappedDriver()).setLocation(arg0);247 }248 @Override249 public WebElement findElementByAccessibilityId(String using) {250 return ((FindsByAccessibilityId) super.getWrappedDriver()).findElementByAccessibilityId(using);251 }252 @Override253 public List<WebElement> findElementsByAccessibilityId(String using) {254 return ((FindsByAccessibilityId) super.getWrappedDriver()).findElementsByAccessibilityId(using);255 }256 @Override257 public ScreenOrientation getOrientation() {258 return ((Rotatable) super.getWrappedDriver()).getOrientation();259 }260 @Override261 public void rotate(DeviceRotation deviceRotation) {262 ((Rotatable) super.getWrappedDriver()).rotate(deviceRotation);263 }264 @Override265 public DeviceRotation rotation() {266 return ((Rotatable) super.getWrappedDriver()).rotation();267 }268 @Override269 public void rotate(ScreenOrientation screenOrientation) {270 ((Rotatable) super.getWrappedDriver()).rotate(screenOrientation);271 }272 @Override273 public WebDriver context(String name) {274 return ((ContextAware) super.getWrappedDriver()).context(name);275 }276 @Override277 public String getContext() {278 return ((ContextAware) super.getWrappedDriver()).getContext();279 }280 @Override281 public Set<String> getContextHandles() {282 return ((ContextAware) super.getWrappedDriver()).getContextHandles();283 }284 @Override285 public Response execute(String driverCommand, Map parameters) {286 return ((MobileDriver) super.getWrappedDriver()).execute(driverCommand, parameters);287 }288 @Override289 public WebElement findElementByIosUIAutomation(String using) {290 return ((FindsByIosUIAutomation) super.getWrappedDriver()).findElementByIosUIAutomation(using);291 }292 @Override293 public List<WebElement> findElementsByIosUIAutomation(String using) {294 return ((FindsByIosUIAutomation) super.getWrappedDriver()).findElementsByIosUIAutomation(using);295 }296 @Override297 public WebElement findElementByAndroidUIAutomator(String using) {298 return ((FindsByAndroidUIAutomator) super.getWrappedDriver()).findElementByAndroidUIAutomator(using);299 }300 @Override301 public List<WebElement> findElementsByAndroidUIAutomator(String using) {302 return ((FindsByAndroidUIAutomator) super.getWrappedDriver()).findElementsByAndroidUIAutomator(using);303 }304 @Override305 public void startActivity(String appPackage, String appActivity, String appWaitPackage, String appWaitActivity,306 boolean stopApp) throws IllegalArgumentException {307 ((StartsActivity) super.getWrappedDriver()).startActivity(appPackage, appActivity, appWaitPackage,308 appWaitActivity, stopApp);309 }310 @Override311 public void startActivity(String appPackage, String appActivity, String appWaitPackage, String appWaitActivity) {312 ((StartsActivity) super.getWrappedDriver()).startActivity(appPackage, appActivity, appWaitPackage,313 appWaitActivity);314 }315 @Override316 public void startActivity(String appPackage, String appActivity) {317 ((StartsActivity) super.getWrappedDriver()).startActivity(appPackage, appActivity);318 }319 @Override320 public void startActivity(String appPackage, String appActivity, String appWaitPackage, String appWaitActivity,321 String intentAction, String intentCategory, String intentFlags, String intentOptionalArgs)322 throws IllegalArgumentException {323 ((StartsActivity) super.getWrappedDriver()).startActivity(appPackage, appActivity, appWaitPackage,324 appWaitActivity, intentAction, intentCategory, intentFlags, intentOptionalArgs);325 }326 @Override327 public void startActivity(String appPackage, String appActivity, String appWaitPackage, String appWaitActivity,328 String intentAction, String intentCategory, String intentFlags, String intentOptionalArgs, boolean stopApp)329 throws IllegalArgumentException {330 ((StartsActivity) super.getWrappedDriver()).startActivity(appPackage, appActivity, appWaitPackage,331 appWaitActivity, intentAction, intentCategory, intentFlags, intentOptionalArgs, stopApp);332 }333 @Override334 public void pushFile(String remotePath, byte[] base64Data) {335 ((PushesFiles) super.getWrappedDriver()).pushFile(remotePath, base64Data);336 }337 @Override338 public void pushFile(String remotePath, File file) throws IOException {339 ((PushesFiles) super.getWrappedDriver()).pushFile(remotePath, file);340 }341 @Override342 public TargetLocator switchTo() {343 return super.getWrappedDriver().switchTo();344 }...

Full Screen

Full Screen

AndroidTest.java

Source:AndroidTest.java Github

copy

Full Screen

...6import io.appium.java_client.MobileBy;7import io.appium.java_client.MobileElement;8import io.appium.java_client.android.Activity;9import io.appium.java_client.android.AndroidElement;10import io.appium.java_client.android.StartsActivity;11import io.appium.java_client.remote.MobileCapabilityType;12import io.appium.java_client.remote.MobilePlatform;13import io.appium.java_client.service.local.AppiumDriverLocalService;14import io.appium.java_client.service.local.AppiumServerHasNotBeenStartedLocallyException;15import org.junit.AfterClass;16import org.junit.Before;17import org.junit.BeforeClass;18import org.junit.Test;19import org.openqa.selenium.By;20import org.openqa.selenium.remote.DesiredCapabilities;21import org.openqa.selenium.remote.Response;22import java.io.File;23import java.util.Map;24public class AndroidTest {25 private static AppiumDriverLocalService service;26 private static AppiumDriver<AndroidElement> driver;27 private StartsActivity startsActivity;28 /**29 * initialization.30 */31 @BeforeClass32 public static void beforeClass() throws Exception {33 service = AppiumDriverLocalService.buildDefaultService();34 service.start();35 if (service == null || !service.isRunning()) {36 throw new AppiumServerHasNotBeenStartedLocallyException(37 "An appium server node is not started!");38 }39 File appDir = new File("src/test/java/io/appium/java_client");40 File app = new File(appDir, "ApiDemos-debug.apk");41 DesiredCapabilities capabilities = new DesiredCapabilities();42 capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID);43 capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");44 capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());45 driver = new AppiumDriver<>(service.getUrl(), capabilities);46 }47 /**48 * finishing.49 */50 @AfterClass51 public static void afterClass() {52 if (driver != null) {53 driver.quit();54 }55 if (service != null) {56 service.stop();57 }58 }59 @Before60 public void setUp() throws Exception {61 startsActivity = new StartsActivity() {62 @Override63 public Response execute(String driverCommand, Map<String, ?> parameters) {64 return driver.execute(driverCommand, parameters);65 }66 @Override67 public Response execute(String driverCommand) {68 return driver.execute(driverCommand);69 }70 };71 Activity activity = new Activity("io.appium.android.apis", ".ApiDemos");72 startsActivity.startActivity(activity);73 }74 @Test75 public void findByAccessibilityIdFromDriverTest() {...

Full Screen

Full Screen

appiumtestphonepay.java

Source:appiumtestphonepay.java Github

copy

Full Screen

...11import io.appium.java_client.MobileElement;12import io.appium.java_client.android.Activity;13import io.appium.java_client.android.AndroidDriver;14import io.appium.java_client.android.AndroidElement;15import io.appium.java_client.android.StartsActivity;16// The startActivity method is provided by an interface StartsActivity implemented by AndroidDriver only17public class appiumtestphonepay {18 19 public static AppiumDriver mDriver;20 //private static StartsActivity startsActivity;21 public static void main(String[] args) {22 // TODO Auto-generated method stub23 try {24 openApp();25 } catch (Exception e) {26 // TODO Auto-generated catch block27 System.out.println(e.getCause());28 System.out.println(e.getMessage());29 e.printStackTrace();30 }31 }32 33 public static void openApp() throws Exception34 {35 DesiredCapabilities cap = new DesiredCapabilities();36 cap.setCapability("noReset","true");37 //cap.setCapability("fullReset","false");38 cap.setCapability("deviceName", "SamsungS9Plus");39 cap.setCapability("udid", "231427221c027ece");40 cap.setCapability("platformName", "Android");41 cap.setCapability("platformVersion", "9");42 // cap.setCapability(�autoGrantPermissions�,true);43 // cap.setCapability("autoAcceptAlerts",true);44 45 // cap.setCapability("appPackage", "com.fab.personalbankingSIT");46 // cap.setCapability("appActivity", "com.fab.personalbanking.login.views.LoginHomeActivity");47 48 cap.setCapability("appPackage", "com.phonepe.app");49 // cap.setCapability("appActivity", "com.google.android.apps.nbu.paisa.user.applock.ui.AppLockVerificationActivity");50 cap.setCapability("appActivity", "com.phonepe.app.ui.activity.Navigator_MainActivity");51 52 53 // Activity act = new Activity("com.google.android.apps.nbu.paisa.user","com.google.android.apps.nbu.paisa.user.applock.ui.AppLockVerificationActivity"); 54 URL url = new URL("http://127.0.0.1:4723/wd/hub");55 56 mDriver = new AndroidDriver(url, cap);57 58 mDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);59 System.out.println("Hello");60 System.out.println("Hello....Hiiii");61 System.out.println("Bye");62 Thread.sleep(3000);63 System.out.println(mDriver.getContext());64 mDriver.findElementByXPath("//*[@text='Recharge']").click();65 Thread.sleep(3000);66 System.out.println(mDriver.getContext());67 68 69 //StartsActivity startsActivity = new StartsActivity();70 // Activity activity = new Activity("com.phonepe.app", "com.phonepe.app.v4.nativeapps.rechargeandbillpayment.ui.activity.Navigator_BillProviderActivity"); 71 // ((AndroidDriver) mDriver).startActivity(activity);72 73 // startsActivity.startActivity(activity); 74 mDriver.findElementById("com.phonepe.app:id/tvSearch").click();75 Thread.sleep(2000);76 mDriver.findElementById("com.phonepe.app:id/et_search_box").sendKeys("8600639104");77 Thread.sleep(3000);78 String x = mDriver.findElementById("com.phonepe.app:id/tv_title").getAttribute("text");79 System.out.println(x);80 String y = mDriver.findElementById("com.phonepe.app:id/tv_title").getAttribute("name");81 82 System.out.println(y);83 //mDriver.startActivity(new Activity("com.phonepe.app", "com.phonepe.app.v4.nativeapps.rechargeandbillpayment.ui.activity.Navigator_BillProviderActivity"));...

Full Screen

Full Screen

AndroidWrappers.java

Source:AndroidWrappers.java Github

copy

Full Screen

1package wrappers;2import org.openqa.selenium.WebElement;3import io.appium.java_client.android.Activity;4import io.appium.java_client.android.AndroidDriver;5import io.appium.java_client.android.StartsActivity;6import io.appium.java_client.android.connection.ConnectionStateBuilder;7import io.appium.java_client.android.connection.HasNetworkConnection;8import io.appium.java_client.android.nativekey.AndroidKey;9import io.appium.java_client.android.nativekey.KeyEvent;10import io.appium.java_client.android.nativekey.PressesKey;11public class AndroidWrappers extends CommonWrappers {12 public boolean launchAndroidApp(String deviceName, String appPackage, String appActivity, String automationName,13 String app) {14 return launchApp("Android", deviceName, "", appPackage, appActivity, automationName, "", "", "", "", "", app,15 "", "");16 }17 public boolean launchAndroidAppInParallel(String deviceName, String udid, String appPackage, String appActivity,18 String automationName, String chromeDriverPort, String mjpegServerPort, String systemPort, String app) {19 return launchApp("Android", deviceName, udid, appPackage, appActivity, automationName, chromeDriverPort,20 systemPort, "", "", "", app, mjpegServerPort, "");21 }22 public boolean launchChromeBrowser(String deviceName, String URL) {23 return launchBrowser("Android", "Chrome", deviceName, URL, "", "", "");24 }25 public boolean launchChromeBrowserInParallel(String deviceName, String URL, String udid, String chromeDriverPort) {26 return launchBrowser("Android", "Chrome", deviceName, URL, udid, chromeDriverPort, "");27 }28 public boolean startAnAppUsingActivity(String appPackage, String appActivity) {29 try {30 ((StartsActivity) driver).startActivity(new Activity(appPackage, appActivity));31 } catch (IllegalArgumentException e) {32 e.printStackTrace();33 }34 return true;35 }36 public void showNotificationMenu() {37 ((AndroidDriver<WebElement>) driver).openNotifications();38 }39 public boolean pressEnter() {40 ((PressesKey) driver).pressKey(new KeyEvent(AndroidKey.ENTER));41 return true;42 }43 public boolean pressBack() {44 ((PressesKey) driver).pressKey(new KeyEvent(AndroidKey.BACK));45 return true;46 }47 public void hideNotificationMenu() {48 pressBack();49 }50 public void toggleLocationServices() {51 ((AndroidDriver<WebElement>) driver).toggleLocationServices();52 }53 public boolean WiFiOffInAndroid() {54 ((HasNetworkConnection) driver).setConnection(new ConnectionStateBuilder().withAirplaneModeEnabled().build());55 return true;56 }57 public boolean WiFiOnInAndroid() {58 ((HasNetworkConnection) driver).setConnection(new ConnectionStateBuilder().withWiFiEnabled().build());59 return true;60 }61 public String getCurrentActivity() {62 return ((StartsActivity) driver).currentActivity();63 }64 public boolean deleteChromeCookies() {65 driver.manage().deleteAllCookies();66 return true;67 }68}...

Full Screen

Full Screen

AndroidWebDriverStub.java

Source:AndroidWebDriverStub.java Github

copy

Full Screen

...3import io.appium.java_client.LocksDevice;4import io.appium.java_client.android.HasAndroidDeviceDetails;5import io.appium.java_client.android.HasSupportedPerformanceDataType;6import io.appium.java_client.android.PushesFiles;7import io.appium.java_client.android.StartsActivity;8import io.appium.java_client.android.connection.HasNetworkConnection;9import io.appium.java_client.windows.PressesKeyCode;10import org.openqa.selenium.By;11import org.openqa.selenium.WebElement;12import org.openqa.selenium.remote.Response;13import java.time.Duration;14import java.util.*;15public class AndroidWebDriverStub extends WebDriverStub implements PressesKeyCode, HasNetworkConnection,16 PushesFiles, StartsActivity, FindsByAndroidUIAutomator,17 HasAndroidDeviceDetails, HasSupportedPerformanceDataType, LocksDevice {18 @Override19 public void get(String s) {20 }21 @Override22 public String getCurrentUrl() {23 return "";24 }25 @Override26 public String getTitle() {27 return "";28 }29 @Override30 public List<WebElement> findElements(By by) {...

Full Screen

Full Screen

AndroidNativeWrappers.java

Source:AndroidNativeWrappers.java Github

copy

Full Screen

1package wrappers;2import org.openqa.selenium.WebElement;3import io.appium.java_client.android.Activity;4import io.appium.java_client.android.AndroidDriver;5import io.appium.java_client.android.StartsActivity;6import io.appium.java_client.android.connection.ConnectionStateBuilder;7import io.appium.java_client.android.connection.HasNetworkConnection;8import io.appium.java_client.android.nativekey.AndroidKey;9import io.appium.java_client.android.nativekey.KeyEvent;10import io.appium.java_client.android.nativekey.PressesKey;11public class AndroidNativeWrappers extends CommonWebWrappers {12 public boolean launchAndroidApp(String deviceName, String appPackage, String appActivity, String automationName,13 String app) {14 return launchApp("Android", deviceName, "", appPackage, appActivity, automationName, "", "", "", "", "", app,15 "", "");16 }17 public boolean launchAndroidAppInParallel(String deviceName, String udid, String appPackage, String appActivity,18 String automationName, String chromeDriverPort, String mjpegServerPort, String systemPort, String app) {19 return launchApp("Android", deviceName, udid, appPackage, appActivity, automationName, chromeDriverPort,20 systemPort, "", "", "", app, mjpegServerPort, "");21 }22 public boolean startAnAppUsingActivity(String appPackage, String appActivity) {23 try {24 ((StartsActivity) driver).startActivity(new Activity(appPackage, appActivity));25 } catch (IllegalArgumentException e) {26 e.printStackTrace();27 }28 return true;29 }30 public boolean pressEnter() {31 ((PressesKey) driver).pressKey(new KeyEvent(AndroidKey.ENTER));32 return true;33 }34 public boolean pressBack() {35 ((PressesKey) driver).pressKey(new KeyEvent(AndroidKey.BACK));36 return true;37 }38 public void showNotificationMenu() {39 ((AndroidDriver<WebElement>) driver).openNotifications();40 }41 public void hideNotificationMenu() {42 pressBack();43 }44 public void toggleLocationServices() {45 ((AndroidDriver<WebElement>) driver).toggleLocationServices();46 }47 public boolean dataOffInAndroid() {48 ((HasNetworkConnection) driver).setConnection(new ConnectionStateBuilder().withAirplaneModeEnabled().build());49 return true;50 }51 public boolean dataOnInAndroid() {52 ((HasNetworkConnection) driver).setConnection(new ConnectionStateBuilder().withWiFiEnabled().build());53 ((HasNetworkConnection) driver).setConnection(new ConnectionStateBuilder().withDataEnabled().build());54 return true;55 }56 public String getCurrentActivity() {57 return ((StartsActivity) driver).currentActivity();58 }59}...

Full Screen

Full Screen

AndroidCommonActions.java

Source:AndroidCommonActions.java Github

copy

Full Screen

1package com.htm.utils;2import io.appium.java_client.AppiumDriver;3import io.appium.java_client.android.AndroidDriver;4import io.appium.java_client.android.StartsActivity;5import io.appium.java_client.android.nativekey.AndroidKey;6import io.appium.java_client.android.nativekey.KeyEvent;7import io.appium.java_client.android.nativekey.PressesKey;8/**9 * This class contains all the common method for Android driver.10 * @author Bharat Puri11 *12 */13@SuppressWarnings("deprecation")14public class AndroidCommonActions {15 @SuppressWarnings("rawtypes")16 public static AndroidDriver androidDriver;17 18 @SuppressWarnings({ "rawtypes" })19 public void pressBackButton(AppiumDriver consumerMobileDriver){20 // ((PressesKey) consumerMobileDriver).pressKeyCode(AndroidKeyCode.BACK);21 22 }23 24 25 @SuppressWarnings({ "rawtypes" })26 public void homeScreen(AppiumDriver consumerMobileDriver){27 //((PressesKey) consumerMobileDriver).pressKeyCode(AndroidKeyCode.HOME);28 29 }30 31 @SuppressWarnings("rawtypes")32 public void getBackToCurrentActivity(AppiumDriver consumerMobileDriver){33 ((StartsActivity)consumerMobileDriver).currentActivity();34 }35 @SuppressWarnings("rawtypes")36 public void closeApp(AppiumDriver consumerMobileDriver){37 consumerMobileDriver.closeApp();38 // androidDriver.resetApp();39 40 }41 42 @SuppressWarnings("rawtypes")43 public void startApp(AppiumDriver consumerMobileDriver){44 Utils.waitInSeconds(2);45 consumerMobileDriver.launchApp();46 Utils.waitInSeconds(2);47 ...

Full Screen

Full Screen

MobileWrapper.java

Source:MobileWrapper.java Github

copy

Full Screen

...910import io.appium.java_client.AppiumDriver;11import io.appium.java_client.android.Activity;12import io.appium.java_client.android.AndroidDriver;13import io.appium.java_client.android.StartsActivity;1415public class MobileWrapper {16 17 public static AppiumDriver<WebElement> driver;18 19 //Launch App in Mobile20 public boolean launchApp(String appPackage,String appActivity,String deviceName)21 {22 boolean bValue = false;23 try24 {25 DesiredCapabilities dc = new DesiredCapabilities();26 27 dc.setCapability("appPackage", appPackage);28 dc.setCapability("appActivity", appActivity);29 dc.setCapability("deviceName", deviceName);30 dc.setCapability("platformName", "Android");31 dc.setCapability("noReset", true);32 33 driver = new AndroidDriver<WebElement>(new URL("http://0.0.0.0:4723/wd/hub"),dc);34 driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);35 Thread.sleep(5000);36 37 bValue = true;38 } 39 40 catch (Exception e) {41 42 System.out.println("Issue in launching the app>>>>"+e.getMessage());43 }44 45 return bValue;46 }4748 //Launch Browser49 public boolean launchBrowser(String browser,String deviceName,String url)50 {51 boolean bValue = false;52 try 53 {54 DesiredCapabilities dc = new DesiredCapabilities();55 56 dc.setCapability("browserName", browser);57 dc.setCapability("deviceName", deviceName);58 59 driver = new AndroidDriver<WebElement>(new URL("http://0.0.0.0:4723/wd/hub"),dc);60 driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);61 driver.manage().window().maximize();62 driver.get(url);63 Thread.sleep(5000);64 65 bValue = true;66 } 67 68 catch (Exception e) {69 System.out.println("Issue in launching the application via browser>>>>"+e.getMessage());70 }71 72 return bValue;73 }74 75 //switch from one application to another76 public void switchFromApplication(String appPackage,String appActivity)77 {78 ((StartsActivity) driver).startActivity(new Activity(appPackage,appActivity));79 }80}81 ...

Full Screen

Full Screen

StartsActivity

Using AI Code Generation

copy

Full Screen

1package appium;2import io.appium.java_client.android.AndroidDriver;3import java.net.MalformedURLException;4import java.net.URL;5import org.openqa.selenium.remote.DesiredCapabilities;6import io.appium.java_client.android.StartsActivity;7import io.appium.java_client.android.AndroidKeyCode;8public class Appium {9 public static void main(String[] args) throws MalformedURLException, InterruptedException {10 DesiredCapabilities caps = new DesiredCapabilities();11 caps.setCapability("deviceName", "Android Device");12 caps.setCapability("platformName", "Android");13 caps.setCapability("platformVersion", "7.0");14 caps.setCapability("appPackage", "com.android.calculator2");15 caps.setCapability("appActivity", "com.android.calculator2.Calculator");16 caps.setCapability("noReset", "true");

Full Screen

Full Screen

StartsActivity

Using AI Code Generation

copy

Full Screen

1package appium.java;2import io.appium.java_client.android.AndroidDriver;3import io.appium.java_client.android.AndroidElement;4import io.appium.java_client.android.StartsActivity;5import java.net.URL;6import org.openqa.selenium.remote.DesiredCapabilities;7public class AppiumJava {8 public static void main(String[] args) throws Exception {9 DesiredCapabilities capabilities = new DesiredCapabilities();10 capabilities.setCapability("deviceName", "Android Emulator");11 capabilities.setCapability("platformVersion", "4.2");12 capabilities.setCapability("platformName", "Android");13 capabilities.setCapability("appPackage", "com.android.calculator2");14 capabilities.setCapability("appActivity", "com.android.calculator2.Calculator");

Full Screen

Full Screen

StartsActivity

Using AI Code Generation

copy

Full Screen

1package com.appium;2import java.net.MalformedURLException;3import java.net.URL;4import org.openqa.selenium.remote.DesiredCapabilities;5import io.appium.java_client.android.AndroidDriver;6public class LaunchApp {7 public static void main(String[] args) throws MalformedURLException {8 DesiredCapabilities cap = new DesiredCapabilities();9 cap.setCapability("deviceName", "Redmi");10 cap.setCapability("platformName", "Android");11 cap.setCapability("platformVersion", "9");12 cap.setCapability("appPackage", "com.android.calculator2");13 cap.setCapability("appActivity", "com.android.calculator2.Calculator");

Full Screen

Full Screen

StartsActivity

Using AI Code Generation

copy

Full Screen

1StartsActivity activity = (StartsActivity) driver;2activity.startActivity(new Activity("com.example.android.apis", ".ApiDemos"));3AppiumDriver appiumDriver = (AppiumDriver) driver;4appiumDriver.launchApp();5AppiumDriver appiumDriver = (AppiumDriver) driver;6appiumDriver.launchApp();7AppiumDriver appiumDriver = (AppiumDriver) driver;8appiumDriver.launchApp();9AppiumDriver appiumDriver = (AppiumDriver) driver;10appiumDriver.launchApp();11AppiumDriver appiumDriver = (AppiumDriver) driver;12appiumDriver.launchApp();13AppiumDriver appiumDriver = (AppiumDriver) driver;14appiumDriver.launchApp();

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 methods in StartsActivity

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful