• pageobject框架下多人操作,页面元素和测试数据的优化


    前言:人生就像一杯茶,不会苦一辈子,但总会苦一阵子。

    遇到的问题:单人操作时,元素信息和测试数据均存放在一个excel表格中。若遇到多人操作,很容易报错。

    解决方案:将元素信息和测试数据表格按模块区分

    一、单人操作:

    1、元素信息存放形式如下:

    2、测试数据信息存放形式如下:

     二、多人操作

    1、页面元素信息表

     2、测试数据表样式

    三、表格优化后的代码

    1、excel_data_utils

    import os
    import xlrd
    from common.config_utils import local_config
    
    current_path = os.path.dirname(__file__)
    excel_path = os.path.join( current_path,'..',local_config.element_info_path )
    
    class ElementdataUtils:
        def __init__(self,module_name,page_name,element_path=excel_path):
            self.element_path = element_path
            self.excel_path = os.path.join(self.element_path,module_name,page_name+'.xlsx')
            self.workbook = xlrd.open_workbook(self.excel_path)
            self.sheet = self.workbook.sheet_by_index(0)
            self.row_count = self.sheet.nrows
    
        def get_element_info(self):
            element_infos = {}
            for i in range(1, self.row_count):
                element_info = {}
                element_info['element_name'] = self.sheet.cell_value(i, 1)
                element_info['locator_type'] = self.sheet.cell_value(i, 2)
                element_info['locator_value'] = self.sheet.cell_value(i, 3)
                timeout_value = self.sheet.cell_value(i, 4)
                element_info['timeout'] = timeout_value if isinstance(timeout_value,float) else local_config.time_out
                element_infos[self.sheet.cell_value(i, 0)] = element_info
            return element_infos
    
    if __name__=="__main__":
        # s = ElementdataUtils('login_page')
        elements = ElementdataUtils('main','main_page').get_element_info()
        # print(elements)
        for e in elements.values():
            print( e )

    2、test_data_utils

    import os
    from common.excel_utils import ExcelUtils
    from common.config_utils import local_config
    
    current_path = os.path.abspath(os.path.dirname(__file__))
    test_data_path = os.path.join( current_path , '..' , local_config.testdata_path )
    
    class TestDataUtils:
    
        def __init__(self,test_suite_name,test_file_name,test_class_name=None,test_data_path=test_data_path):
            test_data_path = os.path.join( test_data_path,test_suite_name,test_file_name+'.xlsx' )
            self.excel_data = ExcelUtils( test_data_path , test_class_name ).get_sheet_data_by_list()
            self.excel_rows = len(self.excel_data)
    
        def convert_exceldata_to_testdata(self):
            # {'test_login_success':
            #      {'test_name':'验证是否能成功进行登录','isnot':'是','excepted_result':'测试人员1','test_parameter':{'username':'test01','password':'newdream123'} }
            #  'test_login_fail':
            #      { }
            #  }
            test_data_infos = {}
            for i in range(1,self.excel_rows): # 1,2
                test_data_info = {}
                test_data_info[ 'test_name' ] = self.excel_data[i][1]
                test_data_info[ 'isnot' ] = False if self.excel_data[i][2].__eq__('是') else True
                test_data_info[ 'excepted_result' ] = self.excel_data[i][3]
                test_parameter = {}
                for j in range( 4, len(self.excel_data[i]) ):
                    if self.excel_data[i][j].__contains__('=') and len( self.excel_data[i][j] ) > 2 :
                        parameter_info = self.excel_data[i][j].split('=')
                        test_parameter[ parameter_info[0] ] = parameter_info[1]
                test_data_info[ 'test_parameter' ] = test_parameter
                test_data_infos[ self.excel_data[i][0] ] = test_data_info
            return test_data_infos
    
    if __name__ == '__main__':
        infos = TestDataUtils('login_suite','login_test').convert_exceldata_to_testdata()
        for i in infos.values():
            print( i )
    

      

  • 相关阅读:
    SVN使用方法
    NHiberante3.2 调用存储过程之Errors in named queries:
    AjaxFileUpload + *.ashx 文件上传在IE8.0(XP,VS2010,Development Server)下的注意
    PB中设置SQLCA.AutoCommit = False的说明
    UrlRoutingModel摘要
    PB中的大数据量插入操作测试
    PB TreeView控件
    关于端口共用
    关于RealProxy
    EF无法更新错误
  • 原文地址:https://www.cnblogs.com/miaoxiaochao/p/12901650.html
Copyright © 2020-2023  润新知