当前位置:网站首页>Appium foundation - use the first demo of appium

Appium foundation - use the first demo of appium

2022-07-05 06:03:00 Test - Eight Precepts

We use Python Language as the writing language of test script .
Before executing the script :

  • Android The simulator or mobile phone is turned on .
  • Make sure the computer and Android The device is linked .
    That is to use ADB command adb connect Link devices ,
    Or by adb devices The command can view the device .
  • Turn on Appium service .

stay Python Development of IDE in (PyCharm) Write the following script in :

"""
1. Learning goals 
     master appium How to start the phone 
2. Operation steps 
    1- explain : Explicit drive object ( Action object )
    web Automated steps :
        1. Specifies to launch the browser 
        2. Enter url 
        3. Continue with other operations ...

    APP Automated steps :
         First pass the following message :
             System name : Android  IOS
             System version :  Version number 
             Equipment name :  adopt adb devices Command acquisition 
            APP Package name :   Open which APP
            APP Start name : Get into APP Which page 

    2- Import appium in webdriver
    3- Add startup parameters 
         Equipment information 
             System name : Android  IOS
             System version :  Version number 
             Equipment name : adb devices
        APP Information 
            APP Package name :   Open which APP
            APP Start name : Get into APP Which page 
     4- start-up app
        webdriver.Remote()
     5- operation app
     6- close app
3. demand 
     start-up Android Settings in the simulator APP
"""

# 1. Import appium
import time
from appium import webdriver

# 2. Add startup parameters 
#  Namely Desired capabilities, Is a dictionary type object .
desired_caps = {
    "platformName": "Android",  #  System name 
    "platformVersion": "7.1.2",  #  System version 
    "deviceName": "127.0.0.1:21503",  #  Equipment name 
    "appPackage": "com.android.settings",  # APP Package name 
    "appActivity": ".Settings"  # APP Start name 
}
"""
 explain :
deviceName :
    cmd Go to the command line terminal 
     Input adb connect 127.0.0.1:21503  Link carefree Simulator 
     Input adb devices  Get device name 
    
appPackage and appActivity obtain :
     First, open the settings in the virtual machine 
     Enter the command adb shell dumpsys window windows | findstr mFocusedApp
     stay u0 After that is the package name and startup name com.android.settings/.Settings
    
"""
"""
 Tips :
platformName Field Android and android It can be in both case .
deviceName  Field , In the test Android The phone , You can write as you like , such as 123
     because deviceName The field is for IOS Systematic ,
     about Android System , This field must have , But the content can be written at will , And cannot be empty .
    
platformVersion  You can write two digits in the field , Be able to run .
"""
# 3. start-up APP
#  Declare the mobile phone driver object ( Instantiation webdriver)
#  The first parameter is zero appium Address of service , Need to start the appium service .
#  The second parameter is Desired capabilities object 
#  Let's just pass in these two parameters first .
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps)

# http://127.0.0.1:4723/wd/hub  in /wd/hub This is fixed , There has to be , Required .
#  The above step has put app It's on .

# 4. operation APP
#  Not first app Do anything .

# 5. close APP
time.sleep(5)
driver.quit()

Tips :
function appium Code considerations :

1. Guaranteed equipment ( mobile phone ) Successfully connected to the computer
Is the use of adb connect The command links the device
perhaps adb devices You can view the device name

2. function appium server( The service is started )

3. Just execute the test code .
Be careful : If it's the first run Appium Script , You will install a device called Appium Settings Of App.

Finally, let's take a look Appium What does the service log say about , as follows :

[Appium] Welcome to Appium v1.13.0
[Appium] Appium REST http interface listener started on 0.0.0.0:4723

#  One session
[HTTP] --> POST /wd/hub/session
#  Pass in Desired capabilities Dictionary type object 
[HTTP] {"capabilities":{"firstMatch":[{"platformName":"Android","appium:platformVersion":"7.1.2","appium:deviceName":"127.0.0.1:21503","appium:appPackage":"com.android.settings","appium:appActivity":".Settings"}]},"desiredCapabilities":{"platformName":"Android","platformVersion":"7.1.2","deviceName":"127.0.0.1:21503","appPackage":"com.android.settings","appActivity":".Settings"}}

#  start-up AppiumDriver, Create an echo 
[W3C] Calling AppiumDriver.createSession() with args: 

... Omit some information ...

#  Then start some ADB command 
[ADB] Found 2 'build-tools' folders under 'F:\DevInstall\envs\android-sdk-windows' (newest first):
[ADB]     F:/DevInstall/envs/android-sdk-windows/build-tools/29.0.3

... Omit some information ...

[BaseDriver] Event 'newSessionStarted' logged at 1605778307025 (17:31:47 GMT+0800 ( China standard time ))
# 6d2f52a7-f71e-4842-98e9-22aff59a4b38  by sessionID
[W3C (6d2f52a7)] Cached the protocol value 'W3C' for the new session 6d2f52a7-f71e-4842-98e9-22aff59a4b38

... Omit some information ...

[BaseDriver] Event 'quitSessionFinished' logged at 1605778313510 (17:31:53 GMT+0800 ( China standard time ))
[W3C (6d2f52a7)] Received response: null
[W3C (6d2f52a7)] But deleting session, so not returning
[W3C (6d2f52a7)] Responding to client with driver.deleteSession() result: null
[HTTP] <-- DELETE /wd/hub/session/6d2f52a7-f71e-4842-98e9-22aff59a4b38 200 1469 ms - 14
[HTTP] 

Tips :

  • The suffix for Android apps is .apk, yes AndroidPackage Abbreviation .
  • IOS Installation package .ipa, install ios Test version , need Ios Development will iPhone Mobile phone UUID Add the number to the developer project .

a key : Supporting learning materials and video teaching

So here I have carefully prepared the detailed information of the above outline in The link below is as follows

原网站

版权声明
本文为[Test - Eight Precepts]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/186/202207050549591220.html