appium自动化学习(二)

第一条用例。

#!_*_coding:utf-8_*_
import os
from selenium import webdriver
import time
import unittest

PATH = lambda p: os.path.abspath(
    os.path.join(os.path.dirname(__file__), p)
)

class OpenToSearch(unittest.TestCase):#继承unittest.TestCase类
	def setUp(self):        #初始化
		desired_caps = {}
		desired_caps['deviceName'] = 'QO4315C24235'
		desired_caps['platformName'] = 'Android'
		desired_caps['browserName'] = ''
		desired_caps['platformVersion'] = '4.2.2'
		#desired_caps['app'] = PATH(r'C:\Users\mazhigang\Desktop\AndroidStorm.apk')
		desired_caps['appPackage'] = 'com.storm.smart'
		desired_caps['appActivity'] = '.LogoActivity'

		self.driver = webdriver.Remote('http://localhost:4723/wd/hub',desired_caps)
		time.sleep(10)

	def test_open_search(self):  #测试用例
		self.driver.find_element_by_xpath("//android.widget.ImageView[contains(@index,5)]").click()#点击搜索按钮
		time.sleep(3)
		search = self.driver.find_element_by_xpath("//android.widget.TextView[contains(@index,0)]")#跳转到搜索页面,定位TextView元素
		self.assertEqual(search.text,u'大家都在搜','bug')#判断定位到的元素的text是否与预期结果一致

	def teardown(self):    #释放工作
		self.driver.quit()

if __name__ == '__main__':
	unittest.main()

  

posted @ 2014-10-28 14:15  tester_SKP  阅读(469)  评论(0)    收藏  举报