首先Appuim的安裝情參照:http://www.reibang.com/p/55fef32ff505
先來看一下運行Android的case赋访,我的是基于python的:
#coding=utf-8
import sys
reload(sys)
sys.setdefaultencoding( "utf-8" )
import os
import glob
import unittest
from time import sleep
from appium import webdriver
PLATFORM_VERSION = '4.4'
class AndroidWebViewTests(unittest.TestCase):
def setUp(self):
# app = os.path.abspath( os.path.join(os.path.dirname(__file__),'../../apps/selendroid-test-app.apk'))
desired_caps = {
# 'app': app,
'appPackage': 'com.apricotforest.dossier',
'appActivity': '.medicalrecord.activity.main.MainLoadingActivity',
'platformName': 'Android',
'platformVersion': PLATFORM_VERSION,
'deviceName': 'XiaoMI',
'udid': '84303468',
}
if (PLATFORM_VERSION != '4.4'):
desired_caps['automationName'] = 'selendroid'
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
def test_webview(self):
if (PLATFORM_VERSION == '4.4'):
button = self.driver.find_element_by_id('btn_login')
button.click()
#self.driver.switch_to.context('WEBVIEW_0')
#input_field = self.driver.find_element_by_id('name_input')
#sleep(1)
#input_field.clear()
#input_field.send_keys('Appium User')
#input_field.submit()
# test that everything is a-ok
#source = self.driver.page_source
#self.assertNotEqual(-1, source.find('This is my way of saying hello'))
#self.assertNotEqual(-1, source.find('"Appium User"'))
def tearDown(self):
self.driver.quit()
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(AndroidWebViewTests)
unittest.TextTestRunner(verbosity=2).run(suite)
里面需要注意的是:
uuid是你待測試的Android機的deviceID罕容,可以通過adb devices獲得。
Android的automationName是selendroid编整,一定要設(shè)置。
接下來就可以跑測試了:
首先乳丰,啟動appium:
bogon:~ xingshulin$ appium -p 4723
[Appium] Welcome to Appium v1.6.3
[Appium] Appium REST http interface listener started on 0.0.0.0:4723
然后就是運行case了掌测,對于python,就是python android_webview.py
bogon:python xingshulin$ python android_webview.py
test_webview (__main__.AndroidWebViewTests) ... ok
----------------------------------------------------------------------
Ran 1 test in 14.512s
OK
成功产园!
對了汞斧,如果想獲得Android手機上控件的信息,就用Android SDK提供的uiautomatorviewer吧淆两。