Appium-API-Device

Device

Activity

Start Activity

Start an Android activity by providing package name and activity name

Java:driver.startActivity(new Activity("com.example", "ActivityName"));
Python:self.driver.start_activity("com.example", "ActivityName");

Get Current Activity

Get the name of the current Android activity

Java:String activity = driver.currentActivity();
Python:activity = self.driver.current_activity;

Get Current Package

Get the name of the current Android package

Java:String package = driver.getCurrentPackage();
Python:package = self.driver.current_package;

Install App

Install the given app onto the device

Java:driver.installApp("/Users/johndoe/path/to/app.apk");
Python:self.driver.install_app('/Users/johndoe/path/to/app.apk');

Is App Installed

Check whether the specified app is installed on the device

Java:driver.isAppInstalled("com.example.AppName");
Python:self.driver.is_app_installed('com.example.AppName');

Launch an App

Launch an app on device

Java:driver.launchApp();
Python:self.driver.launch_app()

Background App

Send the currently running app for this session to the background

Java:driver.runAppInBackground(Duration.ofSeconds(10));
Python:self.driver.background_app(10)

Close an App

Close an app on device

Java:driver.closeApp();
Python:self.driver.close_app()

Reset App

Reset the currently running app for this session

Java:driver.resetApp();
Python:self.driver.reset()

Remove App

Remove an app from the device

Java:driver.removeApp("com.example.AppName");
Python:self.driver.remove_app('com.example.AppName');

Description
iOS tests with XCUITest can also use the mobile: removeApp method.

Get App Strings

Java:Map<String, String> appStrings = driver.getAppStringMap("en", "/path/to/file");
Python:appStrings = self.driver.app_strings("en", "/path/to/file")

End Test Coverage

Get test coverage data

Java:driver.endTestCoverage("Intent", "/path");
Python:self.driver.end_test_coverage("Intent", "/path")

Get Clipboard

Get the content of the system clipboard

Java:
driver.getClipboard(ClipboardContentType.PLAINTEXT); // get plaintext
driver.getClipboardText();

Python:
self.driver.get_clipboard()
self.driver.get_clipboard_text()

Set Clipboard

Set the content of the system clipboard

Java:
// base64Content is Base64-encoded content
driver.setClipboard("label", ClipboardContentType.PLAINTEXT, base64Content);
driver.setClipboardText("happy testing");

Python:
self.driver.set_clipboard('happy testing')
self.driver.set_clipboard_text('happy testing')

Emulate power state

Emulate power state change on the connected emulator.

Java:driver.setPowerAC(PowerACState.OFF);
Python:# Not supported

Emulate power capacity

Emulate power capacity change on the connected emulator.

Java:driver.setPowerCapacity(100);
Python:# Not supported

Push File

Place a file onto the device in a particular place

Java:driver.pushFile("/path/to/device/foo.bar", new File("/Users/johndoe/files/foo.bar"));
Python:self.driver.push_file('/path/to/device/foo.bar', 'QXJlIHlvdXIgYmVlcnMgb2theT8=');

Pull File

Retrieve a file from the device's file system

Java:byte[] fileBase64 = driver.pullFile("/path/to/device/foo.bar");
Python:file_base64 = self.driver.pull_file('/path/to/device/foo.bar');

Pull Folder

Retrieve a folder from the device's file system

Java:byte[] folder = driver.pullFolder("/path/to/device/foo.bar");
Python:folder_base64 = self.driver.pull_folder('/path/to/device/foo.bar');

Shake

Perform a shake action on the device

Java:driver.shake();
Python:self.driver.shake();

Lock

Lock the device

Java:driver.lockDevice();
Python:self.driver.lock();

Unlock

Unlock the device

Java:
driver.lockDevice();
driver.unlockDevice();

Python:
self.driver.lock();
self.driver.unlock();

Is Device Locked

Check whether the device is locked or not

Java:boolean isLocked = driver.isDeviceLocked();
Python:# Not supported

Rotate

Rotate the device in three dimensions

Java:driver.rotate(new DeviceRotation(10, 10, 10));
Python:# Not supported

Press Key Code

Press a particular key on the device

Java:driver.pressKeyCode(AndroidKeyCode.SPACE, AndroidKeyMetastate.META_SHIFT_ON);
Python:self.driver.press_keycode(10);

Long Press Key Code

Press and hold a particular key code on the device

Java:driver.longPressKeyCode(AndroidKeyCode.HOME);
Python:self.driver.long_press_keycode(10);

Hide Keyboard

Hide soft keyboard

Java:driver.hideKeyboard();
Python:self.driver.hide_keyboard()

Is Keyboard Shown

Whether or not the soft keyboard is shown

Java:boolean isKeyboardShown = driver.isKeyboardShown();
Python:# Not supported

Toggle Airplane Mode

Toggle airplane mode on device

Java:driver.toggleAirplaneMode();
Python:# Not supported

Toggle Data

Switch the state of data service

Java:driver.toggleData();
Python:# Not supported

Toggle WiFi

Switch the state of the wifi service

Java:driver.toggleWifi();
Python:# Not supported

Toggle Location Services

Switch the state of the location service

Java:driver.toggleLocationServices();
Python:self.driver.toggle_location_services();

Send SMS

Simulate an SMS message (Emulator only)

Java:driver.sendSMS("555-123-4567", "Hey lol");
Python:# Not supported

GSM Call

Make GSM call (Emulator only)

Java:driver.makeGsmCall("5551234567", GsmCallActions.CALL);
Python:# Not supported

GSM Signal

Set GSM signal strength (Emulator only)

Java:driver.setGsmSignalStrength(GsmSignalStrength.GOOD);
Python:# Not supported

GSM Voice

Set GSM voice state (Emulator only)

Java:driver.setGsmVoice(GsmVoiceState.HOME);
Python:# Not supported

Get Performance Data

Returns the information of the system state which is supported to read as like cpu, memory, network traffic, and battery

Java:List<List

posted @ 2019-03-07 09:02  bamboo233  阅读(1202)  评论(0)    收藏  举报