class PubMethod(Base): def __init__(self, driver): self.base = Base(driver) self # 启动应用 def startApp(self, packagename): self.base.useApp(packagename, 'start') sleep(2) # 退出应用 def stopApp(self, packagename): self.base.useApp(packagename, 'stop') sleep(2) # 清除应用数据 def clearApp(self, packagename): self.base.useApp(packagename, 'clear') sleep(2) # 点击手机home键 def clickHome(self): sleep(1) self.base.usePhone('home') # 点击手机back def clickBack(self): sleep(1) self.base.usePhone('back') # 点击隐私弹窗同意按钮——LYX def clickPrivacyAgree(self): if self.base.elementIsExit(PRIVACY_AGREE_BUTTUN): self.base.clickByElement(PRIVACY_AGREE_BUTTUN, '隐私弹窗同意按钮') else: self.assertFalse(PRIVACY_AGREE_BUTTUN) # 点击隐私弹窗不同意按钮——LYX def clickPrivacyDisagree(self): if self.base.elementIsExit(PRIVACY_DISAGREE_BUTTUN): self.base.clickByElement(PRIVACY_DISAGREE_BUTTUN, '隐私弹窗不同意按钮') else: self.assertFalse(PRIVACY_DISAGREE_BUTTUN) # 点击权限弹窗拒绝按钮——LYX def clickPermissionDisagree(self): if self.base.elementIsExit(PERMISSION_DISAGREE_BUTTUN): self.base.clickByElement(PERMISSION_DISAGREE_BUTTUN, '权限弹窗拒绝按钮') else: self.assertFalse(PERMISSION_DISAGREE_BUTTUN) # 点击权限弹窗允许按钮——LYX def clickPermissionAgree(self): if self.base.elementIsExit(PERMISSION_AGREE_BUTTON): self.base.clickByElement(PERMISSION_AGREE_BUTTON, '权限弹窗允许按钮') else: self.assertFalse(PERMISSION_AGREE_BUTTON) # 获取百度文字识别 API 识别并提取图片中文字————LCM def getBaiduApiText(self, element): ''' :param element: 判断当前页面存在的元素 :return: 返回去掉符号的文字 ''' if self.base.elementIsExit(element): sleep(2) text = self.base.baiduOcr() textTitle = ' '.join(text) strText = re.sub('\W+', '', textTitle) return strText else: self.assertFalse(element) # 删除桌面的书签 —— LJX def deleteBookmark(self, element, position): if self.base.scrollToElement(element): # todo:缺少左右滑动 self.base.dragByElement(element, position) else: pass # 返回到首页或负一屏 —— LJX def mbackToHomeOrNegative(self): # 如果不在首页也不在负一屏,返回上一层,直到返回到首页或负一屏 if self.base.elementIsExit(PRIVACY_AGREE_BUTTUN): self.base.clickByElement(PRIVACY_AGREE_BUTTUN, '隐私弹窗同意按钮') self.base.browserWatcher() self.base.browserWatcher() elif self.base.elementIsExit(PERMISSION_AGREE_BUTTON): self.base.clickByElement(PERMISSION_AGREE_BUTTON, '权限弹窗允许按钮') self.base.browserWatcher() else: while not self.base.elementIsExit( BACKGROUND_ID) and not self.base.elementIsExit(SAVED_PAGE): if self.base.elementIsExit(WEBSITE_BACKWARD): self.base.clickByElement(WEBSITE_BACKWARD, '不在首页,返回上一层') elif self.base.elementIsExit(NEWS_PAGE_BACK): self.base.clickByElement(NEWS_PAGE_BACK, '不在首页,返回上一层') else: self.clickBack()
class DownPage(Base): def __init__(self, driver): self.base = Base(driver) # 长按下载网页 def longLink(self): if self.base.elementIsExit(SEARCH_PAGE_REFRASH): self.base.long_clickByElement(LONG_SEARCH_PAGR_LINK, '长按搜索结果页网页链接') else: self.assertFalse(SEARCH_PAGE_REFRASH) # 点击长按弹框中的“下载链接”按钮 def clickDownLink(self): if self.base.elementIsExit(LONG_PRESS_BOX): self.base.clickByElement(DOWNLINK, '点击长按菜单弹框中的“下载链接”按钮') else: self.assertFalse(LONG_PRESS_BOX) # 点击下载弹框中的“下载”按钮 def clickDownButton(self): if self.base.elementIsExit(DOWNLOAD_NAME): self.base.clickByElement(DOWN_LOAD, '点击下载弹框中的“下载”按钮') else: self.assertFalse(DOWNLOAD_NAME) # 点击下载弹框中的“取消”按钮 def clickCancelButton(self): if self.base.elementIsExit(DOWNLOAD_NAME): self.base.clickByElement(DOWN_CANCEL, '点击下载弹框中的“取消”按钮') else: self.assertFalse(DOWNLOAD_NAME) # 地址栏输入“QQ应用” def inputApp(self): if self.base.elementIsExit(SEARCHPANEL_ANOTHERCHANGE): self.base.elementSetText(SEARCHPANEL_WEBSITE, APPNAME, "输入“QQ”") else: self.assertFalse(SEARCHPANEL_ANOTHERCHANGE) # 地址栏输入“QQ应用” def clickAppDown(self): if self.base.elementIsExit(QQDOWN): self.base.clickByElement(QQDOWN, "点击“高速下载”") else: self.assertFalse(QQDOWN) # 获取下载弹框中的标题内容————LCM def getDownTitle(self, element): if self.base.elementIsExit(element): return self.base.elementText(element, '获取下载弹框中的标题内容') else: self.assertFalse(element) # 长按下载管理页面中的文件————LCM def longPressElement(self): if self.base.elementIsExit(DOWN_LOAD_MANAGE_TITLE): if self.base.elementIsExit(DOWN_LOAD_MANAGE_TITLE): self.base.long_clickByElement(DOWN_LOAD_MANAGE_TITLE, '长按下载管理页面中的文件') else: self.assertFalse(DOWN_LOAD_MANAGE_TITLE) else: self.base.usePhone('back') # 点击操作下载管理页面中的文件————LCM def clickChoose(self): # 判断“全选”按钮存在,则点击全选 if self.base.elementIsExit(DOWN_LOAD_MANAGE_CHOOSE): self.base.clickByElement(DOWN_LOAD_MANAGE_CHOOSE, '选择下载管理页面中的文件') self.clickDeleteAllFile() # 判断“全不选”按钮存在,则点击“删除” elif self.base.elementIsExit(DOWN_LOAD_MANAGE_CHOOSEONE): self.clickDeleteAllFile() else: self.assertFalse(DOWN_LOAD_MANAGE_CHOOSE) # 下载管理页面中点击删除按钮————LCM def clickDeleteAllFile(self): if self.base.elementIsExit(DOWN_LOAD_MANAGE_RENAME): # 点击删除按钮 self.base.clickByElement(DOWN_LOAD_MANAGE_DELETE_SELECTED, '点击删除按钮') self.clickDelete() else: self.assertFalse(DOWN_LOAD_MANAGE_RENAME) # 下载管理页面中点击删除所有的文件————LCM def clickDelete(self): if self.base.elementIsExit(DOWN_LOAD_MANAGE_DELETE): # 点击删除全部文件 self.base.clickByElement(DOWN_LOAD_MANAGE_DELETE, '点击删除下载管理页面中的文件') else: self.assertFalse(DOWN_LOAD_MANAGE_DELETE_SELECTED)