How to use before_case method in lisa

Best Python code snippet using lisa_python

update_testlink_cases.py

Source:update_testlink_cases.py Github

copy

Full Screen

1#!/usr/bin/python -u2import os, sys, re3import time4from pprint import pprint5from pprint import pformat6import logging7from copy import deepcopy8import signal9from optparse import OptionParser10#import subprocess,signal,select11print(sys.argv)12argc = len(sys.argv)13if argc < 2:14 print('You need pass 2 parameters : %s DUT "tl_case_name at_tst_name at_case_name" ' % sys.argv[0])15 exit(1)16print("\n" * 10)17print('Argv : %s' % str(sys.argv) )18[dut_types, para] = sys.argv[1:]19dut_type = 'TMPL_TST'20tl_case = ''21at_tst = ''22at_case = ''23z = para.split()24if len(z) == 3:25 tl_case = z[0].strip()26 at_tst = z[1].strip()27 at_case = z[2].strip()28else:29 print('[ERROR] : %s' % para)30 exit(1)31m = r'[^/]*\.tst'32z = re.findall(m, at_tst)33if len(z):34 at_tst = z[0]35 pass36m = r'[^/]*\.xml'37z = re.findall(m, at_case)38if len(z):39 at_case = z[0]40 pass41#print(at_tst,at_case)42#exit(1)43#[dut_type,tl_case,at_tst,at_case] = ['TV2KH','00400031','ping.tst','No-17311__Ping_Test_with_WAN_URL']44# Find tl_case_file45case = {46 'fn_tl_case': '',47 'fn_at_run_cfg': '',48 'fn_at_tst': '',49 #50 'precondition': [],51 'pre_jobs': [],52 'pre_check': [],53 'premise': [],54 'jobs': [],55 'after_jobs': [],56 'postcondition': [],57}58print('--' * 16)59print('\n\n')60z = dut_types.split(',')61if len(z) == 1:62 dut_type = z[0]63 pass64else:65 dut_type = 'TMPL_TST'66print('==> %s' % dut_type)67tst_path = '/root/automation/testsuites/2.0'68tl_case_path = os.path.join(tst_path, dut_type + '/tl_cases')69cmd = 'find %s -type f | grep %s | grep -e "case$" ' % (tl_case_path, tl_case)70print('==> [TODO] : Find testlink case with command : %s' % cmd)71resp = os.popen(cmd).read().strip()72if len(resp) and os.path.exists(resp):73 #tl_case = resp74 case['fn_tl_case'] = resp75 print('==> [PASS] : Find testlink case : %s' % resp )76 pass77else:78 print('==> [FAIL] : Find testlink case : %s' % resp )79 print('[ERROR] : %s' % para)80 exit(1)81#print('--'*16)82#print('\n\n')83# Find run.cfg84#print('==> [TODO] : Find run.cfg')85#run_cfg_path = os.path.join(tst_path,'%s/run.cfg'%(dut_type))86#if os.path.exists(run_cfg_path):87# print('==> [PASS] : Find run.cfg file : %s' % (run_cfg_path) )88# pass89#else :90# print('==> [FAIL] : Find run.cfg file : %s' % run_cfg_path )91# exit(1)92print('--' * 16)93print('\n\n')94found = False95for dut in z:96 print('==> [%s] : Find tst file(%s) contains at case(%s)' % ('TODO', at_tst, at_case) )97 run_cfg_path = os.path.join(tst_path, '%s/run.cfg' % (dut))98 at_tst_path = os.path.join(tst_path, '%s/tsuites' % (dut))99 cmd = 'grep %s %s' % (at_tst, run_cfg_path)100 resp = os.popen(cmd).read().strip()101 if not len(resp):102 continue103 cmd = 'grep -r -i %s %s | grep /%s | grep -e "-tc" | grep -i "%s" ' % (at_case, at_tst_path, at_tst, at_case)104 resp = os.popen(cmd).read().strip()105 #print(resp)106 #exit(0)107 if len(resp):108 p = resp.find(':')109 #tl_case = resp110 case['fn_at_tst'] = resp[:p]111 #case['jobs'] = [resp[p+1:]]112 #print('jobs : %s' % (case['jobs']) )113 print('==> [%s] : Find tst file contains at case : %s' % ('PASS', case['fn_at_tst']) )114 found = True115 break116 else:117 #print('==> [%s] : Find tst file contains at case : %s' % ('FAIL',case['fn_at_tst']) )118 #print(cmd)119 #exit(1)120 pass121if not found:122 print('==> [%s] : Find tst file contains at case : %s' % ('FAIL', case['fn_at_tst']) )123 #print(cmd)124 print('[ERROR] : %s' % para)125 exit(1)126print('--' * 16)127print('\n\n')128print('==> [%s] : Find tst tst precondition in run.cfg' % ('TODO'))129fd = open(run_cfg_path, 'r')130lines = []131if fd:132 lines = fd.readlines()133 fd.close()134 pass135last_pre = ''136for line in lines:137 m = r'-f .*/pre_.*\.tst'138 res = re.findall(m, line)139 if len(res):140 last_pre = res[0]141 pass142 else:143 m = at_tst144 res = re.findall(m, line)145 if len(res):146 break147 else:148 pass149 pass150 pass151if last_pre:152 print('==> [%s] : Find tst tst precondition in run.cfg : \n %s' % ('PASS', last_pre))153 case['precondition'].append(last_pre)154 pass155else:156 print('==> [%s] : Find tst tst precondition in run.cfg' % ('FAIL'))157 pass158print('--' * 16)159print('\n\n')160print('==> [%s] : Load tst file(%s) contains at case(%s) ' % ('TODO', at_tst, at_case) )161fd = open(case['fn_at_tst'], 'r')162lines = []163if fd:164 lines = fd.readlines()165 fd.close()166 pass167before_case = True168before_nextcase = True169overwrite_pre = True170for linenum, line in enumerate(lines):171 if line.startswith('#'):172 continue173 # precondition174 m = r'-f .*/pre_(.*)\.tst'175 res = re.findall(m, line)176 if len(res):177 if overwrite_pre:178 overwrite_pre = False179 print('--> empty precondition')180 case['precondition'] = []181 z = case['precondition']182 if not before_case:183 z = case['postcondition']184 continue185 #pass186 #187 if not line.startswith('#'):188 if line not in z:189 z.append(line)190 print('==> add precondition (%d : %s)' % (linenum, res[0]))191 continue192 else:193 pass194 #pre-jobs195 m = '-tc.*%s.*' % at_case196 res = re.findall(m, line)197 if len(res):198 case['jobs'].append(line)199 before_case = False200 print('==> Find case (%d : %s)' % (linenum, line))201 #break202 continue203 else:204 pass205 #206 m = '-nc.*'207 res = re.findall(m, line)208 if len(res):209 z = case['pre_jobs']210 if not before_case:211 z = case['after_jobs']212 if not before_nextcase:213 continue214 pass215 if len(z):216 last = z[-1]217 if last == line:218 continue219 pass220 z.append(line)221 continue222 else:223 pass224 #225 m = '-tc.*'226 res = re.findall(m, line)227 if len(res):228 if before_case:229 #case['precondition'] = []230 pass231 else:232 before_nextcase = False233 #case['after_jobs'].append(res[0])234 pass235 #break236 continue237 else:238 pass239 if line.startswith('-pre_cmdline'):240 case['pre_check'].append(line.strip())241 continue242 else:243 pass244 if len(line.strip()) and not line.startswith('#'):245 if before_case:246 case['pre_jobs'].append(line)247 pass248 else:249 if before_nextcase:250 case['after_jobs'].append(line)251 else:252 if line.startswith('-label'):253 case['after_jobs'].append(line)254 pass255pprint(case)256### process raw data257print('--' * 16)258print('\n\n')259print('==> Process Raw Data' )260#precondition261prec = case['precondition']262d = []263prec.reverse()264for v in prec:265 if v not in d:266 d.append(v)267 if v.find('pre_tr') > 0:268 pass269 else:270 break271d.reverse()272case['precondition'] = d273# pre_jobs274prej = case['pre_jobs']275d = []276prej.reverse()277vlist = []278vlist_uniq = []279vlist_duplicate = []280for v in prej:281 m = r'(\w*)\s*=(.*)'282 res = re.findall(m, v)283 if len(res):284 key, val = res[0]285 if key not in vlist:286 vlist.append(key)287 vlist_uniq.append(key)288 d.append(v)289 pass290 else:291 vlist_duplicate.append(key)292 if key in vlist_uniq:293 vlist_uniq.remove(key)294 continue295 if v not in d:296 d.append(v)297 pass298d.reverse()299case['pre_jobs'] = d300print('==>Duplicate variables : %s ' % str(vlist_duplicate) )301print('==>Uniq variables : %s ' % str(vlist_uniq) )302#303# after_jobs304prej = case['after_jobs']305d = []306prej.reverse()307vlist = []308for v in prej:309 m = r'(\w*)\s*=(.*)'310 res = re.findall(m, v)311 if len(res):312 key, val = res[0]313 if key not in vlist:314 vlist.append(key)315 d.append(v)316 pass317 else:318 continue319 if v not in d:320 d.append(v)321 pass322d.reverse()323case['after_jobs'] = d324pprint(case)325# save to file326#327"""328case = {329 'fn_tl_case' : '',330 'fn_at_run_cfg' : '',331 'fn_at_tst' : '',332 #333 'precondition' : [],334 'pre_jobs' : [],335 'premise' : [],336 'jobs' : [],337 'after_jobs' : [],338 'postcondition' : [],339}340"""341print('--' * 16)342print('\n\n')343print('==> case content' )344comment = """345#346# The data is collecting from file : %s347#348""" % (case['fn_at_tst'])349postfiles = ''350rpcfiles = ''351pre = '-SUITE_PRECONDITION_BEGIN\n%s\n-SUITE_PRECONDITION_END\n\n' % ('\n'.join(case['precondition']) )352pre_jobs = '-SUITE_PRE_JOBS_BEGIN\n%s\n-SUITE_PRE_JOBS_END\n\n' % ('\n'.join(case['pre_jobs']) )353pre_check = '-CASE_PRE_CHECK_BEGIN\n%s\n-CASE_PRE_CHECK_END\n\n' % ('\n'.join(case['pre_check']) )354premise = '-CASE_DEPENDENT_BEGIN\n%s\n-CASE_DEPENDENT_END\n\n' % ('\n'.join(case['premise']) )355jobs = '-CASE_BEGIN\n%s\n-CASE_END\n\n' % ('\n'.join(case['jobs']) )356after_jobs = '-CASE_AFTER_JOBS_BEGIN\n%s\n-CASE_AFTER_JOBS_END\n\n' % ('\n'.join(case['after_jobs']) )357postcondition = '-SUITE_POSTCONDITION_BEGIN\n%s\n-SUITE_POSTCONDITION_END\n\n' % ('\n'.join(case['postcondition']) )358pre_jobs = '-CASE_PRE_JOBS_BEGIN\n\n\n-CASE_PRE_JOBS_END\n\n'359z = [comment, postfiles, rpcfiles, pre, pre_jobs, pre_check, premise, jobs, after_jobs, postcondition]360o = "\n\n###############################\n".join(z)361fmt = """362#363#Import from file : %s364#365################################################################################366-SUITE_PRECONDITION_BEGIN367%s368-SUITE_PRECONDITION_END369################################################################################370-SUITE_PRE_JOBS_BEGIN371%s372-SUITE_PRE_JOBS_END373################################################################################374-CASE_PRE_JOBS_BEGIN375%s376-CASE_PRE_JOBS_END377################################################################################378-SUITE_PRE_CHECK_BEGIN379%s380-SUITE_PRE_CHECK_END381################################################################################382-CASE_PRE_CHECK_BEGIN383%s384-CASE_PRE_CHECK_END385################################################################################386-CASE_POST_FILES_BEGIN387%s388-CASE_POST_FILES_END389################################################################################390-CASE_TR69RPC_FILES_BEGIN391%s392-CASE_TR69RPC_FILES_END393################################################################################394-CASE_DEPENDENT_BEGIN395%s396-CASE_DEPENDENT_END397################################################################################398-CASE_BEGIN399%s400-CASE_END401################################################################################402-CASE_AFTER_JOBS_BEGIN403%s404-CASE_AFTER_JOBS_END405################################################################################406-SUITE_POSTCONDITION_BEGIN407%s408-SUITE_POSTCONDITION_END409"""410o = fmt % (case['fn_at_tst'],411 '\n'.join(case['precondition']),412 '\n'.join(case['pre_jobs']),413 '',414 '\n'.join(case['pre_check']),415 '',416 '',417 '',418 '\n'.join(case['premise']),419 '\n'.join(case['jobs']),420 '\n'.join(case['after_jobs']),421 '\n'.join(case['postcondition']),422)423#print(o)424# save to file425fn = case['fn_tl_case']426fd = open(fn, 'w')427if fd:428 fd.write(o)429 fd.close()...

