🚀 Mobile Device Command and Interaction Tool Documentation
This project aims to provide a flexible and reliable automation testing framework for mobile devices, supporting operations through accessibility locators (preferred) and coordinate-based input. Users can choose different positioning methods according to actual needs to achieve a seamless automation process.
📄 Command List and Description
mobile_list_apps
- Description: List all installed applications on the device.
- Parameters:
bundleId(string): The unique package/identifier of the application, e.g.,com.google.android.keeporcom.apple.mobilenotes.
mobile_launch_app
- Description: Launch the specified application on the device or emulator.
- Parameters:
bundleId(string): The unique package/identifier of the application, e.g.,com.google.android.keeporcom.apple.mobilenotes.
mobile_terminate_app
- Description: Terminate the running application.
- Parameters:
packageName(string): Callam force stopbased on the application's package/identifier or directly terminate the process.
mobile_get_screen_size
- Description: Get the resolution of the device screen in pixels.
- Parameters: None
mobile_click_on_screen_at_coordinates
- Description: Click at the specified screen coordinates.
- Parameters:
x(number): The X coordinatey(number): The Y coordinate
mobile_list_elements_on_screen
- Description: List all elements on the screen and their coordinates, including the displayed text or accessibility labels.
- Parameters: None
mobile_element_tap
- Description: Click the specified UI element according to the accessibility locator.
- Parameters:
element(string): A human-readable description of the element (e.g., "Login button").ref(string): The accessibility/automation ID or the reference obtained from the snapshot.
mobile_tap
- Description: Click at the specified screen coordinates.
- Parameters:
x(number): The X coordinatey(number): The Y coordinate
mobile_press_button
- Description: Press the hardware button on the device (e.g., Home, Back, Volume, Enter, etc.).
- Parameters: None
mobile_open_url
- Description: Open the specified URL in the device browser.
- Parameters:
url(string): The URL address to open, e.g.,https://example.com.
mobile_type_text
- Description: Input text into the focused element (such as TextField, SearchField).
- Parameters:
text(string): The text to inputsubmit(boolean): Whether to press the Enter key after input
mobile_element_swipe
- Description: Swipe from one UI element to another.
- Parameters:
startElement(string): A human-readable description of the starting elementstartRef(string): The accessibility/automation ID of the starting elementendElement(string): A human-readable description of the ending elementendRef(string): The accessibility/automation ID of the ending element
mobile_swipe
- Description: Perform a swipe operation between two coordinate points.
- Parameters:
startX(number): The starting X coordinatestartY(number): The starting Y coordinateendX(number): The ending X coordinateendY(number): The ending Y coordinate
mobile_press_and_hold
- Description: Long-press the screen at the specified position.
- Parameters:
x(number): The X coordinatey(number): The Y coordinateduration(number): The duration of the long-press in milliseconds
mobile_drag_and_drop
- Description: Drag an element from one position to another.
- Parameters:
fromX(number): The X coordinate of the starting point of the dragfromY(number): The Y coordinate of the starting point of the dragtoX(number): The X coordinate of the ending point of the dragtoY(number): The Y coordinate of the ending point of the drag
mobile_scroll
- Description: Perform a scroll operation on the screen.
- Parameters:
direction(string): The scroll direction, optional values are:up,down,left,right
mobile_get_text
- Description: Get the text content of the specified element.
- Parameters:
elementRef(string): The accessibility/automation ID of the element
mobile_set_text
- Description: Set the text content of the specified element.
- Parameters:
elementRef(string): The accessibility/automation ID of the elementtext(string): The text content to set
mobile_clear_text
- Description: Clear the text content in the input box.
- Parameters:
elementRef(string): The accessibility/automation ID of the input box element
mobile_click_element_by_text
- Description: Click the specified UI element according to the text content.
- Parameters:
text(string): The text content displayed by the elementpartialMatch(boolean, optional): Whether to allow partial matching, default isfalse
mobile_click_element_by_content_description
- Description: Click the specified UI element according to the content description.
- Parameters:
contentDescription(string): The content description of the elementpartialMatch(boolean, optional): Whether to allow partial matching, default isfalse
mobile_wait_for_element
- Description: Wait for the specified element to appear (e.g., wait for the page to finish loading).
- Parameters:
elementRef(string): The accessibility/automation ID of the elementtimeout(number, optional): The waiting timeout in milliseconds, default is30000
mobile_take_screenshot
- Description: Take a screenshot of the screen and save it.
- Parameters:
filename(string, optional): The name of the file to save, default is automatically generated.
mobile_device_time
- Description: Get the current time of the device.
- Parameters: None
mobile_set_volume
- Description: Adjust the device volume.
- Parameters:
volumeLevel(number): The volume level, ranging from0to1.0
mobile_toggle_airplane_mode
- Description: Turn on or off airplane mode.
- Parameters: None
mobile_check_wifi_connection
- Description: Check if the device is connected to a Wi-Fi network.
- Parameters:
ssid(string, optional): The Wi-Fi SSID to checktimeout(number, optional): The waiting timeout in seconds, default is30
mobile_connect_to_wifi
- Description: Connect to the specified Wi-Fi network.
- Parameters:
ssid(string): The Wi-Fi SSID to connect topassword(string, optional): The Wi-Fi password
mobile_disconnect_WIFI
- Description: Disconnect the current Wi-Fi connection.
- Parameters: None
mobile_check_network_connection
- Description: Check the network connection status of the device (including mobile data and Wi-Fi).
- Parameters:
networkType(string, optional): The network type to check, optional values are:wifi,mobile
mobile_set_geolocation
- Description: Set the geographical location information of the device (suitable for simulated positioning scenarios).
- Parameters:
latitude(number): The latitudelongitude(number): The longitudealtitude(number, optional): The altitude, default is0
mobile_unset_geolocation
- Description: Restore the default geographical location information of the device.
- Parameters: None
mobile_back_to_home_screen
- Description: Return to the home screen.
- Parameters: None
mobile_launch_app
- Description: Launch the specified application.
- Parameters:
packageName(string): The package name of the applicationactivityName(string, optional): The name of the Activity to launch, default is the default launch page of the application
mobile_close_app
- Description: Close the current application.
- Parameters:
packageName(string): The package name of the application
mobile_clear_app_data
- Description: Clear the data and cache of the application.
- Parameters:
packageName(string): The package name of the application
mobile_install_apk
- Description: Install an APK file on the device.
- Parameters:
apkPath(string): The path of the APK filewaitTime(number, optional): The waiting time after installation in seconds, default is5
mobile_uninstall_apk
- Description: Uninstall the specified application.
- Parameters:
packageName(string): The package name of the application
mobile_push_file
- Description: Push a file to the device.
- Parameters:
localFilePath(string): The local file pathremoteFileName(string, optional): The file name on the device, default is the same as the local file name
mobile_pull_file
- Description: Pull the specified file from the device to the local.
- Parameters:
remoteFileName(string): The file path on the devicelocalSavePath(string, optional): The local save path, default is the current working directory
mobile_logcat_clear
- Description: Clear the logcat logs of the device.
- Parameters: None
mobile_logcat_dump
- Description: Export the logcat logs of the device to a file.
- Parameters:
filename(string, optional): The name of the log file to save, default is automatically generated.
mobile_input_text
- Description: Input text into the input box (similar to the sendKeys operation).
- Parameters:
elementRef(string): The accessibility/automation ID of the input box elementtext(string): The text content to input
mobile_input_number
- Description: Input a numerical value into the number input box.
- Parameters:
elementRef(string): The accessibility/automation ID of the number input box elementnumberValue(number): The numerical value to input
mobile_switch_to_webview
- Description: Switch to the WebView window (suitable for hybrid applications).
- Parameters:
webViewIndex(number, optional): The index of the WebView to switch to, default is the first WebView
mobile_switch_to_native
- Description: Switch back to the Native elements (suitable for hybrid applications).
- Parameters: None
mobile_get_current_context
- Description: Get the current context (Native or WebView).
- Parameters:
result(string): The type of the current context, the return value is:NATIVE,WEBVIEW
mobile_wait_for_element_text
- Description: Wait for the text content of the specified element to appear.
- Parameters:
elementRef(string): The accessibility/automation ID of the elementexpectedText(string): The expected text contenttimeout(number, optional): The waiting timeout in milliseconds, default is30000
mobile_compare_element_text
- Description: Compare whether the current text content of the specified element is consistent with the expected text.
- Parameters:
elementRef(string): The accessibility/automation ID of the elementexpectedText(string): The expected text contentignoreCase(boolean, optional): Whether to ignore case, default isfalse
mobile_is_element_present
- Description: Check if the specified element exists.
- Parameters:
elementRef(string): The accessibility/automation ID of the elementresult(boolean): Returnstrueif it exists, otherwisefalse
mobile_is_element_enabled
- Description: Check if the specified element is enabled (clickable).
- Parameters:
elementRef(string): The accessibility/automation ID of the elementresult(boolean): Returnstrueif enabled, otherwisefalse
mobile_is_element_selected
- Description: Check if the specified element is selected (e.g., RadioButton, CheckBox, etc.).
- Parameters:
elementRef(string): The accessibility/automation ID of the elementresult(boolean): Returnstrueif selected, otherwisefalse
mobile_is_element_displayed
- Description: Check if the specified element is visible.
- Parameters:
elementRef(string): The accessibility/automation ID of the elementresult(boolean): Returnstrueif visible, otherwisefalse
mobile_element_attribute
- Description: Get the value of a certain attribute of the specified element.
- Parameters:
elementRef(string): The accessibility/automation ID of the elementattributeName(string): The name of the attribute to getresult(string): The value corresponding to the attribute
mobile_element_text
- Description: Get the text content of the specified element.
- Parameters:
elementRef(string): The accessibility/automation ID of the elementresult(string): The text content
mobile_set_value
- Description: Set the value in the input box (similar to the sendKeys operation).
- Parameters:
elementRef(string): The accessibility/automation ID of the input box elementvalue(string): The text content to set
mobile_press_element
- Description: Perform a click operation on the specified element.
- Parameters:
elementRef(string): The accessibility/automation ID of the elementtimes(number, optional): The number of clicks, default is1
mobile_long_press_element
- Description: Perform a long-press operation on the specified element.
- Parameters:
elementRef(string): The accessibility/automation ID of the elementduration(number, optional): The duration of the long-press in milliseconds, default is500
mobile_swipe_element
- Description: Perform a swipe operation on the specified element (left or right).
- Parameters:
elementRef(string): The accessibility/automation ID of the elementdirection(string): The swipe direction, optional values are:LEFT,RIGHTdistance(number, optional): The distance of the swipe, default is half of the element's width
mobile_drag_element
- Description: Perform a drag operation on the specified element.
- Parameters:
elementRef(string): The accessibility/automation ID of the elementtargetElementRef(string, optional): The accessibility/automation ID of the target element to drag to, default is null, indicating dragging to the center of the screenduration(number, optional): The duration of the drag operation in milliseconds, default is500
mobile_scroll_element
- Description: Perform a scroll operation on the specified element.
- Parameters:
elementRef(string): The accessibility/automation ID of the elementdirection(string): The scroll direction, optional values are:UP,DOWN,LEFT,RIGHTsteps(number, optional): The number of scroll steps, default is1
mobile_pinch_element
- Description: Perform a pinch operation on the specified element.
- Parameters:
elementRef(string): The accessibility/automation ID of the elementscaleFactor(number, optional): The scaling factor for pinching, ranging from(0,1), default is0.5duration(number, optional): The duration of the operation in milliseconds, default is500
mobile_zoom_element
- Description: Perform a zoom operation on the specified element.
- Parameters:
elementRef(string): The accessibility/automation ID of the elementscaleFactor(number, optional): The scaling factor for zooming, ranging from(0,1)or(1, infinity), default is2duration(number, optional): The duration of the operation in milliseconds, default is500
mobile_rotate_element
- Description: Perform a rotation operation on the specified element.
- Parameters:
elementRef(string): The accessibility/automation ID of the elementdegrees(number, optional): The rotation angle, ranging from-180to180, default is90duration(number, optional): The duration of the operation in milliseconds, default is500
mobile_tap_coordinates
- Description: Perform a click operation at the specified coordinate position.
- Parameters:
x(number): The x coordinate of the clicky(number): The y coordinate of the click
mobile_tap_elements
- Description: Perform a click operation on a group of elements, clicking each element in sequence.
- Parameters:
elements(array): An array of the accessibility/automation IDs of the elementssimultaneous(boolean, optional): Whether to click simultaneously, default isfalse
mobile_long_tap_coordinates
- Description: Perform a long-press operation at the specified coordinate position.
- Parameters:
x(number): The x coordinate of the long-pressy(number): The y coordinate of the long-pressduration(number, optional): The duration of the long-press in milliseconds, default is500
mobile_swipe_coordinates
- Description: Perform a swipe operation at the specified coordinate position.
- Parameters:
startX(number): The x coordinate of the starting pointstartY(number): The y coordinate of the starting pointendX(number): The x coordinate of the ending pointendY(number): The y coordinate of the ending pointduration(number, optional): The duration of the swipe operation in milliseconds, default is500
mobile_swipe_elements
- Description: Perform a swipe operation on a group of elements, swiping each element in sequence.
- Parameters:
elements(array): An array of the accessibility/automation IDs of the elementsdirection(string, optional): The swipe direction, default isRIGHTsimultaneous(boolean, optional): Whether to swipe simultaneously, default isfalse
mobile_drag_coordinates
- Description: Perform a drag operation at the specified coordinate position.
- Parameters:
startX(number): The x coordinate of the starting point of the dragstartY(number): The y coordinate of the starting point of the dragendX(number): The x coordinate of the ending point of the dragendY(number): The y coordinate of the ending point of the dragduration(number, optional): The duration of the drag operation in milliseconds, default is500
mobile_drag_elements
- Description: Perform a drag operation on a group of elements, dragging each element in sequence.
- Parameters:
startElements(array): An array of the accessibility/automation IDs of the starting elementsendElements(array): An array of the accessibility/automation IDs of the ending elementssimultaneous(boolean, optional): Whether to drag simultaneously, default isfalse
mobile_pinch_coordinates
- Description: Perform a pinch operation at the specified coordinate position.
- Parameters:
startX(number): The x coordinate of the starting pointstartY(number): The y coordinate of the starting pointendX(number): The x coordinate of the ending pointendY(number): The y coordinate of the ending pointscaleFactor(number, optional): The scaling factor, default is0.5duration(number, optional): The duration of the operation in milliseconds, default is500
mobile_pinch_elements
- Description: Perform a pinch operation on a group of elements, pinching each element in sequence.
- Parameters:
elements(array): An array of the accessibility/automation IDs of the elementssimultaneous(boolean, optional): Whether to pinch simultaneously, default isfalse
mobile_zoom_coordinates
- Description: Perform a zoom operation at the specified coordinate position.
- Parameters:
x(number): The x coordinate of the zoomy(number): The y coordinate of the zoomscaleFactor(number, optional): The scaling factor, default is2duration(number, optional): The duration of the operation in milliseconds, default is500
mobile_zoom_elements
- Description: Perform a zoom operation on a group of elements, zooming each element in sequence.
- Parameters:
elements(array): An array of the accessibility/automation IDs of the elementssimultaneous(boolean, optional): Whether to zoom simultaneously, default isfalse
mobile_rotate_coordinates
- Description: Perform a rotation operation at the specified coordinate position.
- Parameters:
x(number): The x coordinate of the rotationy(number): The y coordinate of the rotationdegrees(number, optional): The rotation angle, default is90duration(number, optional): The duration of the operation in milliseconds, default is500
mobile_rotate_elements
- Description: Perform a rotation operation on a group of elements, rotating each element in sequence.
- Parameters:
elements(array): An array of the accessibility/automation IDs of the elementsdegrees(number, optional): The rotation angle, default is90simultaneous(boolean, optional): Whether to rotate simultaneously, default isfalse
Notes:
- Keep the parameter names, types, and default values consistent with the examples, especially the handling of boolean parameters such as
simultaneous. - For each operation function, ensure that the format and data type of the input parameters are correct, and perform necessary parameter validation.
- Add more comments if necessary to explain complex functions or special cases.
Examples:
// Example: Use the mobile_tap_elements function to click two elements in sequence
var elements = ["element1", "element2"];
mobile_tap_elements(elements, true);
Task:
Write a JavaScript function library to implement various operations on the mobile device screen, including clicking, long-pressing, swiping, dragging, zooming, and rotating. Each function should support specifying coordinates or elements and be able to handle multiple operations simultaneously.
Requirements:
- Each function should have a clear functional description and provide examples.
- Keep the parameter names, types, and default values unified, especially the handling of boolean parameters such as
simultaneous. - Perform necessary parameter validation to ensure the correct format and data type of the input.
- Add comments to explain complex functions or special cases.
Example:
// Example: Use the mobile_tap_elements function to click two elements in sequence
var elements = ["element1", "element2"];
mobile_tap_elements(elements, true);
Solution:
// mobile_operations.js
// Define operation type constants
const OPERATION_TYPE = {
TAP: 'tap',
LONG_TAP: 'longTap',
SWIPE: 'swipe',
DRAG: 'drag',
PINCH: 'pinch',
ZOOM: 'zoom',
ROTATE: 'rotate'
};
// Operation executor
class MobileOperations {
constructor() {
this.operations = [];
}
// Add an operation
addOperation(type, params) {
this.operations.push({ type, params });
return this;
}
// Execute all operations
execute(simultaneous = false) {
if (simultaneous) {
// Execute all operations simultaneously
this.operations.forEach(op => this.executeOperation(op.type, op.params));
} else {
// Execute all operations sequentially
this.operations.forEach(op => this.executeOperation(op.type, op.params));
}
return this;
}
// Execute a single operation
executeOperation(type, params) {
switch (type) {
case OPERATION_TYPE.TAP:
this.mobile_tap(params);
break;
case OPERATION_TYPE.LONG_TAP:
this.mobile_long_tap(params);
break;
case OPERATION_TYPE.SWIPE:
this.mobile_swipe(params);
break;
case OPERATION_TYPE.DRAG:
this.mobile_drag(params);
break;
case OPERATION_TYPE.PINCH:
this.mobile_pinch(params);
break;
case OPERATION_TYPE.ZOOM:
this.mobile_zoom(params);
break;
case OPERATION_TYPE.ROTATE:
this.mobile_rotate(params);
break;
default:
throw new Error('Unknown operation type');
}
}
// Tap operation
mobile_tap(params) {
const { x, y } = params;
// Tap on the screen
if (typeof x!== 'number' || typeof y!== 'number') {
throw new Error('x and y must be numbers');
}
console.log(`Tap at coordinates (${x}, ${y})`);
}
// Long-tap operation
mobile_long_tap(params) {
const { x, y, duration = 500 } = params;
// Long-tap on the screen for a specified duration
if (typeof x!== 'number' || typeof y!== 'number') {
throw new Error('x and y must be numbers');
}
console.log(`Long-tap at coordinates (${x}, ${y}) for ${duration} milliseconds`);
}
// Swipe operation
mobile_swipe(params) {
const { start, end, duration = 500 } = params;
// Swipe from the starting point to the ending point
if (typeof start.x!== 'number' || typeof start.y!== 'number') {
throw new Error('start must have x and y coordinates');
}
if (typeof end.x!== 'number' || typeof end.y!== 'number') {
throw new Error('end must have x and y coordinates');
}
console.log(`Swipe from (${start.x}, ${start.y}) to (${end.x}, ${end.y})`);
}
// Drag operation
mobile_drag(params) {
const { start, end, duration = 500 } = params;
// Drag from the starting point to the ending point
if (typeof start.x!== 'number' || typeof start.y!== 'number') {
throw new Error('start must have x and y coordinates');
}
if (typeof end.x!== 'number' || typeof end.y!== 'number') {
throw new Error('end must have x and y coordinates');
}
console.log(`Drag from (${start.x}, ${start.y}) to (${end.x}, ${end.y})`);
}
// Pinch operation
mobile_pinch(params) {
const { points, scale = 0.5, duration = 500 } = params;
// Perform a pinch operation on the specified points
if (!Array.isArray(points) || points.length!== 2) {
throw new Error('points must be an array of two points');
}
console.log(`Perform a pinch operation on points ${JSON.stringify(points)} with a scaling factor of ${scale}`);
}
// Zoom operation
mobile_zoom(params) {
const { x, y, scale = 2, duration = 500 } = params;
// Perform a zoom operation at the specified position
if (typeof x!== 'number' || typeof y!== 'number') {
throw new Error('x and y must be numbers');
}
console.log(`Perform a zoom operation at coordinates (${x}, ${y}) with a scaling factor of ${scale}`);
}
// Rotate operation
mobile_rotate(params) {
const { x, y, degrees = 90, duration = 500 } = params;
// Perform a rotation operation at the specified position
if (typeof x!== 'number' || typeof y!== 'number') {
throw new Error('x and y must be numbers');
}
console.log(`Perform a rotation operation at coordinates (${x}, ${y}) with an angle of ${degrees} degrees`);
}
// Example of combined operations
static exampleOperations() {
const mo = new MobileOperations();
// Tap operation
mo.addOperation(OPERATION_TYPE.TAP, { x: 100, y: 200 });
// Long-tap operation
mo.addOperation(OPERATION_TYPE.LONG_TAP, { x: 300, y: 400, duration: 1000 });
// Swipe operation
mo.addOperation(OPERATION_TYPE.SWIPE, {
start: { x: 50, y: 50 },
end: { x: 250, y: 250 }
});
// Drag operation
mo.addOperation(OPERATION_TYPE.DRAG, {
start: { x: 100, y: 100 },
end: { x: 300, y: 300 }
});
return mo;
}
// Execute example operations
static executeExample() {
const operations = this.exampleOperations();
operations.execute();
}
}
// Usage example
const mobileOperations = new MobileOperations();
mobileOperations.addOperation(MobileOperations.OPERATION_TYPE.TAP, { x: 100, y: 200 });
mobileOperations.addOperation(MobileOperations.OPERATION_TYPE.LONG_TAP, { x: 300, y: 400, duration: 1000 });
mobileOperations.execute();
Solution Code
class MobileOperations {
constructor() {
this.operations = [];
}
addOperation(type, params) {
if (!this[type]) {
throw new Error('Unknown operation type');
}
this.operations.push({ type, params });
return this;
}
execute() {
for (const op of this.operations) {
this[op.type](op.params);
}
return this;
}
// Tap operation
mobile_tap(params) {
const { x, y } = params;
if (typeof x!== 'number' || typeof y!== 'number') {
throw new Error('x and y must be numbers');
}
console.log(`Tap at coordinates (${x}, ${y})`);
}
// Long-tap operation
mobile_long_tap(params) {
const { x, y, duration = 500 } = params;
if (typeof x!== 'number' || typeof y!== 'number') {
throw new Error('x and y must be numbers');
}
console.log(`Long-tap at coordinates (${x}, ${y}) for ${duration} milliseconds`);
}
// Swipe operation
mobile_swipe(params) {
const { start, end, duration = 500 } = params;
if (typeof start.x!== 'number' || typeof start.y!== 'number') {
throw new Error('start must have x and y coordinates');
}
if (typeof end.x!== 'number' || typeof end.y!== 'number') {
throw new Error('end must have x and y coordinates');
}
console.log(`Swipe from (${start.x}, ${start.y}) to (${end.x}, ${end.y})`);
}
// Drag operation
mobile_drag(params) {
const { start, end, duration = 500 } = params;
if (typeof start.x!== 'number' || typeof start.y!== 'number') {
throw new Error('start must have x and y coordinates');
}
if (typeof end.x!== 'number' || typeof end.y!== 'number') {
throw new Error('end must have x and y coordinates');
}
console.log(`Drag from (${start.x}, ${start.y}) to (${end.x}, ${end.y})`);
}
// Pinch operation
mobile_pinch(params) {
const { points, scale = 0.5, duration = 500 } = params;
if (!Array.isArray(points)) {
throw new Error('points must be an array');
}
console.log(`Perform a pinch operation with points ${JSON.stringify(points)} and a scaling factor of ${scale}`);
}
// Rotate operation
mobile_rotate(params) {
const { center, startAngle, endAngle, duration = 500 } = params;
if (typeof center.x!== 'number' || typeof center.y!== 'number') {
throw new Error('center must have x and y coordinates');
}
console.log(`Rotate from ${startAngle} degrees to ${endAngle} degrees centered at point (${center.x}, ${center.y})`);
}
// Execute example operations
static example() {
const operations = new MobileOperations()
.addOperation('mobile_tap', { x: 100, y: 200 })
.addOperation('mobile_long_tap', { x: 300, y: 400, duration: 1000 })
.addOperation('mobile_swipe', {
start: { x: 50, y: 50 },
end: { x: 250, y: 250 }
})
.addOperation('mobile_drag', {
start: { x: 100, y: 100 },
end: { x: 300, y: 300 }
})
.addOperation('mobile_pinch', {
points: [{ x: 150, y: 150 }, { x: 250, y: 250 }],
scale: 0.8
})
.addOperation('mobile_rotate', {
center: { x: 200, y: 200 },
startAngle: 0,
endAngle: 360
});
operations.execute();
}
}
// Usage example
MobileOperations.example();
Explanation
This solution defines a MobileOperations class to manage various interaction operations on mobile devices. Each operation (such as tapping, long-tapping, swiping, etc.) is encapsulated as an independent method, and these operations can be added to a queue and executed sequentially through the execute() method.
The main features include:
- Modular design: Each operation is an independent method, which is easy to maintain and expand.
- Composability: Allows users to flexibly combine different operations to achieve complex interaction logic.
- Error handling: Parameter validation is performed in each method to ensure the correctness of the input.
In this way, developers can easily build and execute various interaction operations on mobile devices.








Join Now




