Appium-API-Device

原文链接: http://www.cnblogs.com/music378/p/10487372.html

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> performanceData = driver.getPerformanceData("my.app.package", "cpuinfo", 5);
Python:# Not supported

Get Performance Data Types

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

Java:List performanceTypes = driver.getSupportedPerformanceDataTypes();
Python:# Not supported

Start Recording Screen

Java:
driver.startRecordingScreen();
driver.startRecordingScreen(new BaseStartScreenRecordingOptions(....));

Python:
self.driver.start_recording_screen()

Stop Recording Screen

Java:
driver.stopRecordingScreen();
driver.stopRecordingScreen(new BaseStopScreenRecordingOptions(....));

Python:
self.driver.stop_recording_screen()

Perform Touch ID

Simulate a touch id event (iOS Simulator only)

Java:
driver.performTouchID(false); // Simulates a failed touch
driver.performTouchID(true); // Simulates a passing touch

Python:
self.driver.touch_id(false); # Simulates a failed touch
self.driver.touch_id(true); # Simulates a passing touch

Toggle Touch ID Enrollment

Toggle the simulator being enrolled to accept touchId (iOS Simulator only)

Java:driver.toggleTouchIDEnrollment(true);
Python:self.driver.toggle_touch_id_enrollment()

Open Notifications

Open Android notifications (Emulator only)

Java:driver.openNotifications();
Python:self.driver.open_notifications();

Get System Bars

Retrieve visibility and bounds information of the status and navigation bars

Java:Map<String, String> systemBars = driver.getSystemBars();
Python:# Not supported

Get System Time

Get the time on the device

Java:String time = driver.getDeviceTime();
Python:time = self.driver.device_time()

Finger print

Authenticate users by using their finger print scans on supported emulators.

Java:driver.fingerPrint(1);
Python:self.driver.finger_print(1)

转载于:https://www.cnblogs.com/music378/p/10487372.html

猜你喜欢

转载自blog.csdn.net/weixin_30193109/article/details/94810712