1, installation Appium
Installation via terminal:
Install the nodejs,:https://nodejs.org/download/, open the terminal input node-v after the installation is complete, check whether the installation is successful
Install NPM, open terminal, enter command:
sudo Bash sudo curl-l https://npmjs.org/install.sh | sh
After the installation is complete, enter npm-v to check if the installation was successful
To install Appium, command:
Install--registry http://registry.cnpmjs.org install-g appium (recommended for this, NPM's domestic image)
After the installation is complete, enter Appium hint: Welcome to Appium instructions are installed
Check if the environment required for Appium is OK (this step is important) go to the cmd command line, enter Appium-doctor, and the following prompt appears, all Checks were successful, indicating that the environment is successful.
Installation via DMG (recommended):
DMG Program:
Official download:http://appium.io/
Domestic Download:http://pan.baidu.com/s/1jGvAISu (recommended)
2. Installing ADT
: Http://pan.baidu.com/s/1hqGHhRI
ADT is divided into multiple versions, including Adt-bundle with Eclipse and SDK, recommended for download, Eclipse without installation, and then copy folder to application directory after downloading.
3. Configure Environment variables
Open terminal, enter command in sequence
Touch-E. Bash_profile
The text is automatically opened, added to the text, and then saved
Export android_home=/applications/eclipse/sdkexport PATH= $PATH: $ANDROID _home/platform-tools: $ANDROID _ Home/tools
Where Android_home is the path for the downloaded SDK
Then enter the command in the terminal
source. bash_profile
OK, the environment variable is set up, you can now try to enter the ADB return in the terminal window, do not display command not Found is a success
4. Select the appropriate Python IDE
Recommended eclipse with Pydev and wing IDE
pydev:http://pydev.org/
Wing ide:http://wingware.com/
5, installation Selenium
Before installing selenium, you need to arrange the pip before entering the command in the terminal window:
sudo easy_install pip
Then install selenium, enter the command in the terminal window:
sudo Install selenium-i http://pypi.douban.com/simple
Domestic Douban download faster, recommended.
At this point, enter Python in the terminal, and then enter import selenium, if the error indicates that the installation was successful
6. Writing Appium Automation scripts
The reference code below, Appium itself is based on the selenium, so need to use the selenium package, UnitTest is used to manage case, before writing, we need to configure the Appium environment, such as platform, system version, device ID, installation package, Start activity, AutoLaunch (whether to install APK and start automatically) and so on.
Device ID Acquisition: Phone connected to the computer, open the terminal input ADB devices to obtain the device ID
Apppackge get: Connect the computer, launch the application, open the terminal input ADB shell PS can see the application of the Packgename
Appactivity get: Open terminal input aapt d badging documents/python/apk/nova_7.2.0_debug.apk to view launchactivity, Where the APK address is replaced with your local APK address
1 #Coding=utf-82 " "3 Create on 2015-4-164 python 2.7 for Mac5 @author: Tangdongchu6 " "7 ImportOS8 ImportUnitTest9 fromSeleniumImportWebdriverTen Import Time One A #appium Environment Configuration -PATH =LambdaP:os.path.abspath ( -Os.path.join (Os.path.dirname (__file__), p) the ) - - classdpapptests (unittest. TestCase): - defsetUp (self): +Desired_caps = {} -desired_caps['PlatformName'] ='Android' #setting up the platform +desired_caps['platformversion'] ='4.4' #System Version Adesired_caps['devicename'] ='93d1243b' #Device ID atdesired_caps['AutoLaunch'] ='true' #whether to start automatically -desired_caps['app'] =PATH ( - 'apk/nova_7.2.0_debug.apk' #Install the package path, placed in the directory of the py file - ) -desired_caps['Apppackage'] ='com.dianping.v1' #Package Name -desired_caps['appactivity'] ='com.dianping.main.guide.SplashScreenActivity' #Activated activity in -Self.driver = Webdriver. Remote ('Http://localhost:4723/wd/hub', Desired_caps) to + defTearDown (self): -Self.driver.quit ()#Case exit after execution the * defTest_dpapp (self):#the case to be executed $Time.sleep (15)Panax NotoginsengEl = Self.driver.find_element_by_xpath ("//android.widget.textview[contains (@text, ' Shanghai ')]")#Find a position box with XPath -El.click ()#Click the Position box the + A the if __name__=='__main__': +Suite =UnitTest. Testloader (). Loadtestsfromtestcase (dpapptests) -UnitTest. Texttestrunner (verbosity=2). Run (Suite)#Execute case Set
7. Get UI Elements
In the SDK directory there is a tools folder, which has a Uiautomator view program, open as, insert device, click the Second button on the left of the bottom
The resulting interface is as follows, selecting elements to see the layout information of the element, such as the bottom of the positioning box can be located by ID, or through XPath to locate.
8. Run case
Open Appium,
Choose android (if you want to run on iOS, you'll need to install Xcode), and then launch
Go back to the Python IDE and run the code
Now look at the Appium window, there will be a log output, case run can see the results of the execution, such as
9. Reference documents
Appium Model Code: Https://github.com/appium/sample-code/tree/master/sample-code/examples/python
Appium official Chinese Document: HTTPS://GITHUB.COM/APPIUM/APPIUM/TREE/MASTER/DOCS/CN
Appium Environment Build Python (Mac System)