Top Appium Commands every Developer must know
On This Page What is Appium?Appium Commands Cheat Sheet
Mobile Application examination is either done manually or automatize. Open-source tools such as Appium can automate wandering application tests. What is Appium? Appium is an open-source test mechanisation puppet for try Mobile Applications. It supports various platforms, such as iOS, Android, and Windows. Categories of Important Appium Commands and Methods This article provides acheat sheet of the top Appium biddingevery developer must know. is an open-source tool for testing Mobile Applications. It supports respective platforms, such as iOS, Android, and Windows. It allows user to test respective eccentric of Mobile Applications, such as: Learn More: Appium offers. That is, a individual API deeds for both Android and iOS platforms. This means developer or testers can use the like code for all platforms. Like Appium allows examiner to write test script in different programming languages such as,, Ruby, PHP, JavaScript, and C #. Also Read: Appiumrender various commands and method for automating mobile applications across Android and iOS platforms. These dictation allow testers to interact with mobile apps like a existent exploiter. Below is a handy cheat sheet covering usually used Appium commands to race up your mobile automation workflow. Before starting with with Appium, you would need to follow these steps: 1. Ensure that theJava Libraryis installed for Appium. 2. Download and instalMavenfollowing the steps fromthe official site. 3. Import statements for several commands can be as follows. Add them to your program as per the commands in use: Here are the Basic Appium Commands in the Java version: Desired Capabilities define the properties of the mobile device and app under examination (like platform name, device name, app route, etc.). These capableness are required to part an Appium session and connect to the target gimmick or emulator. Example: Example: Example: helps in do a meshwork request to a Selenium hub to start a driver session since Appium run on the Client-Server model. It is not recommended to use the Remote WebDriver immediately. Hence, it is used with the IOS Driver and Android Driver. IOS and Android Drivers inherit from Appium Driver. They add additional use that are useful to the context of mobile mechanization on IOS and Android devices severally through Appium. In the example below, the URL is pointing to the local host. Note:You can include the URL which level to your outside web server as well here. Read More: To interact with app elements, Appium uses different locater scheme such as id, className, xpath, accessibilityId, and AndroidUIAutomator or iOSPredicateString. Learn More: Choosing the correct strategy assure honest and fast element detection. Also Read: This family includes essential action like clicking, typing, scroll, swiping, and interacting with system features (e.g., locking the device or rotating the blind). Also Read: These simulate real user behavior for robust. Pro tip: Tools like SUSA can handle this autonomously — upload your app and get results without writing a single test script. These are platform-agnostic command like trade contexts (for intercrossed apps), do multi-touch gesture, interact with notifications, or capturing device log that are important for deep functional and UI proof. Example: Example: Example: Example: Some advanced Appium methods go beyond standard WebDriver bidding. These are enforce applyExecute Methods, allowing you to trigger mobile-specific actions like unlocking a device, feign a fingerprint scan, or toggling web settings. These extended Appium methods work through the execute bid, get them compatible with any Appium or Selenium node. Example: Use Execute Methods when you need advanced control over mobile behavior not covered by default WebDriver APIs. Platform-specific commands exclusive to iOS devices, including manage biometric prompting, establish Safari, or interacting with system alarm, helpful for full iOS mechanization coverage. Example: Example: Advanced bid in Android testing provide greater control over device demeanour, let testers to simulate real-world weather and validate app responses. Below are key Appium commands for wangle device province, injecting file, simulating hardware key, and retrieving execution data: Appium also allow you install, uninstall, and readjust apps directly on iOS devices through mechanisation, saving time during repeated testing cycles. Example: Example: Example: Example: Example: Example: Example: Commands in this category allow you to install APKs, manage app permit, clear app data, and access Android-specific utilities from within your. Appium is a go-to tool for mobile automation thanks to its cross-platform support and flexibility. However, existent device testing is crucial, as emulator can ’ t replicate real-world conditions like ironware behavior, battery position, or network intermission. BrowserStack App Automateoffers a powerful program to run Appium tests on thousands of existent iOS and Android devices on their. Benefits of Testing on Existent Devices with BrowserStack: Mastering key Appium command is essential for progress efficient and dependable mobile test automation. With the right commands and real device testing on platforms like BrowserStack, developer can ensure robust app performance across device, platform, and real-world weather. Tutorials Best Practices, Tips, and Tricks Getting Started with Differences and Comparisons On This Page # Ask-and-Contributeabout this matter with our Discord community. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.Top Appium Commands every Developer must know
Overview
What is Appium?
Appium Commands Cheat Sheet
Pre-Requisites
1. Initialize Desired Capabilities
appiumLocalService = new AppiumServiceBuilder () .usingAnyFreePort () .build ();
appiumLocalService.start ();
DesiredCapabilities crest = new DesiredCapabilities (); caps.setCapability (“ automationName ”, `` XCUITest ''); caps.setCapability (“ deviceName ”, `` iPhone 13 ''); caps.setCapability (“ platformName ”, `` iOS ''); caps.setCapability (“ platformVersion ”, `` 15.6 '');
DesiredCapabilities crest = new DesiredCapabilities (); caps.setCapability (“ automationName ”, `` UiAutomator2 ''); caps.setCapability (“ deviceName ”, `` Samsung ''); caps.setCapability (“ platformName ”, `` Android ''); caps.setCapability (“ platformVersion ”, `` 7.1 '');
DesiredCapabilities caps = new DesiredCapabilities (); caps.setCapability (“ app ”, `` path/to/TestApp.app.zip '');
DesiredCapabilities cap = new DesiredCapabilities (); caps.setCapability (“ appPackage ”, `` com.android.calculator2 ''); caps.setCapability (“ appActivity ”, `` com.android.calculator2.Calculator ''); caps.setCapability (“ app ”, `` path/to/TestApp.apk '');
DesiredCapabilities cap = new DesiredCapabilities (); caps.setCapability (“ browserName ”, `` Safari '');
DesiredCapabilities caps = new DesiredCapabilities (); caps.setCapability (“ browserName ”, `` Chrome '');
driver = new IOSDriver & lt; IOSElement & gt; (appiumLocalService, caps);
driver = new AndroidDriver & lt; AndroidElement & gt; (appiumLocalService, cap);
driver.context (driver.getContextHandles () .stream () .filter (c - & gt; c.contains (`` WEBVIEW '')) .findFirst () .orElse (null));
driver = new IOSDriver & lt; IOSElement & gt; (new URL (``http: //0.0.0.0:4723/wd/hub``), caps); //This URL points to the local waiter
driver = new AndroidDriver & lt; AndroidElement & gt; (new URL (``http: //127.0.0.1:4723/wd/hub``), caps); //This URL point to the local server
2. Locator Strategies
driver.findElementById (`` android: id/button '');
driver.findElementByAccessibilityId (`` Views '');
driver.findElementByClassName (`` android.widget.CheckBox '');
driver.findElementsByClassName (`` android.widget.CheckBox '');
driver.findElementByAndroidUIAutomator (`` new UiSelector () .textContains (\ '' BUTTON\ ''); '');
driver.findElementByImage (base64EncodedImageFile);
driver.findElementByXPath (`` (//XCUIElementTypeButton) [1] '');
driver.findElementByXPath (`` // * [@ resource-id='com.example.android.apis: id/button '] '');
3. App & amp; Device Actions
driver.switchTo () .alert () .accept (); driver.switchTo () .alert () .dismiss ();
element.click (); element.clear (); element.sendKeys (`` textToType '');
driver.rotate (ScreenOrientation.LANDSCAPE);
driver.setClipboardText (`` 9876 '', `` UserText ''); String clipboard = driver.getClipboardText ();
TouchAction touchAction = new TouchAction (driver);
touchAction.tap (TapOptions.tapOptions () .withPosition (PointOption.point (x, y));
touchAction.press (PointOption.point (x, y));
touchAction.waitAction (WaitOptions .waitOptions (Duration.ofMillis (200)));
touchAction.moveTo (PointOption.point (x, y));
touchAction.longPress (PointOption.point (x, y));
touchAction.release (); touchAction.perform ();
driver.toggleAirplaneMode (); driver.toggleData (); driver.toggleLocationServices (); driver.toggleWifi ();
driver.isKeyboardShown (); // returns boolean driver.hideKeyboard ();
driver.isDeviceLocked (); // homecoming boolean driver.lockDevice (); driver.unlockDevice ();
driver.openNotifications ();
driver.pushFile (`` /data/local/tmp/file '', new File (`` path/to/file '')); driver.pullFile (`` /path/to/device/file ''); // returns byte [] driver.pullFolder (`` /path/to/device ''); // returns byte []
driver.getDeviceTime (); // returns String
4. Advanced Commands & # 8211; both iOS & amp; Android
TouchAction actionOne = new TouchAction (driver);
actionOne.press (PointOption.point (10, 10));
actionOne.moveTo (PointOption.point (10, 100));
actionOne.release ();
TouchAction actionTwo = new TouchAction (driver); actionTwo.press (PointOption.point (20, 20)); actionTwo.moveTo (PointOption.point (20, 200)); actionTwo.release (); MultiTouchAction action = new MultiTouchAction (driver); action.add (actionOne); action.add (actionTwo); action.perform ();
TouchAction touchAction = new TouchAction (driver); WebElement factor = (WebElement) driver.findElementById (`` android: id/text2 ''); Point point = element.getCoordinates () .onPage (); Dimension size = element.getSize (); touchAction.press (PointOption.point (point.getX () + 5, point.getY () + 5)) .waitAction (WaitOptions.waitOptions (Duration.ofMillis (200))) .moveTo (PointOption.point (point.getX () + size.getWidth () - 5, point.getY () + size.getHeight () - 5)) .release () .perform ();
JavascriptExecutor js = (JavascriptExecutor) driver; HashMap & lt; String, String & gt; scrollObject = new HashMap & lt; String, String & gt; (); scrollObject.put (`` direction '', `` downwards ''); // up, left, right scrollObject.put (`` element '', ((RemoteWebElement) element) .getId ()); js.executeScript (`` mobile: scroll '', scrollObject);
driver.findElementByAndroidUIAutomator (`` new UiScrollable (new UiSelector ()) .scrollIntoView (new UiSelector () .text (\ '' Views\ '')); '');
((TakesScreenshot) driver) .getScreenshotAs (OutputType.FILE); // BYTES, BASE64 – returns File, byte [] or String (base64 encoded PNG)
driver.setSetting (Setting.KEYBOARD_AUTOCORRECTION, false); driver.getSettings (); // returns Map & lt; String, Object & gt;
driver.startRecordingScreen (); driver.stopRecordingScreen();
5. Execute Methods for Extended Functionality
driver.execute ('mobile: unlock ', [{unlockType: 'pin ', unlockKey: '1234 '}]);6. Advanced Commands & # 8211; iOS
driver.shake ();
driver.pushFile (`` img.jpg '', new File (`` path to img.jpg ''));
JavascriptExecutor js = (JavascriptExecutor) driver; Map & lt; String, Object & gt; args = new HashMap & lt; & gt; (); args.put (`` schoolbook '', `` Hey Siri, what 's happening? ``); driver.executeScript (`` mobile: siriCommand '', args);
driver.performTouchID (true); // Simulates a correct touch ID driver.performTouchID (false); // Simulates a failed touch ID
JavascriptExecutor js = (JavascriptExecutor) driver; Map & lt; String, Object & gt; args = new HashMap & lt; & gt; (); args.put (`` gens '', `` home ''); // volumeup; volumedown driver.executeScript (`` mobile: pressButton '', args);
7. Advanced Commands & # 8211; Android
driver.setPowerCapacity (100);;
driver.setPowerAC (PowerACState.ON); driver.setPowerAC (PowerACState.OFF);
driver.pushFile (`` /Pictures/img.jpg '', new File (`` itinerary to img.jpg ''));
driver.pressKey (new KeyEvent () .withKey (AndroidKey.HOME)); driver.longPressKey (new KeyEvent () .withKey (AndroidKey.POWER));
driver.getPerformanceData (`` my.app.package '', `` cpuinfo '', 6); // returns List & lt; List & lt; Object & gt; & gt;
8. App Management & # 8211; iOS
args.put (`` app '', `` path/to/app.ipa ''); driver.executeScript (`` mobile: installApp '', args);
args.put (`` bundleId '', `` com.myapp ''); (boolean) driver.executeScript (`` mobile: isAppInstalled '', args);
args.put (`` bundleId '', `` com.apple.calculator ''); driver.executeScript (`` mobile: launchApp '', args);
args.put (`` bundleId '', `` com.myapp ''); driver.executeScript (`` mobile: activateApp '', args);
args.put (`` bundleId '', `` com.myapp ''); (ApplicationState) driver.executeScript (`` mobile: queryAppState '', args); // will revert false if app is not running, differently homecoming true
args.put (`` bundleId '', `` com.myapp ''); (boolean) driver.executeScript (`` mobile: terminateApp '', args); // will return false if app is not running, otherwise return true
args.put (`` bundleId '', `` com.myapp ''); driver.executeScript (`` mobile: removeApp '', args);
9. App Management & # 8211; Android
driver.installApp (`` path/to/app.apk '');
driver.isAppInstalled (`` com.example.android.apis ''); // returns bool
driver.launchApp ();
driver.startActivity (new Activity (`` com.example.android.apis '', '' .ApiDemos ''));
driver.currentActivity (); // homecoming String
driver.getCurrentPackage (); // returns String
driver.runAppInBackground (Duration.ofSeconds (10)); // Runs for 10 seconds
driver.queryAppState (`` com.example.android.apis ''); // returns Application State
driver.getAppStringMap (`` en '', `` path/to/file ''); // returns Map & lt; String, String & gt;
driver.closeApp ();
driver.resetApp ();
driver.terminateApp (`` com.example.android.apis ''); // returns bool
driver.removeApp (`` com.example.AppName '');
Test on Real Mobile Devices with BrowserStack
Conclusion
Appium Useful Resources
Related Guides
Automate This With SUSA
Test Your App Autonomously