作者在 2016-04-11 21:55:08 发布以下内容
#-*- coding:UTF-8 -*-
'''
Created on 2016-4-11
@author: poptest
'''
import time
from appium import webdriver
class CommonFunction(object):
#封装点击动作(文本类型,文本值)
def clickAct(self,getType,getValue):
if getType == "id":
return dr.find_element_by_id(getValue).click()
elif getType == "name":
return dr.find_element_by_name(getValue).click()
elif getType == "xpath":
return dr.find_element_by_xpath(getValue).click()
elif getType=="class":
dr.find_element_by_class_name(getValue).click()
elif getType=="mator":
dr.find_element_by_android_uiautomator(getValue).click()
elif getType == "link_text":
return dr.find_element_by_link_text(getValue).click()
def exit(self):
dr.quit()
def addgoodsaddress(self,userName,userTel,userAddr):
time.sleep(3)
#点击头像、登陆进去
M.clickAct("id","com.subject.zhongchou:id/avatar_img")
time.sleep(2)
#点击收货地址
M.clickAct("id","com.subject.zhongchou:id/address_layout")
time.sleep(2)
#点击添加收货地址ַ
M.clickAct("xpath","//android.widget.Button[@text='添加收货地址']")
time.sleep(2)
#收件人
dr.find_element_by_id("com.subject.zhongchou:id/add_address_name_edit").send_keys(userName)
time.sleep(2)
#输入手机号
dr.find_element_by_id("com.subject.zhongchou:id/add_address_tel_edit").send_keys(userTel)
time.sleep(2)
#点击选择省份
M.clickAct("id","android:id/text1")
time.sleep(2)
#滑屏坐标,上下滑屏 需要滑屏次,才能找见需要的省份
dr.swipe(400,70,460,0,500)
time.sleep(2)
dr.swipe(460,1200,460,200,500)
time.sleep(2)
dr.swipe(460,1200,460,200,500)
time.sleep(2)
#找见北京,点击选择
M.clickAct("mator","new UiSelector().text(\"北京\")")
time.sleep(2)
#选择市区
M.clickAct("id","com.subject.zhongchou:id/add_address_city_name_text")
time.sleep(2)
dr.swipe(400,1050,400,350,500)
#找见昌平区
M.clickAct("mator","new UiSelector().text(\"昌平区\")")
#输入地址
dr.find_element_by_id("com.subject.zhongchou:id/add_address_detail_edit").send_keys(userAddr)
time.sleep(1)
#点击保存
M.clickAct("id","com.subject.zhongchou:id/save_text")
def login(self,telPhone,passW):
time.sleep(4)
#点击我
M.clickAct("xpath","//android.widget.CheckedTextView[@text='我']")
time.sleep(2)
#点击马上登录
M.clickAct("id","com.subject.zhongchou:id/login_now_tv")
time.sleep(3)
#输入手机号
dr.find_element_by_id("com.subject.zhongchou:id/loginnumber_phones").send_keys(telPhone)
time.sleep(2)
#输入密码
dr.find_element_by_id("com.subject.zhongchou:id/loginnumber_password").send_keys(passW)
time.sleep(2)
#点击登录
M.clickAct("id","com.subject.zhongchou:id/go_numberlogin")
def enterApp(self):
global dr,M
#输入法设置
descried_caps={}
descried_caps["unicodeKeyboard"] = "True"
descried_caps["resetKeyboard"] = "True"
#传输设备号
descried_caps['device']='2014813'
descried_caps['platformName']='Android'
descried_caps['deviceName']='HM2014813'
descried_caps['version']='5.1'
dr = webdriver.Remote("http://127.0.0.1:4723/wd/hub",descried_caps)
M = CommonFunction()
#-*- coding:UTF-8 -*- #
'''
Created on 2016-4-8
@author: poptest
'''
import unittest,time
from ShareLibModel import CommonFunction44
P = CommonFunction44.CommonFunction()
class Test(unittest.TestCase):
def setUp(self):
P.enterApp()
def tearDown(self):
P.exit()
def testLogin(self):
P.login("18513253584","111111")
time.sleep(3)
P.addgoodsaddress(u"小红","18513253584",u"北京市昌平区")
def testAddr(self):
P.login("18513253584","111111")
print "1"
time.sleep(2)
P.addgoodsaddress(u"王亚萍","18513253584",u"北京市昌平区")
#流程为setup-testAddr-teardown,第二遍执行setup-testLogin-teardown.
if __name__ == "__main__":
unittest.main()