Full Screen

Full Screen

test_group_remove.py

Source:test_group_remove.py Github

copy

Full Screen

...30 yield31 token = start_demo32 group_remove_all(token)33 @pytest.fixture(scope="function")34 def before_case(self, start_demo):35 token_1 = start_demo36 # 前置条件创建一个群组并且添加两个人,群组就有了user1,user2,user3 三个用户,群名称为新建三人群+一个时间戳37 res = group_create_with_users(token_1,38 user_ids=f"{user2_info['user_id']},{user3_info['user_id']}",39 group_name=f"新建三人群名称{int(time.time() * 100)}")40 yield res, token_141 @allure.story("群主解散一个群场景")42 @allure.title("test_group_owner_remove_group")43 def test_group_owner_remove_group(self, before_case):44 """45 1:断言删除这个群之前,查询这个群信息的 status状态等于046 2:群主user1解散群组操作47 3:断言群主解散一个群的返回值的code = 048 4:断言删除这个群之后 查询这个群信息的 status 状态等于 -1...

Full Screen

Full Screen

appium_test1.py

Source:appium_test1.py Github

copy

Full Screen

1from src.common.driver_configure import driver_configure2from src.common.base_page import Base_page3from src.util.before_case import Before_Case4from appium.webdriver.common import mobileby5drive=driver_configure ().get_driver ()6base_drive=Base_page ( drive )7by=mobileby.MobileBy ()8case=Before_Case(base_drive=base_drive,by=by)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run lisa automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful