Start a Appium instance of Android

Source: Internet
Author: User

1. View the app package name and activity method for Android (There are many ways on the web, which is used to view the log method)cmd input >adb logcat-c>adb logcat activitymanager:i *:sthen manipulate the application to be tested in the emulator, view the log, and the results are as follows, cmp= app package name/activityReference documents: http://blog.csdn.net/jlminghui/article/details/40622103 2. Positioning elements some tools of the Android SDK can help locate, under the tools of the Android SDK installation directory1.monitor.bat: Find the Content-description for Android controls for easy positioning2.uiautomatorviewer.bat: View the properties of the control, or view the apppackage of the app under testNote: Both tools support only the API Level16 above, and if this version is below, the two tools are not available. is how to choose the machine to acquire if there are multiple machines:(How to use Uiautomator: http://blog.csdn.net/chenbang110/article/details/23371731) Other methods: Use Appium's inspector to locate the element, use the method link to see my other essay http://www.cnblogs.com/meitian/p/4837938.html 3. Open Appium,launch (the small triangle on the right) 4. Write a test case, execute a Use case script, complete a Appium instance(Be sure to open the Appium and emulator before executing the test script)Code:From appium import Webdriver
Import Timesettings for #以下为启动session时的desired capabilities
desired_caps = {}
desired_caps[' platformname ' = ' Android '
desired_caps[' platformversion ' = ' + '
desired_caps[' devicename '] = ' emulator-5554 '#desired_caps [' app ']= ' D:\software\Android\APPS\com.tencent.mm_621.apk ', this is the installation package address of the app to be installed, not required, there are # This item will first install the app through this address, I do not use this, directly with the package name and activity namedesired_caps[' apppackage '] = ' Com.android.calculator2 '
desired_caps[' appactivity '] = '. Calculator '

#以下为启动driver, as well as some use case actions for locating elements and manipulating elements
Driver = Webdriver. Remote (' Http://127.0.0.1:4723/wd/hub ', desired_caps)
Time.sleep (5)
driver.find_element_by_id ("Com.android.calculator2:id/digit1"). Click ()
Time.sleep (2)
driver.find_element_by_id ("Com.android.calculator2:id/plus"). Click ()
Time.sleep (2)
driver.find_element_by_id ("Com.android.calculator2:id/digit2"). Click ()
Time.sleep (2)
driver.find_element_by_id ("Com.android.calculator2:id/equal"). Click ()
Time.sleep (2)
test = driver.find_element_by_class_name ("Android.widget.EditText"). Text
print (test)
Assert test = = 3
driver.quit ()  desired capabilities settings when you set some of the item description: Other points of note:1. If there are multiple simulators, the launch VAD selected in the launch device in the Appium Android settings will affect the boot emulator, My code is set to start platformversion for 4.3.1 simulator, but appium there is set 4.0.4, execution will always go to find 4.0.4, did not find the last error2. Low version of Android to use Selendroid3. The company needs to configure the agent to be able to network, here if you do not change the start of the agent is no way to execute the success of the use case, there is a simple way to first open fiddle, then to execute the use case

Start an Appium instance of Android

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.