Example #1
0
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
Example #2
0
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()  #进入个人资料设置页面
Example #3
0
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)
Example #4
0
class AndroidRun(object):
    def __init__(self):
        self.path = FilePath()
        self.yaml = ReadYaml()

    def startAppiumServer(self, data):
        """
        pytest 使用外部 driverDict 参数 启动 Appium server
        :param data: driverDict
        :return:
        """
        driverName = data["deviceName"]
        # pytest.main(["-s", "--driverDict={0}".format(data), "--html={0}/{1}.html".format(FilePath.reportPath,driverName),"{0}".format(FilePath.androidTestDir)])
        pytest.main([
            "-s", "--driverDict={0}".format(data),
            "--html={0}/{1}.html".format(FilePath.reportPath, driverName),
            "{0}".format(
                r"C:\Users\qi\PycharmProjects\TpKeyWord\test\Android\testPersonalPage.py"
            )
        ])

    def main(self):
        """
        Android 测试入口方法, 根据连接的手机设备启动AppiumServer
        1、读取所有手机配置信息
        2、检查已经连接电脑的手机设备的udid
        3、获取已连接设备的 配置信息
        4、启动Appium 设备
        :return:
        """
        driverConfigPath = self.path.androidDriverPath
        driverData = self.yaml.getStream(driverConfigPath)

        connetcDriver = getConnectUdid()

        desired_pool = []
        for udid in connetcDriver:
            if udid not in driverData:
                DriverUdidNotExit("配置文件没有设备:{0}的信息".format(udid))

            for data in driverData:
                if data["udid"] == udid:
                    break

            udid = data["udid"]
            host = data["host"]
            port = data["port"]
            server = AppiumServer(host, port, udid)
            server.startAppiumServer()

            pool = multiprocessing.Process(target=self.startAppiumServer,
                                           args=(data, ))
            desired_pool.append(pool)

        for pool in desired_pool:
            pool.start()

        for pool in desired_pool:
            pool.join()
Example #5
0
class ClassGroupPage(object):
    def __init__(self, driver):
        self.driver = driver
        self.readyaml = ReadYaml()
        self.base = BaseApi(self.driver)
        self.imImdexPage = self.readyaml.getStream(FilePath.iOSImIndexPage)
        self.reconnect = self.imImdexPage.get("reconnect")
        self.searchButton = self.imImdexPage.get("searchButton")
        self.searchFild = self.imImdexPage.get("searchFild")
        self.QuestionResonse = self.imImdexPage.get("QuestionResonse")
        self.DoubtResonse = self.imImdexPage.get("DoubtResonse")
        self.classGroupResonse = self.imImdexPage.get("classGroupResonse")

        self.addressButton = self.imImdexPage.get("addressButton")
        self.systemNotice = self.imImdexPage.get("systemNotice")
        self.doubtButton = self.imImdexPage.get("doubtButton")
        self.classGroupButton = self.imImdexPage.get("classGroupButton")

    def switchSystem(self):
        """
        点击进入系统消息
        :return:
        """
        self.base.iosClick(self.systemNotice)

    def switchAdders(self):
        """
        点击进入通讯录
        :return:
        """
        self.base.iosClick(self.addressButton)

    def indexSearch(self, searchContent, searchType):
        """
        校园首页搜索
        :param searchContent:
        :param searchType:
        :return:
        """
        pass

    def switchDoubt(self):
        """
        选择问答
        :return:
        """
        self.base.iosClick(self.doubtButton)

    def switchClassGroup(self):
        """
        选择班级
        :return:
        """
        self.base.iosClick(self.classGroupButton)
