问题描述

当前我是将断言和业务流程封装在 page 对象之中,然后在 unittest 直接去调用对应的方法执行,没有单独使用 unittest 的 assert 断言。部分代码所下所示:

page 层-DeepRecoveryView

class DeepRecoveryView(RecycleBinView,BasicRecoveryView):
    btnDeepRecovery=(By.ID,'com.wondershare.drfone:id/btnDeepRecovery')
    nextBtn=(By.ID,'com.wondershare.drfone:id/btnRecoverData')
    try_DeeprecoverBtn=(By.ID,'com.wondershare.drfone:id/onePageTxt')


    dialog_ok=(By.ID,'com.wondershare.drfone:id/dialog_ok')
    btnHideDeepRecovery=(By.ID,'com.wondershare.drfone:id/btnHideDeepRecovery')

    def deep_recover_h5_action(self):
        ''' 扫描完成后下一步进行发送邮件操作'''

        # 等待next按钮出现
        WebDriverWait(self.driver, 20).until(lambda x: x.find_element(*self.nextBtn_loc))
        #点击next按钮
        self.find_element(*self.nextBtn_loc).click()
        self.type_h5_action()

    def check_recycleBin(self):
        '''
        检测扫描结果页面是否存在资源
        :return: True,False
        '''
        try:
            self.find_element(*self.imageBtn)
        except NoSuchElementException:
            logging.info('No resource')
            return False
        else:
            logging.info('Resource exist!')
            return True

    def deepRecovery_from_recycleBin(self):
        '''
        从recycle bin进入
        '''
        self.open_recycleBin_page()
        #如果存在资源则直接点击资源下方的Banner菜单,没有资源则点击界面文字“Deep recobery”
        logging.info('========deepRecovery_from_recycleBin==========')

        if self.check_recycleBin():
            #点击页面下方banner栏恢复
            self.getScreenShot('deepRecovery_from_recycleBin')
            self.find_element(*self.try_DeeprecoverBtn).click()
            self.deep_recover_h5_action()
        else:
            #点击页面深度恢复文字提示
            self.getScreenShot('deepRecovery_from_recycleBin')
            self.find_element(*self.btnDeepRecovery).click()
            self.deep_recover_h5_action()

        #退出到主界面
        for i in range(3):
            self.find_element(*self.closeBtn).click()

    def deepRecover_from_RecoverMenu(self):
        '''
        从Recovery 主菜单页面 进入
        '''
        logging.info('============= deepRecover_from_RecoverMenu =============')
        #进入recover界面主页
        self.find_element(*self.basic_recoveryBtn).click()
        self.getScreenShot('deepRecover_from_RecoverMenu')
        #点击deep recovery
        self.find_element(*self.btnDeepRecovery).click()
        self.deep_recover_h5_action()

        # 退出到主界面
        for i in range(3):
            self.find_element(*self.closeBtn).click()

    def deepRecover_from_quickRecover(self):
        '''
        #从quickRecovery 进入
        '''
        logging.info('===============deepRecover_from_quickRecover============')
        self.open_quickRecover_page()
        if self.check_quickRecover_resource():
            #如果存在资源向上滑动屏幕
            self.swipeUp()
            self.find_element(*self.btnHideDeepRecovery).click()
            self.getScreenShot('deepRecover_from_quickRecover')
            self.deep_recover_h5_action()

        else:
            # 没有资源点击页面深度恢复文字提示
            logging.info('start click btnDeepRecovery')
            self.getScreenShot('deepRecover_from_quickRecover')
            self.find_element(*self.btnDeepRecovery).click()
            self.deep_recover_h5_action()

        # 退出到主界面
        for i in range(4):
            self.find_element(*self.closeBtn).click()

unittest

class TestDeepRecovery(StartEnd):
    @tag(Tag.DR,Tag.SMOKE,Tag.DR_High)
    def test_deepRecovery_from_recycleBin(self):
        """从recycleBin入口恢复"""
        deep=DeepRecoveryView(self.driver)
        deep.deepRecovery_from_recycleBin()

    @tag(Tag.DR,Tag.SMOKE,Tag.DR_High)
    def test_deepRecover_from_RecoverMenu(self):
        """从Recover主菜单恢复"""
        deep=DeepRecoveryView(self.driver)
        deep.deepRecover_from_RecoverMenu()

但是看到一种说法说这样会 混合访问页面数据和断言逻辑的职责,导致 page 层过于臃肿,不应当在 page 层中包含断言,不知大家是如何设计断言的?


↙↙↙阅读原文可查看相关链接,并与作者交流