def run(dname, loop, rtype): global DEVICENAME, DEVICE, LogPath global LOOP_NUM, RESULT_DICT, FAIL_CASE, RUN_ID DEVICENAME = dname DEVICE = device.Device(DEVICENAME) # run test case logname = desktop.get_log_name(dname, 'TestMemory') LogPath = os.path.dirname(os.path.abspath(logname)) utest_log = os.path.join(LogPath, 'unittest.html') # ##RESULT_DICT format {casename:{Result:['PASS','PASS'],Log:['','']}}##### RESULT_DICT = {} FAIL_CASE = [] # insert run info to database dname = sys.argv[1] slist = sys.argv[2] vname = device_config.getValue(dname, 'version') RUN_ID = tc.insert_runinfo(slist, dname, vname, loop, rtype) try: for LOOP_NUM in range(loop): fileobj = file(utest_log, 'a+') if LOOP_NUM == 0 or rtype.upper() == 'ALL': suite = unittest.TestLoader().loadTestsFromTestCase( TestMemoryCPU) else: suite = unittest.TestSuite() for name in FAIL_CASE: suite.addTest(TestMemoryCPU(name)) FAIL_CASE = [] if suite.countTestCases() > 0: runner = HTMLTestRunner.HTMLTestRunner( stream=fileobj, verbosity=2, loop=LOOP_NUM, title='Test Memory&CPU Report', description='Test Result', ) runner.run(suite) fileobj.close() sleep(5) # write log to summary report if LOOP_NUM == loop - 1: desktop.summary_result(utest_log, True, RESULT_DICT) TestLinkObj.write_result_to_testlink(DEVICENAME, RESULT_DICT) else: desktop.summary_result(utest_log, False, RESULT_DICT) except Exception, ex: print ex
def run(dname, loop, rtype): global DEVICENAME, CONFIG, DEVICE, LogPath global LOOP_NUM, RESULT_DICT, FAIL_CASE CONFIG = configuration.configuration() fname = PATH('../config/' + 'configuration.ini') CONFIG.fileConfig(fname) DEVICENAME = dname DEVICE = device.Device(DEVICENAME) # initial test environment init_env() # run test case logname = desktop.get_log_name(dname, 'TestTasks') LogPath = os.path.dirname(os.path.abspath(logname)) utest_log = os.path.join(LogPath, 'unittest.html') # ##RESULT_DICT format {casename:{Result:['PASS','PASS'],Log:['','']}}##### RESULT_DICT = {} FAIL_CASE = [] try: for LOOP_NUM in range(loop): fileobj = file(utest_log, 'a+') if LOOP_NUM == 0 or rtype.upper() == 'ALL': suite = unittest.TestLoader().loadTestsFromTestCase(TestTask) else: suite = unittest.TestSuite() for name in FAIL_CASE: suite.addTest(TestTask(name)) FAIL_CASE = [] if suite.countTestCases() > 0: runner = HTMLTestRunner.HTMLTestRunner( stream=fileobj, verbosity=2, title='Task Testing Report', description='Test Result', ) runner.run(suite) fileobj.close() sleep(5) # write log to summary report if LOOP_NUM == loop - 1: desktop.summary_result(utest_log, True, RESULT_DICT) else: desktop.summary_result(utest_log, False, RESULT_DICT) except Exception, ex: print ex
def init_module_version(uid, test_path): init_result = False # # delete old apk file # logger.debug('step: delete old apk file') # del_path = module_config.getValue(test_path, 'device_delete_apk_path') # logger.debug('step: delete old apk file from ' + del_path) # del_path = os.path.join(del_path, '*.apk') # device.remove(del_path) # # # clear app # pkg_name = module_config.getValue(test_path, 'pkg_name') # logger.debug('step: clear pkg content ' + pkg_name) # device.clear_app_data(pkg_name) # logger.debug('step: clear system ui') # device.clear_app_data('com.android.systemui') # # # push new api file # source = module_config.getValue(test_path, 'push_orig_path') # target = module_config.getValue(test_path, 'push_dest_path') # logger.debug('step: push apk file to device') # device.push(source, target) ######################################################################### # # reboot and unlock screen da = action.DeviceAction(uid) logger.debug('step: reboot device and unlock screen') da.reboot_device('default') da.unlock_screen('default') # self-activation pkg_name = module_config.getValue(test_path, 'pkg_name') acti_flag = module_config.getValue(test_path, 'self_activation') product_type = device_config.getValue(uid, 'product_type') if acti_flag.upper() == 'FALSE': logger.debug('step: access to vlife theme, start-up main process') if product_type.upper() == 'THEME': theme.set_device_theme(uid, 'vlife') # configure server option mid_list = module_config.getValue(test_path, 'module_upgrade_path').split(';') count = 0 try: for mid in mid_list: logger.debug('step: config server and enable module ') tc.update_stage_module_status(int(mid), True) flag1 = tc.update_stage_module_network(int(mid), 1, 0) flag2 = tc.check_amount_limit(int(mid)) if flag1 or flag2: config_srv.enableModule('STAGECONFIG') #connect network and waiting for module download logger.debug('step: connect network and download module') for i in range(2): da.connect_network_trigger('CLOSE_ALL:ONLY_WIFI') #check module has download config_dict = {"module": mid} result = tc.get_all_module_info(config_dict) search_path = result['module']['path'] soft_version = result['module']['version'] full_path = os.path.join(r'/data/data/', pkg_name, os.path.dirname(search_path)).replace( '\\', '/') base_name = os.path.basename(search_path) res = device.find_file_from_appfolder(pkg_name, full_path) if res.find(base_name) != -1: logger.debug('step: module is download successfully, ' + search_path + ' has found') # reboot and unlock screen for applying module logger.debug('step: reboot device') da.reboot_device('default') da.unlock_screen('default') # start collect log name = desktop.get_log_name(uid, 'SmokeModule') #LogPath = os.path.dirname(os.path.abspath(name)) log_reader = dumplog.DumpLogcatFileReader(name, uid) log_reader.clear_logcat() log_reader.start() #connect network and waiting for module download logger.debug('step: connect network and download module') for i in range(2): da.connect_network_trigger('CLOSE_ALL:ONLY_WIFI') sleep(10) log_reader.stop() # get pid of app pkg_pid = device.get_pid(pkg_name) #check log for login package and verify if module update loginfo = filter_log_result(name, 'jabber:iq:auth', pkg_pid) init_result = verify_pkg_content(loginfo, soft_version) if init_result: logger.debug('step: module is made effect for ' + str(mid)) if count == len(mid_list) - 2: sid = module_config.getValue('COMMON', 'basic_fun_suite_id') cmd = ' '.join(['run', uid, str(sid)]) subprocess.Popen(cmd, shell=True, stdout=None) # test new module for upgrade device_config.setValue(uid, 'background_module_id1', mid_list[count + 1]) sid = module_config.getValue('COMMON', 'upgrade_fun_suite_id') cmd = ' '.join(['run', uid, str(sid)]) subprocess.call(cmd, shell=True, stdout=None) break count += 1 else: logger.error('step: module is not made effect for ' + str(mid)) break else: logger.error('step: module is not downloaded successfully') break except Exception, ex: print ex
newParser.add_argument("-u", "--uid", dest="uid", help="Your device uid") args = newParser.parse_args() uid = args.uid if uid is None: sys.exit(0) # verify if device is connected devices = device.Device.get_connected_devices() if uid not in devices: print "Device is not connected, please check" sys.exit(0) my_device = device.Device(uid) logname = desktop.get_log_name(uid, 'verify.html') # create test log if not os.path.exists(logname): write_html_header(logname, 'Verify Advertisement') my_logger = log.Log(logname) #start_service() loop_number = 0 TestFlag = True dtime = CONFIG.getValue('Common', 'duration') dtime = 300 # start-up service and monitor logcat logpath = os.path.dirname(logname)
if uid not in devices: print "Device is not connected, please check" sys.exit(0) try: # verify if device is configuration config = configuration.configuration() config.fileConfig(myglobal.CONFIGURATONINI) config.setValue(uid, 'port', str(port)) except Exception, ex: print "There is no related configuration information" sys.exit(0) try: pid = 0 filename = desktop.get_log_name(uid, 'result.log') config.setValue(uid, 'logname', filename) fileobj = file(filename, 'a+') status, appium_process = desktop.launch_appium(uid, port, bport) pid = appium_process.pid if status == "READY": # test_schedule.init_device_environment(uid,port,test_logger,filename) # suite = unittest.TestLoader().loadTestsFromTestCase(test_module) case_list = config.getValue(uid, 'test_list').split(';') for cases in case_list: module, mod = my_import(cases) module.init_device_environment(uid, port, filename) suite = unittest.TestLoader().loadTestsFromName(cases) unittest.TextTestRunner(stream=fileobj, verbosity=2).run(suite) except Exception, ex:
newParser.add_argument("-u", "--uid", dest="uid", help="Your device uid") args = newParser.parse_args() uid = args.uid if uid is None: sys.exit(0) # verify if device is connected devices = device.Device.get_connected_devices() if uid not in devices: print "Device is not connected, please check" sys.exit(0) my_device = device.Device(uid) logname = desktop.get_log_name(uid, 'resource', '.html') logdir = os.path.abspath(os.path.dirname(logname)) # create test log if not os.path.exists(logname): write_html_header(logname, 'Verify LockScreen Source') my_logger = log.Log(logname) # filter data vendor = resource_config.getValue(uid, 'vendor') datas = get_test_resource(vendor) try: for dt in datas: if dt['alias'] is not None and dt['alias'] != '':