Appium (Python) API

Source: Internet
Author: User
Tags tagname appium

1.
Create a new session
Desired_caps = Desired_caps = {
' platformname ': ' Android ',
' platformversion ': ' 7.0 ',
' devicename ': ' Android Emulator ',
' automationname ': ' UiAutomator2 ',
' app ': PATH ('/path/to/app ')
}
self.driver = Webdriver. Remote (' Http://127.0.0.1:4723/wd/hub ', desired_caps)

2.
End Session
self.driver.quit ()

3.
Get Session Features
desired_caps = self.driver.desired_capabilities ()

4.
Fallback (web context only)
Self.driver.back ()

5.

screenshotBase64 = self.driver.get_screenshot_as_base64 ()

6.
Timeout

Set timeout
Self.driver.set_page_load_timeout (The)

Setting an implicit wait timeout
Self.driver.implicitly_wait (5000)

Set Script timeout
Set the amount of time,
In milliseconds,
By executing an asynchronous script,
Execute asynchronous allow to run them all immediately before aborting (web context only)
Self.driver.set_script_timeout (5000)

7.
Direction

Get positioning
Orientation = Self.driver.orientation ()

Set direction
Driver.orientation = "LANDSCAPE"

8.
Geographic substance

Get a location
Location = Self.driver.location ()

Set up a location
Self.driver.set_location (49, 123, 10)

9.
Log

Get the available log types
Log_types = Driver.log_types ()

Get logs
logs = Driver.get_log (' driver ')

10.
Set up

Update Device Settings
# Python does not support

Retrieving Device Settings
# Python does not support

11.
Activities

Start activity
self.driver.start_activity ("Com.example", "Activityname")

Get Current Activity
activity = self.driver.current_activity ()

Get Current Package
Package = Self.driver.current_package ()

12.
Application

Install the application
Self.driver.install_app ('/users/johndoe/path/to/app.apk ')

Application is installed
self.driver.is_app_installed (' com.example.AppName ')

Start the application
Self.driver.launch_app ()

Background application
Send the currently running application to the background
Self.driver.background_app (Ten)

Close the application
Self.driver.close_app ()

Resetting the application
Self.driver.reset ()

Remove an application
Self.driver.remove_app (' com.example.AppName ')

Get the application string
appstrings = self.driver.app_strings ("en", "/path/to/file")

Get test coverage Data
self.driver.end_test_coverage ("Intent", "/path")


13.
File

Push file
Self.driver.push_file ('/path/to/device/foo.bar ', ' qxjlihlvdxigymvlcnmgb2thet8= ')

Pull file
File_base64 = Self.driver.pull_file ('/path/to/device/foo.bar ')

Pull folder
Folder_base64 = Self.driver.pull_folder ('/path/to/device/foo.bar ')

14.
Action

Shaking
Self.driver.shake ()

Lock
Self.driver.lock ()

Unlock
Self.driver.unlock ()

Whether the device is locked
# Python does not support

Rotating
# Python does not support

15.
Keys

Key code
Self.driver.press_keycode (10)

Long Key Code
Self.driver.long_press_keycode (10)

Hide keyboard
Self.driver.hide_keyboard ()

Display keyboard
# Python does not support

16.
Internet

Switch Flight mode
# Python does not support

Switching Data Services
# Python does not support

Switch WiFi
# Python does not support

Toggle Status of Location Services
Self.driver.toggle_location_services ()

Analog SMS (emulator only)
# Python does not support

Call GSM phone (emulator only)
# Python does not support

Set GSM signal strength (emulator only)
# Python does not support

Set GSM voice status (emulator only)
# Python does not support

17.
Performance data

Get Performance data
Returns system state information that supports read, such as CPU, memory, network traffic, and battery
# Python does not support

Get Performance data type
# Python does not support

18.
Simulator

Perform Touch ID
Analog Touch ID event (for iOS emulator only)
self.driver.touch_id (False)
# Simulate a failed touch
self.driver.touch_id (True)
# Analog through the touch

