1.Capabilities Introduction
You can look at the capabilities set in the previous code.
Desiredcapabilities capabilities = new Desiredcapabilities () capabilities.setcapability ("AutomationName", "Appium") ; Capabilities.setcapability ("PlatformName", "Android"); Capabilities.setcapability ("DeviceName", "Android Emulator Capabilities.setcapability ("Platformversion", "4.4.2"), Capabilities.setcapability ("app", App.getabsolutepath ( ); Capabilities.setcapability ("Apppackage", "Com.example.android.contactmanager"); Capabilities.setcapability (" Appactivity ",". Contactmanager ");
Desired capability is a JSON object that contains a set of key and value values. It is sent by the client to the server, which tells the server what capabilities (which can be understood as a capability) to expect, and then the server creates an automated session based on these capabilities.
The desiredcapabilities is located in this package:
Import Org.openqa.Selenium.remote.DesiredCapabilities
So when you use desiredcapabilities, you need to import this class first.
2. General Capabilities
. Automationname
This capability is primarily defined as a test engine. When you test on the Android platform, you need to confirm that you use the Android SDK version, if it is less than 17, you need to specify the test engine is: selendroid. If greater than or equal to 17, you need to use the engine is: Appium, the default is the Appium test engine. Specific usage code:
Desiredcapabilities caps = new desiredcapabilities (); Caps.setcapability ("Automationname", "selendroid");
Of course you can also use Appium's java-client library to set up capabilities, provided you have to import this class:
Import Io.appium.java_client.remote.MobileCapabilityType
Then set the code as follows:
Caps.setcapability (Mobilecapabilitytype.automation_name, "selendroid");
iOS does not need to do this, by default it is the Appium engine.
PlatformName
Defines the name of the test platform, typically used for mobile devices. Values are: Android, iOS, and Firefoxos. Use the following code:
Caps.setcapability ("PlatformName", "Android");
You can also set it in the same way that Java-client provides:
Caps.setcapability (Mobilecapabilitytype.platform_name, "Android");
In the process of use, please follow the actual platform to fill in.
platformversion
Test platform version, mobile device firmware version number, such as: iOS 7.1.1,9.3, etc., Android 4.4.2, 5.1.1 and so on. Setup code:
Caps.setcapability ("Platformversion", "4.4.4");
Java-client provides the Setup method:
Caps.setcapability (mobilecapabilitytype.platform_version, "4.4.4");
or please follow the actual version number to fill in.
devicename
The name of the mobile device, such as the iphone 5s, Google Nexus, etc., set the code:
Caps.setcapability ("DeviceName", "Nexus 5");
Or use Java-client to set the method:
Caps.setcapability (Mobilecapabilitytype.device_name, "Nexus 5");
app
The path to the Apple app or Android app can be either an absolute local path or a remote network path, as long as you have access. Depending on the app, Capabilities,appium will install the app to the device before starting the test. When testing Android, Apppackage and Appactivity also need to be set up and used in conjunction with the app. Apppackage and Appactivity are unique to Android capabilities, which explains the two capabilities in section 5.3.
How to set it up:
Caps.setcapability ("App", "/apps/demo/demo.apk or Http://app.com/app.ipa");
Java-client Setup mode:
Caps.setcapability (Mobilecapabilitytype.app, "/apps/demo/demo.apk or Http://app.com/app.ipa")
Browsername
If you want to test the Web app, then you need to define browsername. For Android, you might have a certain Chrome browser that sets the code:
Caps.setcapability ("Browsername", "Chrome");
Or use the Java-client setting:
Caps.setcapability (Mobilecapabilitytype.browser_name, "Chrome");
For iOS, you might want to define a safari browser
Newcommandtimeout
In order to end the Appium session, Appium sets a time to wait for the command to be sent from the client timeout. The default time is 60 seconds, if you do not set, if you need to set, the code is as follows:
Caps.setcapability ("Newcommandtimeout", "30");
Of course you can use the method settings provided by Java-client:
Caps.setcapability (Mobilecapabilitytype.new_command_timeout, "30");
In general, this does not have to be set, and remains default.
Autolaunch
Setting up a capability will automatically install the app and launch the app. The Setup code is:
Caps.setcapability ("AutoLaunch", "false");
Autowebview
If you are testing a hybrid application and want to go directly into the WebView content, then you need to set the value of this capability to true, the code is as follows:
Caps.setcapability ("Autowebview", "true");
More capabilities can refer to here:
Https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/caps.md
3.Android Exclusive Capabilities
Apppackage
Set the capability of the Android app's package name to tell Appium which app you want to run.
The Setup code is:
Caps.setcapability ("Apppackage", "Com.android.calculator2");
Of course you can also use the method settings provided by Java-client:
Caps.setcapability (Mobilecapabilitytype.app_package, "Com.android.calculator2");
appactivity
Set the activity of the app you want to run (equivalent to an interface or a Web page), such as: loginactivity, login activity, can be understood as the login interface.
The Setup code is:
Caps.setcapability ("Appactivity", "com.xxx.xxx.LoginActivity");
Or use the method settings provided by Java-client:
Caps.setcapability (mobilecapabilitytype.app_activity, "com.xxx.xxx.LoginActivity");
appwaitactivity
Set the Android activity you want to wait for, set it up in the following way:
Caps.setcapability ("Appwaitactivity", "Com.android.calculator2.Calculator");
Or
Caps.setcapability (mobilecapabilitytype.app_wait_activity, "com.android.calculator2.Calculator");
Appwaitpackage
To wait for the app's package, set the method:
Caps.setcapability ("Appwaitpackage", "com.example.android.myApp");
Unicodekeyboard
Whether to use Unicode keyboard input, if set to true, then you can enter Chinese and special characters, this is commonly used, generally set to true. The Setup code is:
Caps.setcapability ("Unicodekeyboard", "true");
Resetkeyboard
Whether to reset the keyboard to the original state, such as when you set the keyboard to the Unicode keyboard, and when the use case finishes, set Resetkeyboard to True, the keyboard resets to the original state. The Setup code is:
Caps.setcapability ("Resetkeyboard", "true");
The above only selected a few representative capability, more capability please refer to:
Https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/caps.md
Four Android capabilities Explained