Saturday, August 17, 2019

Appium Capabilities


Appium has list of capabilities to identify the device , app, activity & browser in order to execute the scripts on the devices.

To automate the Android app, we need below capabilities:

  cap.setCapability("deviceName", "emulator-5554");
  cap.setCapability("udid", "emulator-5554");
  cap.setCapability("appActivity", "com.android.calculator2.Calculator");
  cap.setCapability("appPackage", "com.android.calculator2");
  cap.setCapability("platformName", "Android");
  cap.setCapability("platformVersion", "9.0");

Example for Android capabilities :


package practise;

import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.Test;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import utils.extentReports.ExtentTestManager;

public class FindElementsExample 
{

  static AppiumDriver<MobileElement> driver;

  @Test
 public void setup(Method method) throws InterruptedException, MalformedURLException {
 ExtentTestManager.startTest(method.getName(), "Setup Method");
 DesiredCapabilities cap = new DesiredCapabilities();
 cap.setCapability("deviceName", "emulator-5554");
 cap.setCapability("udid", "emulator-5554");
 cap.setCapability("appActivity", "com.android.calculator2.Calculator");
 cap.setCapability("appPackage", "com.android.calculator2");
 cap.setCapability("platformName", "Android");
 cap.setCapability("platformVersion", "9.0");
 driver = new AppiumDriver<MobileElement>(new URL("http://127.0.0.2:4723/wd/hub"), cap);
 driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
 driver.findElementsByAccessibilityId(using)
 driver.findElementsByAccessibilityId("1").click();

  }
}
Below are the General Appium capabilities:

Capability
Description
Values
automationName
Which automation engine to use
  • For Android - Appium (default) or Selendroid or UiAutomator2 or Espresso
  • For iOS - XCUITest for iOS

platformName
Which mobile OS platform to use
  • for Android OS - Android
  • for iOS OS - iOS
  • for Firefox OS - FirefoxOS

platformVersion
Mobile OS version 
e.g., 7.1, 4.4, 9.0
deviceName
The kind of mobile device or emulator to use
iPhone Simulator, iPad Simulator, iPhone Retina 4-inch, Android Emulator, Galaxy S4, etc.... On iOS, this should be one of the valid devices returned by instruments with instruments -s devices. On Android this capability is currently ignored, though it remains required.
app
The absolute local path or remote http URL to a .ipa file (IOS), .app folder (IOS Simulator), .apk file (Android) or .apks file (Android App Bundle), or a .zip file containing one of these (for .app, the .app folder must be the root of the zip file). Appium will attempt to install this app binary on the appropriate device first. Note that this capability is not required for Android if you specify appPackage and appActivity capabilities (see below). Incompatible with browserName
/abs/path/to/my.apk or http://myapp.com/app.ipa
browserName
Name of mobile web browser to automate. Should be an empty string if automating an app instead.
Safari' for iOS and 'Chrome', 'Chromium', or 'Browser' for Android
newCommandTimeout
How long (in seconds) Appium will wait for a new command from the client before assuming the client quit and ending the session
e.g. 60
language
anguage to set for iOS (XCUITest driver only) and Android.
e.g. fr
locale
Locale to set for iOS (XCUITest driver only) and Android. fr_CA format for iOS. CA format (country name abbreviation) for Android
e.g. fr_CA, CA
udid
Unique device identifier of the connected physical device
e.g. 1ae203187fc012g
orientation
(Sim/Emu-only) start in a certain orientation
LANDSCAPE or PORTRAIT
autoWebview
Move directly into Webview context. Default false
true, false
noReset
Don't reset app state before this session.
true, false
fullReset
Perform a complete reset.
true, false

Below are the Appium capabilities only for Android:


Capability
Description
Values
appActivity
Activity name for the Android activity you want to launch from your package. This often needs to be preceded by a . (e.g., .MainActivity instead of MainActivity). By default this capability is received from the package manifest (action: android.intent.action.MAIN , category: android.intent.category.LAUNCHER)
MainActivity, .Settings
appPackage
Java package of the Android app you want to run. By default this capability is received from the package manifest (@package attribute value)
com.example.android.myApp, com.android.settings
appWaitActivity
Activity name/names, comma separated, for the Android activity you want to wait for. By default the value of this capability is the same as for appActivity. You must set it to the very first focused application activity name in case it is different from the one which is set as appActivity if your capability has appActivity and appPackage
SplashActivity, SplashActivity,OtherActivity, *, *.SplashActivity
appWaitPackage
Java package of the Android app you want to wait for. By default the value of this capability is the same as for appActivity
com.example.android.myApp, com.android.settings
appWaitDuration
Timeout in milliseconds used to wait for the appWaitActivity to launch (default 20000)
30000
deviceReadyTimeout
Timeout in seconds while waiting for device to become ready
5
allowTestPackages
Allow to install a test package which has android:testOnly="true" in the manifest. false by default
true or false
androidInstallPath
The name of the directory on the device in which the apk will be push before install. Defaults to /data/local/tmp
e.g. /sdcard/Downloads/
adbPort
Port used to connect to the ADB server (default 5037)
5037

No comments:

Post a Comment

If any suggestions or issue, please provide