Appium Environment Build Python (Mac System)

Source: Internet
Author: User

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:

-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:

--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. Download the Android SDK

: Http://pan.baidu.com/s/1hqGHhRI

ADT is available in multiple versions, including Adt-bundle with Eclipse and SDK, recommended for download. Here we only need to use the SDK.

3. Configure Environment variables

Open terminal, enter command in sequence

-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 show command not found is the success

4. Select the appropriate Python IDE

Recommended eclipse with PyDev, Wing IDE, and Sublime text

pydev:http://pydev.org/

Wing ide:http://wingware.com/

Sublime text:http://www.sublimetext.com/

5. Install Selenium or appium-python-client

Before installing, you need to arrange the pip before entering the command in the terminal window:

sudo easy_install pip

Then install appium-python-client, enter the command in the terminal window:

sudo pip install appium-python-client

Of course you can also install selenium, the difference is only appium-python-client to bring more methods than selenium method.

sudo pip install selenium-i http://pypi.douban.com/simple

At this point, enter Python in the terminal and enter import appium (or 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

#coding =utf-8" "Create on --4- -python2.7  forMac@author:tangdongchu" "Import Osimport unittest fromSelenium Import webdriverimport time#appium environment configuration path=Lambda P:os.path.abspath (Os.path.join (Os.path.dirname (__file__), p))classdpapptests (unittest. TestCase): def setUp (self): Desired_caps={} desired_caps['PlatformName'] ='Android'#设置平台 desired_caps['platformversion'] ='4.4'#系统版本 desired_caps['devicename'] ='93d1243b'#设备id desired_caps['AutoLaunch'] ='true'#是否自动启动 desired_caps['app'] =PATH ('apk/nova_7.2.0_debug.apk'#安装包路径, placed in the directory of the py file) desired_caps['Apppackage'] ='com.dianping.v1'#包名 desired_caps['appactivity'] ='com.dianping.main.guide.SplashScreenActivity'#启动的activity Self.driver= Webdriver. Remote ('Http://localhost:4723/wd/hub', Desired_caps) def tearDown (self): Self.driver.quit () #case执行完退出 def Test_dpapp (self): #需要执行的case Time.sleep ( the) El= Self.driver.find_element_by_xpath ("//android.widget.textview[contains (@text, ' Shanghai ')]") #通过xpath找到定位框 El.click () #点击定位框if__name__ = ='__main__': Suite=UnitTest. Testloader (). Loadtestsfromtestcase (dpapptests) unittest. Texttestrunner (verbosity=2). Run (Suite) #执行case集

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 to build Python (Mac system)

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.