Toggle the emulator being registered to accept touch ID (only for iOS emulator)
self.driver.toggle_touch_id_enrollment ()

19.
System

Turn on Android notifications (emulator only)
self.driver.open_notifications ()

Get System Bar
Retrieving status and navigation bar visibility and boundary information
# Python does not support

Get system time
Time = Self.driver.device_time ()

20.
Find element
el = self.driver.find_element_by_accessibility_id (' Someaccessibilityid ')

21st
Operation

Click
el = self.driver.find_element_by_accessibility_id (' Someid ')
El.click ()

Input
self.driver.find_element_by_accessibility_id (' Someaccessibilityid '). Send_keys (' Hello world! ')

Clears the value of an element
self.driver.find_element_by_accessibility_id (' Someaccessibilityid '). Clear ()

22.
Property

Get element text
el = self.driver.find_element_by_accessibility_id (' Someaccessibilityid ')
Text = El.text

Get label name
tagName = self.driver.find_element_by_accessibility_id (' Someaccessibilityid '). Tag_name

Get element properties
tagName = self.driver.find_element_by_accessibility_id (' Someaccessibilityid '). Get_attribute (' Content-desc ')

Element is selected
Determines whether a form or form class element is selected (check box, select, and so on)
self.driver.find_element_by_accessibility_id (' Someaccessibilityid '). is_selected ()

Element is enabled
determines whether an element is currently enabled
self.driver.find_element_by_accessibility_id (' Someaccessibilityid '). is_enabled ()

Get element position
Determine the position of an element on a page or screen
Location = self.driver.find_element_by_accessibility_id (' Someaccessibilityid '). location

Get element size
Determines the size of an element in pixels
size = self.driver.find_element_by_accessibility_id (' Someaccessibilityid '). Size

Get element Rectangle
Get the dimensions and coordinates of an element
# Python does not support

Get element CSS Value
Querying the value of a Web element's computed CSS property
cssproperty = self.driver.find_element_by_accessibility_id (' Someid '). Value_of_css_property ("style")

Get the position of an element in a view
Once the element is scrolled into view, determine the position of the element on the screen (primarily internal commands and not supported by all clients)
# Python does not support

23.
Submit Form
Submit a FORM Element
el = self.driver.find_element_by_accessibility_id (' Someaccessibilityid ')
El.submit ();

24.
Get active element
element = Driver.switch_to.active_element

25.
Elements are equal
# Python does not support

26.
Context

Gets the current context
context = Driver.current_context
Or
context = Driver.context

Get all contexts
contexts = driver.contexts

Setting the current context
WebView = driver.contexts[1]
Driver.switch_to.context (WebView)
# ...
driver.switch_to.context (' Native_app ')

27.
Mouse

Move the mouse to
actions = Actionchains (driver)
Actions.move_to (element, 10, 10)
Actions.perform ()

Click any mouse button in the current mouse coordinates
actions = actionchains (driver)
actions.move_to_element (Element)
Actions.click ()
Actions.perform ()

Double-click the current mouse coordinate (set by MoveTo)
actions = actionchains (driver)
actions.move_to_element (Element)
Actions.double_click ()
Actions.perform ()

Button off
Click and hold the left mouse button on the current mouse coordinate
actions = actionchains (driver)
actions.move_to_element (Element)
Actions.click_and_hold ()
Actions.perform ()

Buckle Tight
Release a previously held mouse button
actions = actionchains (driver)
actions.move_to_element (Element)
Actions.click_and_hold ()
actions.move_to_element (element, ten)
action.release ()
Actions.perform ()

28.
Touch

Click the touch device
actions = touchactions (driver)
Actions.tap (Element)
Actions.perform ()

Double click
Double-tap the touch screen with finger action events
actions = touchactions (driver)
Actions.double_tap (Element)
Actions.perform ()

Move
Finger moves on the screen
actions = touchactions (driver)
actions.tap_and_hold (Element)
Actions.move (a)
Actions.perform ()

Touch down
Finger on the screen
actions = touchactions (driver)
actions.tap_and_hold (Element)
Actions.move (a)
Actions.perform ()

