Appium+Python real machine running test demo method

Appium+Python real machine running test demo method

 

1.    Turn on the  USB debugging mode of the phone

 

Second,     connect the phone to the computer

   Connect the phone to the computer with a data cable and authorize the USB debugging mode. To view the effect of the connection, run the command under cmd: adb devices to view the UDID, as shown in the following figure:

If there is output, it means the connection is successful.

 

Third,     start the Appium service

Method 1: Start the cmd command line

   Start the appium service according to the found UDID and run the command:

#>appium -a 127.0.0.1 -p 4723  –U  6207febc --no-reset

The string of characters following the -U parameter is the UDID of the phone, which is found through the second step.

When the program outputs the information as shown in the figure above, it means that appium is successfully started, and the test script can be run at this time.

 

Method 2: start the appium interface

 

 

4.     Writing and running test scripts

   The test scripts run on the real machine are almost the same as those on the emulator, except that some configurations are different. The specific script demo is as follows demo.py:

#! /usr/bin/env python
#coding=utf-8
import os
import time
import unittest
from selenium import webdriver
from lib2to3.pgen2.driver import Driver
from lib2to3.tests.support import driver

PATH=lambda p:os.path.abspath(os.path.join(os.path.dirname(__file__),p))

desired_caps = {}
desired_caps['platformName'] = 'Android' #device system
desired_caps['platformVersion'] = '5.1.2' #device system
versiondesired_caps['deviceName'] = 'Lenovo P1c72' #device name

desired_caps['app'] = PATH('C:\\Users\\LENOVO\\Desktop\\StarZone_V2.0.0.apk') 
#desired_caps['appPackage'] = 'com.xiangchao.starspace'  
#desired_caps['appActivity'] = 'com.xiangchao.starspace.activity.SplashActivity'

#If you set the path of the app on the computer, you do not need to configure appPackage and appActivity, and vice versa

driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)  #启动app

time.sleep(5) #When starting the app, it takes a certain amount of time to enter the boot page, so the waiting time must be set, otherwise the following error will always be reported and the element cannot be located
driver.find_element_by_id('com.xiangchao.starspace:id/skip'). click()

driver.quit()

 

Open another cmd window and run the test script (python demo.py). At this point, the server will have output, and the program will run on the phone.

Note: During the running of the test case, under normal circumstances, the mobile phone will automatically install Settings and Unlock. Some mobile phones have compatibility problems, and the Settings and Unlock programs cannot be opened, so every time you run the script, you will be prompted to install, just follow the prompts to allow the installation.

 

Appium's Desired Capabilities extends the Desired Capabilities of webdriver. The following general configurations need to be specified: 

  • automationName: Which automation engine to use. appium (default) or Selendroid?
  • platformName: Which mobile platform to use. iOSAndroid, orFirefoxOS?
  • deviceName: Which device to start, a real machine or an emulator? iPhone SimulatoriPad SimulatoriPhone Retina 4-inchAndroid EmulatorGalaxy S4, etc...
  • app: The absolute path of the application, note that it must be an absolute path. If appPackage and appActivity are specified, this property can not be set. In addition, this attribute conflicts with the browserName attribute.
  • browserName: The name of the mobile browser. Such as Safari' for iOS and 'Chrome', 'Chromium', or 'Browser' for Android; mutually exclusive with the app property.
  • udid: The id of the physical machine. For example, 1ae203187fc012g.

 

The following attributes are android platform specific: 

  • appActivity: The Activity name of the app to be tested. Such as MainActivity, .Settings. Note that for native apps, add a "." before activity.
  • appPackage: The java package of the app to be tested. For example com.example.android.myApp, com.android.settings.

http://www.cnblogs.com/Nefeltari/p/5603163.html

 

 Get appActivity of Android app

There are many methods written on the Internet https://testerhome.com/topics/1030, and there are additions in the comment area

What I use is to change the apk suffix to zip format, open the compressed package and then open the AndroidManifest.xml file. Find the manifest and activity places, that is, the package name and the activity name. 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326918867&siteId=291194637