Android mobile phone Automation test example detailed

Source: Internet
Author: User
Tags appium

Mobile phone automation Framework is also more, for ios,android two different platforms, finally I picked the appium, it is the use of webdriver to drive testing, this framework I am more familiar with, and it supports two platforms. So I have for these two different platforms to build and test, the environment of the iOS platform is not a problem, concrete construction methods see:

Http://blog.sina.com.cn/s/blog_68f262210102v0ta.html, and the test case, because now I have no way to convert the IPA file into an app file, so the test case is not yet done. After the problem is resolved, the corresponding article will be sent.

This article describes a specific example of an Android automated test in the Windows environment, as seen in the installation of the environment:

Http://blog.sina.com.cn/s/blog_68f262210102v4aj.html, now say the test case:

Test Object : The mobile phone application of network credit Finance's crowdfunding network

run the object : Android Simulator (see the next chapter on the real machine running)

Test Cases : Simple sign-in

use case language : Webdriver+python

Test steps:

1, start Appium

Under Windows, locate the Appium application, double-click Open, and then the Appium Start button in the upper right corner to see the output log, indicating that the boot was successful.



2. Launch Android emulator

How the simulator is created, see:

http://blog.sina.com.cn/s/blog_68f262210102v4a7.html, I created the simulator is: Antester, Start method: in cmd input: Emulator @antester, The Android emulator will pop up in a moment:



3. Writing test Cases

Use your custom editing software to write your test cases, I use the language is Python, the following describes the specific test cases.

#-*-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)

)

Global driver

Class loginandroidtests(unittest. TestCase):

def setUp(self):

#初始化测试平台

desired_caps={}

desired_caps[' device '= ' Android '

desired_caps[' platformname ']=' Android ' # test Platform

desired_caps['browsername']= '

desired_caps[' version ']=' 4.2.2 ' # system versions

desired_caps[' devicename ']='antester' # emulator name

desired_caps['app-package ']=' Com.subject.zhongchou ' # app to test

desired_caps['app-activity ']='. Zhongchou ' # current active app

self. Driver=webdriver. Remote (' Http://localhost:4723/wd/hub ', Desired_caps)

def TearDown(self):

self. driver.quit ()

def test_login(self):

Time.sleep (30)

#点击 The Register Login button

button=Self driver.find_element_by_id ("Com.subject.zhongchou:id/register_button")

Button.Click ()

Time.sleep (10)

#登录

Name =self. driver.find_element_by_id (' Com.subject.zhongchou:id/loginnumber_phone ')

Name.click ()

Name.send_keys (' 183xxxxx905 ') #输入用户名

PSD =self. driver.find_element_by_id (' Com.subject.zhongchou:id/loginnumber_password ')

Psd.click ()

Psd.send_keys (' XXXXXXX ') #输入密码

blogin=Self driver.find_element_by_id (' Com.subject.zhongchou:id/go_numberlogin ') #单击登录按钮

Blogin.click ()

Time.sleep (10)

#此处要检测是否登录成功, I am lazy, a little bit!

if __name__ = = ' __main__ ':

Suite = UnitTest. Testloader (). Loadtestsfromtestcase (loginandroidtests)

UnitTest. Texttestrunner (verbosity=2). Run (Suite)

The above is a complete test case, related to the positioning of elements, content input and other operations. In fact, you can optimize the test data into an XML file independently, and the general operation can be put into a class to be closed to a common method, this code only to illustrate the use of test case structure.

Positioning of elements

Element positioning is a top priority for automated testing, and the Selenium IDE provides a great way to locate, record, and so on when the page is automated. But in the mobile phone automation testing, there is no good tools, generally used is Appium inspector, Uiautomatorviewer and Hierarchyviewer tools, specific use of the method to check online. But there's no good way to record, although Appium Inspector can record iOS apps on a Mac, but it's not very useful.

Appium has a very good Exchange site: http://www.testerhome.com/topics, we can often go to browse, I believe you can learn a lot of knowledge. Fast, accurate positioning is to rely on experience, this post http://testerhome.com/topics/167, talked about some of the positioning methods, I hope to inspire you.

An example of an automated test for Android phone

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.