作者在 2016-04-12 11:53:42 发布以下内容
#-*- coding:UTF-8 -*- #
'''
Created on 2016-4-8
@author: poptest
'''
import time
from appium import webdriver
class PublicFunClass(object):
def clickAct(self,getType,getValue):
if getType == "id":
return lee.find_element_by_id(getValue).click()
elif getType == "name":
return lee.find_element_by_name(getValue).click()
elif getType == "link_text":
return lee.find_element_by_link_text(getValue).click()
elif getType == "xpath":
return lee.find_element_by_xpath(getValue).click()
def quitApp(self):
lee.close_app()
def duanyan(self,duanyan1,duanyan2):
if duanyan1=="id":
return lee.find_element_by_id(duanyan2).text
elif duanyan1=="xpath":
lee.find_element_by_xpath(duanyan2).text
return lee.find_element_by_xpath(duanyan2).text
else:
duanyan1="uiautomator"
return lee.find_element_by_android_uiautomator(duanyan2).text
def lujingzhi(self,lujingzhi1,lujingzhi2):
if lujingzhi1=="id":
return lee.find_element_by_id(lujingzhi2)
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("id","com.subject.zhongchou:id/add_address_btn") #点击添加地址按钮
time.sleep(2)
lee.find_element_by_id("com.subject.zhongchou:id/add_address_name_edit").send_keys(userName) #进去后点击增加名字
time.sleep(2)
lee.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)
lee.swipe(360, 1000, 360, 370, 500) #滑屏坐标,上下滑屏
time.sleep(2)
#需要滑屏2次,才能找见需要的省份
lee.swipe(360, 1000, 360, 370, 500)
time.sleep(2)
lee.find_element_by_android_uiautomator("new UiSelector().text(\"山西\")").click() #找见山西,点击选择
time.sleep(2)
M.clickAct("id","com.subject.zhongchou:id/add_address_city_name_text") # 选择城市
time.sleep(2)
lee.find_elements_by_android_uiautomator("new UiSelector().className(\"android.widget.CheckedTextView\")")[2].click() #选择下表为2 的城市
time.sleep(2)
lee.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("id", 0, 1, "com.subject.zhongchou:id/item_name")
print 'suckmydick'
# lee.find_elements_by_id("com.subject.zhongchou:id/item_name")[1].click()
time.sleep(2)
M.clickAct("id","com.subject.zhongchou:id/login_now_tv") #点击登录
time.sleep(3)
lee.find_element_by_id("com.subject.zhongchou:id/loginnumber_phones").send_keys(telPhone) # 输入手机号
time.sleep(2)
lee.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 lee,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'
lee = webdriver.Remote("http://127.0.0.1:4723/wd/hub",descried_caps) #找见appium的IP地址和端口号
M = PublicFunClass() #将类实例化,后边要用到点击模块,只需要在本page中使用,
from xml.dom import minidom
class denglu1():
def denglu2(self,wenjianname,elementfirstnode,num,erhaojiedianming):
dom = minidom.parse("../zcapp/"+ wenjianname)
root = dom.documentElement#
parnote = root.getElementsByTagName(elementfirstnode)[num]
denglushuju = parnote.getElementsByTagName(erhaojiedianming)[0].childNodes[0].nodeValue
return denglushuju