class ClickPersonal(object): def __init__(self, driver): self.driver = driver self.base = BaseApi(driver) self.indexHolder = IndexHolder(driver) self.readYaml = ReadYaml() self.userInfoPage = self.readYaml.getStream(FilePath.iOSUserInfolPage) self.personalButtons = self.readYaml.getNode(self.userInfoPage, "personalButtons") def clickPersonal(self, db, mobile): """ 进入修改个人资料页面 :param db: :param mobile: :return: """ self.indexHolder.switchNavigation("我的") userName = db.select( "select nickname from user where studentId= {0}".format( mobile))[0][0] self.personalButtons = self.personalButtons.format(userName) if self.base.iosCheckElements(self.personalButtons): button = self.base.iosPredicate(self.personalButtons) button.click() #进入个人资料设置页面
class ImGroup(object): __metaclass__ = abc.ABCMeta def __init__(self, driver): self.readYaml = ReadYaml() self.base = BaseApi(driver) #校园页面 self.schoolNavigationBar = self.readYaml.getStream( FilePath.androidIndexPage) self.schoolclass = self.readYaml.getNode(self.schoolNavigationBar, 'class') #获取通讯录元素路径 self.imGroup = self.readYaml.getStream(FilePath.androidGroup) #通讯录页面 self.addressList = self.readYaml.getNode(self.imGroup, 'addressList') #添加好友页面 self.addFriend = self.readYaml.getNode(self.imGroup, 'addFriend') #添加好友输入框 self.addFriendScanf = self.readYaml.getNode(self.imGroup, 'addFriendScanf') #添加好友按钮 self.addFriendButton = self.readYaml.getNode(self.imGroup, 'addFriendButton') #添加好友验证按钮 self.sendFriendButton = self.readYaml.getNode(self.imGroup, 'sendFriendButton') @abc.abstractmethod def update(self, *args, **kwargs): pass
class IndexPage(object): __metaclass__ = abc.ABCMeta def __init__(self, driver): self.driver = driver self.readYaml = ReadYaml() self.indexPage = self.readYaml.getStream(FilePath.iOSIndexPage) self.base = BaseApi(self.driver) self.closeAdButton = self.readYaml.getNode(self.indexPage, "closeAdButton") self.explorButton = self.readYaml.getNode(self.indexPage, "explorButton") self.classButton = self.readYaml.getNode(self.indexPage, "classButton") self.learnButton = self.readYaml.getNode(self.indexPage, "learnButton") self.questionBankButton = self.readYaml.getNode( self.indexPage, "questionBankButton") self.myselfButton = self.readYaml.getNode(self.indexPage, "myselfButton") self.navigation = self.readYaml.getNode(self.indexPage, "navigation") @abc.abstractmethod def switchNavigation(self): pass def closeAd(self): if self.base.iosCheckElement(self.closeAdButton): self.base.iosClick(self.closeAdButton)
class PersonalHolder(object): __metaclass__ = abc.ABCMeta def __init__(self, driver): self.driver = driver self.db = DbOption() self.readYaml = ReadYaml() self.base = BaseApi(self.driver) self.comePersonal = ClickPersonal(driver) self.indexHolder = IndexHolder(self.driver) self.userInfoPage = self.readYaml.getStream(FilePath.iOSUserInfolPage) self.personalPage = self.readYaml.getStream(FilePath.iOSPersonalPage) self.saveButton = self.readYaml.getNode(self.personalPage, "saveButton") self.backButton = self.readYaml.getNode(self.personalPage, "backButton") self.updateNamePage = self.personalPage.get("updateNamePage") self.updateNameButton = self.updateNamePage.get("updateNameButton") self.updateNameInputButton = self.updateNamePage.get( "updateNameInputButton") self.updateSummaryPage = self.personalPage.get("updateSummaryPage") self.updateSummaryButton = self.updateSummaryPage.get( "updateSummaryButton") self.setSummary = self.updateSummaryPage.get("setSummary") self.SummaryFlage = self.updateSummaryPage.get("SummaryFlage") self.updateSchoolButton = self.personalPage.get("updateSchoolButton") self.update_workButton = self.personalPage.get("update_workButton") @abc.abstractmethod def update(self, *args, **kwargs): pass
class IndexPage(object): def __init__(self, driver): self.driver = driver self.base = BaseApi(self.driver) self.readyaml = ReadYaml() self.indexPage = self.readyaml.getStream(FilePath.androidIndexPage) self.explore = self.readyaml.getNode(self.indexPage, "explore") self.classTab = self.readyaml.getNode(self.indexPage, "class") self.reconnetButton = self.readyaml.getNode(self.indexPage, "reconnetButton") self.questionBank = self.readyaml.getNode(self.indexPage, "questionBank") self.myStudy = self.readyaml.getNode(self.indexPage, "myStudy") self.mySelf = self.readyaml.getNode(self.indexPage, "mySelf") print(self.mySelf) def comeNATIVEAPP(self): """切换到原生""" self.base.switchContext("NATIVE_APP") def chooseNavigation(self): pass
class LoginPage(object): """ 登录类 """ def __init__(self, driver): self.driver = driver self.logger = MyLogger(self.__class__.__name__).getlogger() # 获取日志 self.baseView = BaseApi(self.driver) self.launchPath = FilePath().androidLaunchPage self.readYaml = ReadYaml() self.myself = MySelf(driver) self.launchPage = self.readYaml.getStream(self.launchPath) self.launchEle = self.launchPage.get("launch", False) self.checkLoginEle = self.launchPage.get("ckeckLogin", False) # 登录成功校验元素 self.mobileLoginButton = self.readYaml.getNode(self.launchEle, "mobileLoginButton") self.aaccount = self.readYaml.getNode(self.launchEle, "aaccount") self.passwd = self.readYaml.getNode(self.launchEle, "passwd") self.submitButton = self.readYaml.getNode(self.launchEle, "submitButton") self.forgetPasswd = self.readYaml.getNode(self.launchEle, "forgetPasswd") self.androidUserInfoPage = self.readYaml.getStream( FilePath.androidUserInfoPage) self.settingPage = self.readYaml.getStream(FilePath.androidSettingPage) self.settingButton = self.readYaml.getNode(self.androidUserInfoPage, "settingButton") self.loginOutButton = self.readYaml.getNode(self.settingPage, "loginOutButton") self.affirmLoginoutButton = self.readYaml.getNode( self.settingPage, "affirmLoginoutButton") def login(self, userName, password): """ 登录 :param userName: 账号 :param password: 密码 :return: """ self.loginOut() # 如果已登录会退出登录 if self.baseView.checkElement(self.mobileLoginButton): self.baseView.click(self.mobileLoginButton) else: raise EleNotFound("账号登录按钮未找到") if self.baseView.checkElement(self.aaccount): self.baseView.sendKeys(self.aaccount, userName) self.baseView.sendKeys(self.passwd, password) self.baseView.click(self.submitButton) print('登录成功') else: raise EleNotFound("输入账号按钮未找到") def checkLogin(self, checkCountFlage=5): """ 多次容错检查 首页探索元素 :return: bool """ checkFlage = True checkCount = 0 while checkFlage and checkCount < checkCountFlage: if self.baseView.checkElement( self.readYaml.getNode(self.checkLoginEle, "explore"), 5): checkFlage = False res = True if checkCount and checkCount == checkCountFlage - 1: res = False checkCount += 1 return res def loginOut(self): if self.checkLogin(3): #检查是否已经登录 self.myself.chooseNavigation() if self.baseView.checkElement(self.settingButton): self.baseView.click(self.settingButton) self.baseView.click(self.loginOutButton) self.baseView.click(self.affirmLoginoutButton)
class PersonalHolder(object): __mateclass__ = abc.ABCMeta def __init__(self, driver): self.logger = MyLogger(self.__class__.__name__).getlogger() self.driver = driver self.base = BaseApi(self.driver) self.readYaml = ReadYaml() self.mySelf = MySelf(self.driver) # 我的页面 self.userInfoPage = self.readYaml.getStream( FilePath.androidUserInfoPage) # 个人资料按钮 self.personalCenter = self.readYaml.getNode(self.userInfoPage, "personalCenter") #获取我的页面当前用户名 self.userName = self.readYaml.getNode(self.userInfoPage, 'userName') # 个人资料页面 self.personalPage = self.readYaml.getStream( FilePath.androidPersonalPage) self.updateNameButton = self.readYaml.getNode(self.personalPage, "updateNameButton") self.updateNameInputButton = self.readYaml.getNode( self.personalPage, "updateNameInputButton") self.updateNameSaveButton = self.readYaml.getNode( self.personalPage, "updateNameSaveButton") #返回 self.backButton = self.readYaml.getNode(self.personalPage, "backButton") #修改密码 self.updatePasswdButton = self.readYaml.getNode( self.personalPage, "updatePasswdButton") self.oldPasswordFild = self.readYaml.getNode(self.personalPage, "oldPasswordFild") self.newPasswordFild = self.readYaml.getNode(self.personalPage, "newPasswordFild") self.affirePasswordFild = self.readYaml.getNode( self.personalPage, "affirePasswordFild") self.savePassword = self.readYaml.getNode(self.personalPage, "savePassword") #修改学校 self.schoolButton = self.readYaml.getNode(self.personalPage, "schoolButton") self.schoolFile = self.readYaml.getNode(self.personalPage, "schoolFile") self.schoolNameText = self.readYaml.getNode(self.personalPage, "schoolNameText") #修改简介 self.updateSummaryButton = self.readYaml.getNode( self.personalPage, "updateSummaryButton") self.newSummaryFild = self.readYaml.getNode(self.personalPage, "newSummaryFild") self.newSummaryText = self.readYaml.getNode(self.personalPage, "newSummaryText") #修改工作单位 self.workButton = self.readYaml.getNode(self.personalPage, "workButton") self.workFild = self.readYaml.getNode(self.personalPage, "workFild") self.workNameText = self.readYaml.getNode(self.personalPage, "workNameText") @abc.abstractmethod def update(self, *args, **kwargs): pass
class Login(object): def __init__(self,driver): self.readYaml = ReadYaml() self.loginPage = self.readYaml.getStream(FilePath.iOSLaunchPage) self.base = BaseApi(driver) self.indexHolder = IndexHolder(driver) self.mobileLoginButton = self.readYaml.getNode(self.loginPage,"mobileLoginButton") self.account = self.readYaml.getNode(self.loginPage,"account") self.passwd = self.readYaml.getNode(self.loginPage,"passwd") self.submit = self.readYaml.getNode(self.loginPage,"submit") self.learnTitle = self.readYaml.getNode(self.loginPage,"learnTitle") self.skipButton = self.readYaml.getNode(self.loginPage,"skipButton") self.checkLoginButton = self.readYaml.getNode(self.loginPage,"checkLoginButton") self.settingButton = self.readYaml.getNode(self.readYaml.getStream(FilePath.iOSUserInfolPage),"settingButton") self.settingPage = self.readYaml.getStream(FilePath.iOSettinglPage) self.loginOutButton = self.readYaml.getNode(self.settingPage,"loginOutButton") self.affireButton = self.readYaml.getNode(self.settingPage,"affireButton") def login(self,account,password): self.loginout() mobileLoginEles = self.base.iosPredicates(self.mobileLoginButton) for loginButton in mobileLoginEles: visible = loginButton.get_attribute("visible") if visible == "true": loginButton.click() break if self.base.iosCheckElement(self.account): self.base.setValue(self.account,account,1) self.base.setValue(self.passwd,password,10) self.base.iosClick(self.submit) else: raise EleNotFound("输入账号框未找到") def checkLogin(self,checkCountFlage=5): """ 检查账号是否已经登录 :param checkCountFlage: :return: """ skipStast = self.skip() if skipStast: return skipStast flage = True checkCount = 0 while flage and checkCount<checkCountFlage: if self.base.iosCheckElement(self.checkLoginButton): flage = False res = True if checkCount and checkCount==checkCountFlage-1: res = False checkCount+=1 return res def loginout(self): if self.checkLogin(2): self.indexHolder.switchNavigation("我的") self.base.iosClick(self.settingButton) self.base.swipeDown() self.base.iosClick(self.loginOutButton) self.base.iosClick(self.affireButton) def skip(self): if self.base.iosCheckElement(self.skipButton,10): skipButton = self.base.iosPredicate(self.skipButton) flage = True findNum = 0 while flage and findNum <4: status = skipButton.get_attribute("visible") if status: self.base.iosClick(self.skipButton) flage = False findNum +=1 return True