The latest and most comprehensive Appium automation on the entire network: Equipment operations for common Appium operations

Basic equipment operation

Preconditions:

Sample code:

from appium import webdriver # Import appium driver package
# 1. Define a dictionary of DesiredCapabilities configuration
des = {
    'automationName':'app',
    'platformName':'Android', # The name of the platform, iOS, Android, FirefoxOS
    'platformVersion':'6.0.1', # Fill in the system version number of the android virtual machine/real machine
    'deviceName':'MuMu', # Fill in the device name of the Android virtual machine/real machine
    'appPackage':'com.sky.jisuanji', # Fill in the package name of the app under test
    'appActivity':'.JisuanjizixieActivity', # Fill in the Activity entry of the app under test
    'udid':'127.0.0.1:7555', # Fill in the udid viewed through the command line adb devices
    'noReset':True, # Whether to not reset the APP
    'noSign':True, # Whether not to sign
    'unicodeKeyboard':True, # Whether to support Chinese input
    'resetKeyboard':True, # Whether to support resetting the keyboard
       }

# 2. Send the configured dictionary to the appium server as a request parameter
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub',des)

1. lock(self,seconds): lock screen operation, seconds sets the lock screen duration

# Lock screen operation
driver.lock(3) # Lock screen duration 3s ==> Cross-over event: If you test a video live broadcast, whether the live broadcast can continue after locking the screen and opening it again
time.sleep(2)
print(driver.is_locked()) # is_locked() determines whether the screen is locked and returns a Boolean value

2. unlock(self): unlock operation

# Unlock operation
driver.unlock()
print(driver.is_locked())

3. is_locked(self): Determine whether the screen is locked, and return True when the screen is locked.

# Lock screen operation
driver.lock(3) 
time.sleep(2)
# Determine whether the screen is locked. The lock screen status returns True.
print(driver.is_locked()) # is_locked() determines whether the screen is locked and returns a Boolean value

4. open_notifications(self): Open the notification bar

#Open notification bar operation
time.sleep(2)
driver.open_notifications()

5. driver.orientation='LANDSCAPE': Switch to horizontal screen operation, PORTRAIT: Switch to vertical screen operation, you can also get the current screen status through driver.orientation

# Switch between horizontal and vertical screen operations
print(driver.orientation) # Get the horizontal and vertical screen status of the current screen
time.sleep(2)
driver.orientation = 'LANDSCAPE' # Set horizontal screen
time.sleep(2)
driver.orientation = 'PORTRAIT' # Set vertical screen

6. get_window_size(self,windowHandle='current'): Gets the resolution of the current screen by default and returns the dictionary {'width':,'height':}

# Get the resolution of the current screen by default and return the dictionary {'width':,'height':}
print(driver.get_window_size())

7. network_connection: Get the network status and return an integer number

0 (No connection) Stateless
1(Airplane Mode) Airplane Mode
2(Wifi only) Only open wifi mode
4(Data only) Turn on data traffic mode only
6(All network on) Turn on all (including wifi and data traffic mode)

print(driver.network_connection) # Get network status

8. set_network_connection(self, connection_type): Set the network status, use numbers or import the ConnectionType class for parameter setting

# Set network status
# Method 1: Use digital parameter settings to set 0, 1, 2, 4, 6
driver.set_network_connection(1)
time.sleep(5)
#Method 2: Import the ConnectionType class for parameter setting
from appium.webdriver.connectiontype import ConnectionType
driver.set_network_connection(ConnectionType.ALL_NETWORK_ON)

9. save_screenshot(self,filename): Screenshot operation, filename is the saved file path, and the image format is set to png format.

# Screenshot operation
time.sleep(2)
driver.save_screenshot('C:/Users/Jeff/Desktop/123.png')

10. get_device_time(self, format=None): Get the current time of the device, format is the date and time format setting, the default is 'YYYY-MM-DDTHH:mm:ssZ'

# Get the current time of the device, the default format is 'YYYY-MM-DDTHH:mm:ssZ'
print(driver.get_device_time())

  Recommended tutorials related to automated testing:

The latest automated testing self-study tutorial in 2023 is the most detailed tutorial for newbies to get started in 26 days. Currently, more than 300 people have joined major companies by studying this tutorial! ! _bilibili_bilibili

2023 latest collection of Python automated test development framework [full stack/practical/tutorial] collection essence, annual salary after learning 40W+_bilibili_bilibili

Recommended tutorials related to test development

The best in the entire network in 2023, the Byte test and development boss will give you on-site teaching and teach you to become a test and development engineer with an annual salary of one million from scratch_bilibili_bilibili

postman/jmeter/fiddler test tool tutorial recommendation

The most detailed collection of practical tutorials on JMeter interface testing/interface automated testing projects. A set of tutorials for learning jmeter interface testing is enough! ! _bilibili_bilibili

To teach yourself how to capture packets with fiddler in 2023, please be sure to watch the most detailed video tutorial on the Internet [How to Learn to Capture Packets with Fiddler in 1 Day]! ! _bilibili_bilibili

In 2023, the whole network will be honored. The most detailed practical teaching of Postman interface testing at Station B can be learned by novices_bilibili_bilibili

  Summarize:

 Optical theory is useless. You must learn to follow along and practice it in order to apply what you have learned to practice. At this time, you can learn from some practical cases.

If it is helpful to you, please like and save it to give the author an encouragement. It also makes it easier for you to search quickly next time.

If you don’t understand, please consult the small card below. The blogger also hopes to learn and improve with like-minded testers.

At the appropriate age, choose the appropriate position and try to give full play to your own advantages.

My path to automated test development is inseparable from plans at each stage, because I like planning and summarizing.

Test development video tutorials and study notes collection portal! !

Guess you like

Origin blog.csdn.net/m0_59868866/article/details/134815529
Recommended