Retouching (minor modifications)
Finger on the screen
actions = touchactions (driver)
Actions.tap_and_hold (a)
Actions.release (a)
Actions.perform ()

Long Press
Use finger motion events to long press the touch screen
actions = touchactions (driver)
actions.long_press (Element)
Actions.perform ()

Rolling
Use finger-based action events to scroll through the touchscreen
actions = touchactions (driver)
actions.scroll_from_element (element, ten)
Actions.scroll (Ten)
Actions.perform ()

Brushed Away
Tap the touch screen with finger motion events
actions = touchactions (driver)
actions.flick_element (element, 1, ten)
Actions.perform ()

Multi-Touch execution
Perform a multi-touch action sequence
From appium.webdriver.common.touch_action import touchaction
From appium.webdriver.common.multi_action import multiaction

a1 = touchaction ()
a1.press (Ten)
a1.move_to (Ten)
a1.release ()

A2 = touchaction ()
a2.press (Ten)
a2.move_to (Ten)
a2.release ()

ma = multiaction (self.driver)
Ma.add (A1, A2)
Ma.perform ()

Touch execution
Perform a touch action sequence
From appium.webdriver.common.touch_action import touchaction

actions = touchaction (driver)
Actions.tap_and_hold (a)
actions.move_to (Ten)
actions.release ()
Actions.perform ()

29.
Window

Switch to Window
Change focus to another window (web context only)
Self.driver.switch_to.window ("Handle")

Close window
Close the current window (web context only)
self.driver.close ()

Get Window Handle
retrieves the current window handle (web context only)
window_handle = Self.driver.current_window_handle ()

Get all window handles
Retrieves a list of all window handles available for a session (Web context only)
window_handles = self.driver.window_handles ()

Get title
Gets the current page title (Web context only)
title = Self.driver.title ()

Get window Size
Gets the size of the specified window (web context only)
handle_one_size = self.driver.get_window_size ()
handle_two_size = self.driver.get_window_size ("Handlename")

Set Window size
Change the size of the specified window (web context only)
Self.driver.set_window_size (Ten)

Get window Position
Gets the location of the specified window (web context only)
handle_one_position = self.driver.get_window_position ()
handle_two_position = self.driver.get_window_position ("Handlename")

Set Window Position
Change the location of the specified window (web context only)
Self.driver.set_window_position (Ten)

Maximize window
Maximizes the specified window (web context only)
Self.driver.maximize_window ()

30.
Navigation

Navigating to URLs
Navigate to the new URL (Web context only)
self.driver.get ("http://appium.io/")

Get URL
Retrieves the URL of the current page (Web context only)
URL = self.driver.current_url ()

Get back
If possible, browse backwards in browser history (Web context only)
Self.driver.back ()

Forward
If possible, navigate forward in the browser history (Web context only)
Self.driver.forward ()

Refresh
Refresh the current page (Web context only)
Self.driver.refresh ()

31.
Cookies

Get All Cookies
Retrieve all cookies visible on the current page (Web context only)
cookies = self.driver.get_cookies ()

Set cookies
Set a cookie (web context only)
Self.driver.add_cookie ({name: ' foo ', Value: ' Bar '})

Delete Cookies
Delete a cookie with the given name (Web context only)
Self.driver.delete_cookie ("Cookie_name")

Delete all Cookies
Delete all cookies visible on the current page (Web context only)
self.driver.delete_all_cookies ()

32.
Frame

Switch to Frame
Change focus to another frame on the page (Web context only)
Self.driver.switch_to.frame (3)

Switch to Parent frame
Change focus to Parent context (Web context only)
self.driver.switch_to.parent ()

33.
Execute Asynchronous JavaScript
inject a JavaScript fragment into the page to execute in the context of the currently selected frame (Web context only)
self.driver.execute_async_script (' Document.title ')

34.
Execute JavaScript
Inject a JavaScript fragment into the page to execute in the context of the currently selected frame (Web context only)
self.driver.execute_script (' Document.title ')

Appium (Python) API

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.