Example #6
0
 def testcChangePassword(self, driver, driverFunc):
     updateChangePassword = UpdateChangePassword(driver)
     readYaml = ReadYaml()
     user = readYaml.getStream(FilePath.androidLoginParams)
     passWord = user[0]["password"]
     new_password = '******'
     updateChangePassword.update(passWord, new_password)
     user_id = user[0]["account"]
     updateChangePassword.checkUpdateRes(user_id, new_password)
     updateChangePassword.update(new_password, passWord)
     updateChangePassword.checkUpdateRes(user_id, passWord)
     time.sleep(5)
Example #7
0
class ImAdderPage(object):
    __metaclass__ = abc.ABCMeta

    def __init__(self, driver, db):

        self.readYaml = ReadYaml()
        self.base = BaseApi(driver)
        self.login = Login(driver)
        self.db = db
        self.classGroupPage = ClassGroupPage(driver)
        self.adderPage = self.readYaml.getStream(FilePath.iOSImAdderPage)
        self.add_friend_button = self.adderPage.get("add_friend_button")
        self.add_friend_textField = self.adderPage.get("add_friend_textField")
        self.keybody_search_button = self.adderPage.get(
            "keybody_search_button")
        self.start_chat_button = self.adderPage.get("start_chat_button")
        self.addFriends = self.adderPage.get("addFriends")
        self.sendViryMsg = self.adderPage.get("sendViryMsg")
        self.cancelButton = self.adderPage.get("cancelButton")
        self.back_adder_button = self.adderPage.get("back_adder_button")
        self.back_im_list_button = self.adderPage.get("back_im_list_button")
        self.systemAddFriend = self.adderPage.get("systemAddFriend")
        self.agreeButton = self.adderPage.get("agreeButton")

    @abc.abstractmethod
    def addFirend(self, *args, **kwargs):
        """
        添加好友
        :return:
        """
        pass

    @abc.abstractmethod
    def newFridentSearch(self, *args, **kwargs):
        """
        新朋友搜索
        :param args:
        :param kwargs:
        :return:
        """
        pass

    @abc.abstractmethod
    def imGroup(self, groupName):
        """
        班组
        :param groupName: 班组名称
        :return:
        """
        pass
Example #8
0
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
Example #9
0
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
Example #10
0
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)
Example #11
0
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
Example #12
0
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
Example #13
0
class DbOption(object):
    def __init__(self):
        self.mylogger = MyLogger(self.__class__.__name__).getlogger()
        self.read = ReadYaml()
        btclassDB = self.read.getStream(FilePath.dbConfigPath)["DB_data"]
        self.host = btclassDB["host"]
        self.username = btclassDB["username"]
        self.password = btclassDB["password"]
        self.port = btclassDB["port"]
        self.basename = btclassDB["basename"]
        self.conn = None

    def connect(self):
        try:
            self.conn = pymysql.connect(host=self.host,
                                        user=self.username,
                                        passwd=self.password,
                                        db=self.basename,
                                        port=self.port,
                                        charset='utf8')

        except Exception as msg:
            self.mylogger.info("数据库连接错误:{0}".format(msg))
        return self.conn

    def reconnect(self):
        """
        数据库重连机制
        :return:
        """
        try:
            self.conn.ping()
            return False
        except:
            return self.connect()

    def select(self, sql):
        cursor = self.connect().cursor()
        try:
            reconnect = self.reconnect()
            if reconnect:
                cursor = reconnect.cursor()
            cursor.execute(sql)
            data = cursor.fetchall()
        except Exception as msg:
            self.mylogger.info("sql查询错误:{0}".format(msg) + "\n" +
                               "错误sql:{0}".format(sql))
            data = ()
        cursor.close()
        self.conn.close()
        return data

    def operation(self, sql):
        cursor = self.connect().cursor()
        try:
            reconnect = self.reconnect()
            if reconnect:
                cursor = reconnect.cursor()
            cursor.execute(sql)
            self.conn.commit()
        except Exception as msg:
            self.conn.rollback()
            self.mylogger.info("sql:{0} 操作失败:{1}".format(msg, sql))
        cursor.close()
        self.conn.close()