def test_login(self,base_config_path,data_config_path): # 思路:1.获取测试数据;2.遍历执行每一条测试数据得到运行结果; # 3.实际结果actual与预期结果进行对比,如果一直证明测试通过,否则测试不通过提交缺陷 # 获取所有的登录用到的测试数据及预期结果 data_config_info = Utility.get_json(data_config_path) login_info = Utility.get_excel(data_config_info[0]) for login_data in login_info: Login(self.driver).do_login(base_config_path,login_data) # 判断登录是否成功,同时得到实际结果actual from selenium.webdriver.common.by import By from tools.service import Service if Service.is_element_present(self.driver, By.LINK_TEXT, '注销'): actual = 'login-pass' self.driver.find_element_by_link_text('注销').click() time.sleep(2) else: actual = 'login-fail' time.sleep(2) self.driver.refresh() # 对结果进行断言 flag = Utility.assert_equals(actual,login_data['expect']) if flag: print('test pass') else: print('test fail')
def send_email_url(self, email): """ send a email to reset password :param email: :return: """ pass rand_str = base64.b64encode(uuid.uuid4().bytes) m = hashlib.md5() m.update(rand_str) key = m.hexdigest() redis_inst = self.get_redis_inst() redis_inst.set(email, key, ex=600) conf = config.ConfigMgr.get("user_server", {}) url = "http://{host}:{port}/reset_psw?key={0}&email={1}".format(key, email, **conf) content = "请勿回复本邮件.点击下面的链接,重设密码<br/><a href=" + url + " target='_BLANK'>点击我重新设置密码</a>" \ + "<br/>tips:本邮件超过30分钟,链接将会失效,需要重新申请'找回密码'" subject = "teamwork 找回密码" try: Utility.send_email(subject=subject, contents=content, send_to=email) log.info("send a url:{0} to email successfully".format(url)) except Exception, e: log.exception("send url:{0} failed".format(url)) raise CustomMgrError("send url email failed")
class count_indian_surname_candidate_support: def __init__(self): self.indian_surnames = pandas.read_csv(Utility.ROOT + Utility.INDIAN_SURNAME_FILE_PATH) self.utility = Utility() self.states = self.utility.__extract_abbreviations__(self.utility) @staticmethod def run(self, state, last_name): results = {} if state == 'getAllStates': for state in self.states: results[state] = {} else: # Demo: this code just does MD results['MD'] = {} # results = Utility.multi_dict(self.utility, 3, str) # grab the contribution ID, total amount, and candidate, date for state in results: # self.utility.__get_pretty_printer__().pprint(last_name) contributor = rest.individualContributorSearchByState(rest.API_KEY, last_name, state) json_data = contributor.query() # Utility.__get_pretty_printer__().pprint(json_data) results[state][last_name] = json_data return results def parse_results(self, initial_results, last_name, recipient): for state,surname in initial_results.items(): # self.utility.__get_pretty_printer__().pprint(state) # self.utility.__get_pretty_printer__().pprint(surname) count = 0 results = {} values = list(surname.values()) for value in values: # self.utility.__get_pretty_printer__().pprint(value['pagination']) # count = value['pagination']['count'] if 'results' in value: results = value['results'] # self.utility.__get_pretty_printer__().pprint(count) # self.utility.__get_pretty_printer__().pprint(results) for result in results: # self.utility.__get_pretty_printer__().pprint(result) if result['contributor_last_name'] == last_name: self.utility.parse_memo_text_for_candidate(self.utility, result['memo_text'], last_name, state, recipient) else: results.remove(result) return results
def get_session(cls, sum): base_info = Utility.get_json('..\\config\\base.conf') login_url = "%s://%s:%s/%s/" % ( base_info['PROTOCOL'], base_info['HOSTNAME'], base_info['PORT'], base_info['AURL'],) # print(login_url) base_data = Utility.get_json('..\\config\\Account.conf') login_data = {'userName': base_data[sum]['userName'], 'userPass': base_data[sum]['userPass'], 'checkcode': base_data[sum]['checkcode']} # print(login_data) session = requests.session() resp = session.post(login_url, login_data) # print(resp.text) return session
class TransmitRescourcesTest(unittest.TestCase): #获取转交资源的测试数据 contents = Utility.get_json('../conf/yang/public_rescources_testinfo.conf') transmit_info=Utility.tran_tuple(contents[2]) # print(transmit_info) @classmethod def setUpClass(cls): warnings.simplefilter('ignore', ResourceWarning) def setUp(self): self.driver=Service.get_driver('../conf/yang/base.conf') self.driver.implicitly_wait(15) self.driver.maximize_window() #使用管理员进行登录,进入转交责任人 Service.ignor_login_decrypt(self.driver,'../conf/yang/base_admin.conf') self.tran=TransmitRescources(self.driver) def tearDown(self): self.driver.quit() @classmethod def tearDownClass(cls): pass # 测试查询 @parameterized.expand(transmit_info) def test_do_transmit_rescources(self,area_text_value,dpt_text_value,empname_text_value, \ status_text_value, source_text_value,name_text_value,transmit_area_value, transmit_dpt_value,transmit_empname_value,expect ): transmit_rescources_info={ "area_text_value":area_text_value,"dpt_text_value": dpt_text_value, "empname_text_value": empname_text_value,"status_text_value": status_text_value, "source_text_value": source_text_value,'name_text_value':name_text_value, "transmit_area_value": transmit_area_value,"transmit_dpt_value": transmit_dpt_value,"transmit_empname_value": transmit_empname_value} old_num=self.tran.do_query_rescources(transmit_rescources_info) # print(old_num) #随机执行分配 self.tran.do_transmit_rescources(int(old_num),transmit_rescources_info) # #再次执行搜索 new_num = self.tran.do_query_rescources(transmit_rescources_info) # print(new_num) time.sleep(2) if int(old_num) - int(new_num): actual='transmit-success' else: actual='transmit-fail' self.assertEqual(actual,expect)
def run_test(self): """ 如果数据不是csv,可以重载这个函数,转为df :return: """ if self.test_path is None: self.log.warning('test path is empty, set path in .yaml file firstly') return model_name = os.path.split(self.re_model_path)[-1] curr = Utility.timestamp2str_file() out_folder = model_name + curr if os.path.isdir(self.test_path): out_folder = os.path.join(self.test_path, out_folder) os.mkdir(out_folder) fs = os.listdir(self.test_path) for f in fs: out_path = os.path.join(out_folder, f) f = os.path.join(self.test_path, f) if os.path.isdir(f): continue self.log.info('input: {}'.format(f)) self.log.info('output: {}'.format(out_path)) df = pd.read_csv(f) self.test(df, out_path) elif os.path.isfile(self.test_path): fs = os.path.split(self.test_path) out_folder = os.path.join(fs[0], out_folder) os.mkdir(out_folder) out_path = os.path.join(out_folder, fs[-1]) self.log.info('input: {}'.format(self.test_path)) self.log.info('output: {}'.format(out_path)) df = pd.read_csv(self.test_path, lineterminator='\n') self.test(df, out_path)
def __init__(self): super().__init__() self.log = Utility.get_logger('aspect_dev') self.load_config('aspect_dev') # 由于使用了自定义的分词器,所以要在main模块中声明url_tokenizer函数,并且名字必须为url_tokenizer self.content_vocab_processor = learn.preprocessing.VocabularyProcessor.restore( self.config['vocab_pkl'])
def __init__(self): super().__init__() self.load_config('aspect_pro') self.reload_model() self.log = Utility.get_logger('aspect_pro') self.content_vocab_processor = learn.preprocessing.VocabularyProcessor.restore(self.config['vocab_pkl'])
def get_driver(cls, base_config_path): contents = Utility.get_json(base_config_path) from selenium import webdriver driver = getattr(webdriver, contents['BROWSER'])() driver.implicitly_wait(10) driver.maximize_window() return driver
class OverallTest(unittest.TestCase): # 获取测试数据 contents = Utility.get_json('../conf/peng/testinfo.conf') print(contents[0]) query_week_info = Utility.tran_tuple(contents[8]) print(query_week_info) @classmethod def setUpClass(cls): pass def setUp(self): self.driver = Service.get_driver("../conf/peng/base.conf") self.driver.implicitly_wait(10) self.score = OverallScore(self.driver) def tearDown(self): self.driver.close() @classmethod def tearDownClass(cls): pass @parameterized.expand(query_week_info) def test_query_score(self, s_area, s_name, s_stage, s_direction, s_sclass, expect): query_week_data = { "s_area": s_area, "s_name": s_name, "s_stage": s_stage, "s_direction": s_direction, "s_sclass": s_sclass } self.score.query_score(query_week_data) time.sleep(2) if Service.is_element_present(self.driver, By.CSS_SELECTOR, ".no-records-found > td:nth-child(1)"): actual = "none" else: num = self.score.get_student_total() if int(num) > 0: actual = "query-success" else: actual = "query-fail" self.assertEqual(actual, expect)
def miss_login(cls, driver, base_config_path): cls.open_page(driver, base_config_path) # 通过字典方式传递cookie信息 contents = Utility.get_json(base_config_path) driver.add_cookie({'name': 'username', 'value': contents['username']}) driver.add_cookie({'name': 'password', 'value': contents['password']}) cls.open_page(driver, base_config_path)
def get_random_rescources(self, old_num): if old_num > 10: old_num = 10 from tools.utility import Utility old_num = Utility.get_random_num(1, old_num) self.driver.find_element_by_xpath( f'//*[@id="transmit-table"]/tbody/tr[{old_num}]/td[1]/input' ).click()
class MarketingTest(unittest.TestCase): # 获取测试数据 contents = Utility.get_json('../conf/yun/testinfo.conf') add_marketing_info = Utility.tran_tuple(contents[0]) @classmethod def setUpClass(cls): warnings.simplefilter('ignore', ResourceWarning) def setUp(self): self.driver = Service.get_driver('../conf/yun/base.conf') self.driver.implicitly_wait(15) from lib.marketing import Marketing self.mar = Marketing(self.driver) self.old_total = self.mar.total(self.driver) # 测试增加 @parameterized.expand(add_marketing_info) def test_add(self, region_id, department_id, tel, name, sex, last_status, wechat, qq, school, education, major, workage, age, source, eduexp, experience, last_tracking_remark, expect): add_info = {"cus.region_id": region_id, "cus.department_id": department_id, "cus.tel": tel, "cus.name": name, "cus.sex": sex, "cus.last_status": last_status, "cus.wechat": wechat, "cus.qq": qq, "cus.school": school, "cus.education": education, "cus.major": major, "cus.workage": workage, "cus.age": age, "cus.source": source, "cus.eduexp": eduexp, "cus.experience": experience, "cus.last_tracking_remark": last_tracking_remark, } self.mar.do_add(self.driver, add_info) # self.driver.refresh() # 执行数据后,点击搜索 new_total = self.mar.total(self.driver) if new_total != self.old_total: actual = 'success' else: actual = 'fail' self.assertEqual(actual, expect) def tearDown(self): self.driver.close() @classmethod def tearDownClass(cls): pass
class TechnicalInterviewTest(unittest.TestCase): # 获取测试数据 contents = Utility.get_json('../conf/huang/testinfo.conf') # 获取技术面试的测试数据 add_interview_info = Utility.tran_tuple(contents[4]) @classmethod def setUpClass(cls): warnings.simplefilter('ignore', ResourceWarning) def setUp(self): self.driver = Service.get_driver('../conf/huang/base.conf') self.driver.implicitly_wait(10) self.driver.maximize_window() Service.ignor_login_decrypt(self.driver, '../conf/huang/base.conf') self.ti = TechnicalInterview(self.driver) def tearDown(self): self.driver.quit() @classmethod def tearDownClass(cls): pass # 测试面试 @parameterized.expand(add_interview_info) def test_add_interview(self, outcome, evaluate, expect): add_interview_info = {"outcome": outcome, "evaluate": evaluate} self.ti.do_interview(add_interview_info) # 获取面试的随机值 # studentnum = self.ti.click_interview() outcome_list = Service.get_page_ele( self.driver, '//*[@id="stuInfo_table"]/tbody/tr[1]/td[8]') # print(studentnum) # print(outcome_list) if outcome in outcome_list: actual = 'add-success' else: actual = 'add-fail' self.assertEqual(actual, expect)
class LoginTest(unittest.TestCase): content = Utility.get_json('../conf/yang/testinfo.conf') login_info = Utility.tran_tuple(content[0]) @classmethod def setUpClass(cls): warnings.simplefilter('ignore', ResourceWarning) def setUp(self): self.driver = Service.get_driver('../conf/yang/base.conf') self.driver.implicitly_wait(15) self.driver.maximize_window() from lib.login import Login self.login = Login(self.driver) def tearDown(self): self.driver.close() @classmethod def tearDownClass(cls): pass #测试登录 @parameterized.expand(login_info) def test_login(self, uname, psword, code, expect): self.login.do_login(uname, psword, code, '../conf/yang/base.conf') # time.sleep(25) from selenium.webdriver.common.by import By #如果存在注销链接 time.sleep(3) if Service.is_element_present(self.driver, By.PARTIAL_LINK_TEXT, "修改密码"): actual = "login-success" #退出系统 self.login.click_logout() else: actual = "login-fail" time.sleep(1) # Utility.get_error_png(self.driver) self.assertEqual(actual, expect)
def do_edit_recource(self,old_num,edit_recource_info): if old_num >10: old_num=10 num=Utility.get_random_num(1,old_num) self.driver.find_element_by_xpath(f'//*[@id="personal-table"]/tbody/tr[{num}]/td[15]/button[2]').click() self.edit_name(edit_recource_info['edit_name']) self.edit_status(edit_recource_info['edit_status']) self.edit_tel(edit_recource_info['edit_tel']) self.edit_source(edit_recource_info['edit_source']) self.click_edit_button()
def click_track_resource_button(self,old_num): old_num=int(old_num) if old_num > 10: old_num=10 num_random=Utility.get_random_num(1,old_num) self.driver.find_element_by_xpath(f'//*[@id="personal-table"]/tbody/tr[{num_random}]/td[15]/button[1]').click() #获取跟踪资源的电话号码 time.sleep(3) return self.driver.find_element_by_xpath('//*[@id="resumeDivId"]/div[2]/blockquote/p[1]/span').text
def load_config(self, config_name): """ :param config_name: object :return: """ self.config = Utility.get_conf(config_name) self.train_data_path = self.config.get('train_data_path') self.test_data_path = self.config.get('test_data_path') self.model_out_path = self.config.get('model_out_path') self.re_model_path = self.config.get('re_model_path') self.train_args = self.config.get('train_args') print('train_args:==>\n', self.train_args)
def discard_resource(self,old_num): #1-10的随机数 old_num=int(old_num) if old_num > 10: old_num=10 num_random=Utility.get_random_num(1,old_num) #勾选资源 self.driver.find_element_by_xpath(f'//*[@id="personal-table"]/tbody/tr[{num_random}]/td[1]/input').click() #点击废弃 self.driver.find_element_by_xpath('//*[@id="abandon"]').click() #点击确认 self.driver.find_element_by_xpath('/html/body/div[13]/div/div/div[3]/button[2]').click() self.driver.refresh()
def load_config(self, config_name): """ :param config_name: object :return: """ self.config = Utility.get_conf(config_name) self.re_model_path = self.config.get('re_model_path') self.test_batch_size = self.config.get('test_batch_size') self.send_syslog = self.config.get('send_syslog') self.save_db = self.config.get('save_db') self.save_file = self.config.get('save_file') self.process_inter = self.config.get('process_inter') self.db_fields = self.config.get('db_fields') self.test_path = self.config.get('test_path', None)
def do_week_mark(self, logging__info): Service.open_module(self.driver, "周考成绩") self.click_query_button() time.sleep(2) student_total = self.get_student_total() if int(student_total) >= 10: student_total = 10 num = Utility.get_random_num(1, student_total) self.driver.find_element_by_xpath( f'//*[@id="pe-result"]/tbody/tr[{num}]/td[9]/button').click() self.select_class_stu(logging__info["s_sclass"]) self.select_stage(logging__info["stage"]) self.select_week(logging__info["week"]) self.input_score(logging__info["score"]) self.click_keep_button()
def create_timestamp_folder(self, child='checkpoints'): """ 创建时间戳的文件夹,存放输出模型 :param child: :return: """ timestamp = Utility.timestamp2str_file() self.model_out_path = os.path.join(self.model_out_path, timestamp) if child is not None: self.checkpoint_path = os.path.join(self.model_out_path, child) else: self.checkpoint_path = self.model_out_path if not os.path.exists(self.checkpoint_path): os.makedirs(self.checkpoint_path) self.checkpoint_prefix = os.path.join(self.checkpoint_path, 'model')
def do_edit_student(self, edit_student_info): Service.open_module(self.driver, "学员信息") self.click_query_button() time.sleep(2) student_total = self.get_student_total() if int(student_total) >= 10: student_total = 10 num = Utility.get_random_num(1, student_total) self.driver.find_element_by_xpath( f'/html/body/div[8]/div[2]/div/div/div/div[2]/div[2]/div[2]/table/tbody/tr[{num}]/td[12]/button[2]' ).click() self.edit_name(edit_student_info['edit_name']) self.edit_state_stu(edit_student_info['edit_state']) self.edit_tel(edit_student_info['edit_tel']) self.edit_source(edit_student_info['edit_source']) self.click_edit_button() self.click_cofirm()
class StudentTest(unittest.TestCase): # 获取测试数据 contents = Utility.get_json('../conf/peng/testinfo.conf') print(contents[0]) query_student_info = Utility.tran_tuple(contents[0]) print(query_student_info) edit_student_info = Utility.tran_tuple(contents[1]) @classmethod def setUpClass(cls): pass def setUp(self): self.driver = Service.get_driver("../conf/peng/base.conf") self.driver.implicitly_wait(10) self.student = Student(self.driver) def tearDown(self): self.driver.close() @classmethod def tearDownClass(cls): pass @parameterized.expand(query_student_info) # @unittest.skip("忽略查询学员") def test_query_student(self, area, sname, state, direction, sclass, expect): query_student_data = { "s_area": area, "s_name": sname, "s_state": state, "s_direction": direction, "s_sclass": sclass } self.student.query_student(query_student_data) time.sleep(2) num = self.student.get_student_total() if int(num) > 0: actual = "query-success" else: actual = "query-fail" self.assertEqual(actual, expect) @parameterized.expand(edit_student_info) def test_edit_student(self, edit_name, edit_state, edit_tel, edit_source, expect): edit_student_data = { "edit_name": edit_name, "edit_state": edit_state, "edit_tel": edit_tel, "edit_source": edit_source } self.student.do_edit_student(edit_student_data) # 进行搜索 self.driver.refresh() time.sleep(2) self.student.input_name(edit_name) self.student.click_query_button() list = [] contents = self.driver.find_elements_by_xpath( "/html/body/div[8]/div[2]/div/div/div/div[2]/div[2]/div[2]/table/tbody/tr/td[6]" ) for content in contents: list.append(content.text) if edit_state in list: actual = "edit-success" else: actual = "edit-fail" self.assertEqual(actual, expect)
#!/usr/bin/env python
class WeekMarkTest(unittest.TestCase): # 获取测试数据 contents = Utility.get_json('../conf/peng/testinfo.conf') print(contents[0]) query_week_info = Utility.tran_tuple(contents[2]) print(query_week_info) import_week_info = Utility.tran_tuple(contents[3]) import_week_info_plus = Utility.tran_tuple(contents[4]) @classmethod def setUpClass(cls): pass def setUp(self): self.driver = Service.get_driver("../conf/peng/base.conf") self.driver.implicitly_wait(10) self.week = WeekMark(self.driver) def tearDown(self): self.driver.close() @classmethod def tearDownClass(cls): pass @parameterized.expand(query_week_info) # @unittest.skip("忽略查询") def test_query_week(self, s_name, s_area, s_sclass, expect): query_week_data = { "s_name": s_name, "s_area": s_area, "s_sclass": s_sclass } self.week.query_mark(query_week_data) time.sleep(2) num = self.week.get_student_total() if int(num) > 0: actual = "query-success" else: actual = "query-fail" self.assertEqual(actual, expect) @parameterized.expand(import_week_info) # @unittest.skip("忽略录用") def test_import_week(self, s_sclass, stage, week, score, expect): import_week_data = { "s_sclass": s_sclass, "stage": stage, "week": week, "score": score } self.week.do_week_mark(import_week_data) if Service.is_element_present(self.driver, By.XPATH, "/html/body/div[11]/div/div/div[1]/h4"): actual = "import-fail" else: actual = "import-success" self.assertEqual(actual, expect) @parameterized.expand(import_week_info_plus) # @unittest.skip("") def test_import_week_two(self, s_sclass, stage, week, file, expect): import_week_data_plus = { "s_sclass": s_sclass, "stage": stage, "week": week, "file": file } self.week.do_import(import_week_data_plus) time.sleep(2) if Service.is_element_present( self.driver, By.CSS_SELECTOR, ".bootbox > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > h4:nth-child(2)" ): actual = "import-fail" else: actual = "import-success" self.assertEqual(actual, expect)
class serviceTest(unittest.TestCase): # 获取测试数据 contents = Utility.get_json('../conf/yun/testinfo.conf') #班级管理查询 management_query_info = Utility.tran_tuple(contents[1]) # 班级管理新增 management_add_info = Utility.tran_tuple(contents[2]) #学员考勤 confirm = Utility.tran_tuple(contents[3]) #学员请假查询 leave_query = Utility.tran_tuple(contents[4]) #学员请假修改 change_leave = Utility.tran_tuple(contents[5]) #学员请假新增 add_leave = Utility.tran_tuple(contents[6]) #学员转班 change_class = Utility.tran_tuple(contents[7]) @classmethod def setUpClass(cls): warnings.simplefilter('ignore', ResourceWarning) def setUp(self): self.driver = Service.get_driver('../conf/yun/base.conf') self.driver.implicitly_wait(15) self.cla = Class_service(self.driver) # 测试班级管理查询 @parameterized.expand(management_query_info) #@unittest.skip("忽略增加") def test_query_data(self, regionId, status, expect): query_data_info = {"regionId": regionId, "status": status} self.cla.do_query(query_data_info) total = Service.get_num( self.driver, '//*[@id="cmDiv"]/div[2]/div[2]/div[4]/div[1]/span[1]') if total != 0: actual = 'success' else: actual = 'fail' self.assertEqual(actual, expect) # 测试班级管理查询 @parameterized.expand(management_add_info) #@unittest.skip("忽略增加") def test_add_data(self, class_no, orientation, opening_time, class_headmaster_id, expect): add_data_info = { "c.class_no": class_no, "c.orientation": orientation, "c.opening_time": opening_time, "c.class_headmaster_id": class_headmaster_id } old_total = self.cla.do_add(add_data_info) import time time.sleep(2) new_total = Service.get_num( self.driver, '//*[@id="cmDiv"]/div[2]/div[2]/div[4]/div[1]/span[1]') if new_total != old_total: actual = 'success' else: actual = 'fail' self.assertEqual(actual, expect) #测试考勤 @parameterized.expand(confirm) #@unittest.skip("忽略增加") def test_confirm_data(self, attendance, expect): confirm_data_info = {"attendance": attendance} old_total = self.cla.do_confirm(confirm_data_info) import time time.sleep(2) new_total = Service.get_kaoqin( self.driver, '/html/body/div[8]/div[2]/div/div/div/div[3]/div/div/div/div[1]/div[2]/div/div[1]/div[2]/div[2]/table/tbody/tr[1]/td[7]' ) if new_total != old_total: actual = 'success' else: actual = 'fail' self.assertEqual(actual, expect) #学员请假查询 @parameterized.expand(leave_query) #@unittest.skip("忽略增加") def test_confirm_data(self, region_id, leave_status, expect): confirm_data_info = { "region_id": region_id, "leave_status": leave_status } old_total = self.cla.do_leave_query(confirm_data_info) import time time.sleep(2) new_total = Service.get_num( self.driver, '//*[@id="content"]/div[2]/div/div/div/div[2]/div[2]/div[4]/div[1]/span[1]' ) if new_total != old_total: actual = 'success' else: actual = 'fail' self.assertEqual(actual, expect) # 学员请假修改动作 @parameterized.expand(change_leave) #@unittest.skip("忽略增加") def test_change_leave_data(self, stuName, reason, expect): change_leave_data_info = {"sl.stuName": stuName, "sl.reason": reason} old_text = self.cla.change_leave(change_leave_data_info) import time time.sleep(2) new_text = self.driver.find_element_by_xpath( '/html/body/div[8]/div[2]/div/div/div/div[2]/div[2]/div[2]/table/tbody/tr/td[4]/span' ).text if new_text != old_text: actual = 'success' else: actual = 'fail' self.assertEqual(actual, expect) # 学员请假新增动作 @parameterized.expand(add_leave) #@unittest.skip("忽略增加") def test_add_leave_data(self, start_time, end_time, leave_type, days, stuName, leave_count, reason, comment, expect): add_leave_data_info = { "sl.start_time": start_time, "sl.end_time": end_time, "sl.leave_type": leave_type, "sl.days": days, "sl.stuName": stuName, "sl.leave_count": leave_count, "sl.reason": reason, "sl.comment": comment } old_tatol = self.cla.change_leave(add_leave_data_info) import time time.sleep(2) new_tatol = Service.get_num( self.driver, '//*[@id="content"]/div[2]/div/div/div/div[2]/div[2]/div[4]/div[1]/span[1]' ) if new_tatol != old_tatol: actual = 'success' else: actual = 'fail' self.assertEqual(actual, expect) # 学员转班 @parameterized.expand(change_class) #@unittest.skip("忽略增加") def test_change_class_data(self, regionId, stuClass, expect): change_class_info = {"regionId": regionId, "stuClass": stuClass} old_text = self.cla.do_change_class(change_class_info) import time time.sleep(2) new_text = self.driver.find_element_by_xpath( '/html/body/div[8]/div[2]/div/div/div/div[2]/div[2]/div[2]/table/tbody/tr[1]/td[4]' ).text if new_text != old_text: actual = 'success' else: actual = 'fail' self.assertEqual(actual, expect) def tearDown(self): self.driver.close() @classmethod def tearDownClass(cls): pass
import unittest from parameterized import parameterized from lib.interview import InterViewApi from tools.utility import Utility test_data_conf_path = '../conf/testdata.json' base_conf = '../conf/base_jiang.json' test_data = Utility.get_json(test_data_conf_path) Inter_test_data = Utility.get_excel_dict_tup_list(test_data["interview_api"]) print(Inter_test_data) class InterViewTest(unittest.TestCase): def setUp(self) -> None: self.Inter = InterViewApi(base_conf) def tearDown(self) -> None: pass @parameterized.expand(Inter_test_data) def test_inter(self, inter_data): inter_resp = self.Inter.do_interview(inter_data) inter_resp_code = inter_resp.status_code inter_resp_content = inter_resp.text print(inter_resp_code) actual = inter_resp_content expect = inter_data['expect'] # print(actual) # print(expect)
class ApplicationForExtraWorkTest(unittest.TestCase): # 获取测试数据 contents = Utility.get_json('../conf/huang/testinfo.conf') # 获取加班申请的测试数据 add_overtime_info = Utility.tran_tuple(contents[7]) print(add_overtime_info) @classmethod def setUpClass(cls): warnings.simplefilter('ignore', ResourceWarning) def setUp(self): self.driver = Service.get_driver('../conf/huang/base.conf') self.driver.implicitly_wait(10) self.driver.maximize_window() Service.ignor_login_decrypt(self.driver, '../conf/huang/base.conf') self.afew = ApplicationForExtraWork(self.driver) def tearDown(self): # pass self.driver.quit() @classmethod def tearDownClass(cls): pass #测试值班申请 @parameterized.expand(add_overtime_info) def test_add_overtime(self, start_time, end_time, accounting, hours, region, reason, expect): add_overtime_info = { "start_time": start_time, "end_time": end_time, "accounting": accounting, "hours": hours, "region": region, "reason": reason } overtime_info = { "start_js": "document.querySelector(\"#addApply-form > div > div > div:nth-child(2) > div:nth-child(1) > input\")", "end_js": "document.querySelector(\"#addApply-form > div > div > div:nth-child(2) > div:nth-child(2) > input\")", "start_time": "2020-05-10 09:30", "end_time": "2020-05-10 11:30", "accounting": "结算工资", "hours": "2小时", "region": "成都", "reason": "没钱要赚更多的钱买买买" } # print(add_overtime_info) self.afew.do_overtime(add_overtime_info) reason_list = Service.get_page_ele( self.driver, '//*[@id="apply-table"]/tbody/tr[1]/td[7]/span') if reason in reason_list: actual = 'add-success' else: actual = 'add-fail' self.assertEqual(actual, expect)
def __init__(self): self.indian_surnames = pandas.read_csv(Utility.ROOT + Utility.INDIAN_SURNAME_FILE_PATH) self.utility = Utility() self.states = self.utility.__extract_abbreviations__(self.utility)
class PublicRescourcesTest(unittest.TestCase): #获取查询公共池的数据 contents = Utility.get_json('../conf/yang/public_rescources_testinfo.conf') query_public_info = Utility.tran_tuple(contents[0]) #获取废弃的数据 claim_public_info = Utility.tran_tuple(contents[1]) # print(claim_public_info) @classmethod def setUpClass(cls): warnings.simplefilter('ignore', ResourceWarning) def setUp(self): self.driver = Service.get_driver('../conf/yang/base.conf') self.driver.implicitly_wait(15) self.driver.maximize_window() Service.ignor_login_decrypt(self.driver, '../conf/yang/base.conf') from lib.public_rescources import PublicRescources self.pu = PublicRescources(self.driver) def tearDown(self): self.driver.close() @classmethod def tearDownClass(cls): pass #测试搜索 @parameterized.expand(query_public_info) # @unittest.skip("忽略搜索") def test_do_query_public(self,area_value,dpt_value,abandoned_value,status_value,source_value ,\ education_value,name_value,expect): query_public_info = { "area_value": area_value, 'dpt_value': dpt_value, 'abandoned_value': abandoned_value, 'status_value': status_value, 'source_value': source_value, 'education_value': education_value, 'name_value': name_value } driver = self.driver self.pu.do_query_public(query_public_info) time.sleep(4) #获取页面元素 num = Service.get_num( driver, '//*[@id="content"]/div[3]/div/div[1]/div[2]/div[4]/div[1]/span[1]' ) print(num) if int(num) > 0: actual = 'query-success' else: actual = 'query-fail' self.assertEqual(actual, expect) #测试认领 @parameterized.expand(claim_public_info) def test_do_claim_rescources(self, temp, expect): #获取此生页面显示数量 time.sleep(2) old_num = Service.get_num( self.driver, '//*[@id="content"]/div[3]/div/div[1]/div[2]/div[4]/div[1]/span[1]' ) self.pu.do_claim_rescources(int(old_num)) #点击默认搜索 self.driver.refresh() self.pu.click_public_query() time.sleep(2) new_num = Service.get_num( self.driver, '//*[@id="content"]/div[3]/div/div[1]/div[2]/div[4]/div[1]/span[1]' ) if int(old_num) - int(new_num) == 1: actual = 'claim-success' else: actual = 'claim-fail' self.assertEqual(actual, expect)
'MD': { 'GHOSH': int(0) } }, 'trump': { 'MD': { 'GHOSH': int(0) } } } # initial_results = tool.run(tool, 'MD', 'PATEL') # # Utility.__get_pretty_printer__().pprint(initial_results) # final_results = tool.parse_results(initial_results, 'PATEL') # # Utility.__get_pretty_printer__().pprint(final_results) for last_name in tool.indian_surnames: Utility.__get_pretty_printer__().pprint("Last name: " + last_name) initial_results = tool.run(tool, 'getAllStates', last_name) # Utility.__get_pretty_printer__().pprint(initial_results) final_results = tool.parse_results(initial_results, last_name, recipient) Utility.__get_pretty_printer__().pprint(final_results) f = open("finalResults.txt", "a+") f.write(str(final_results)) f.close() f = open("finalRecipient.txt", "a+") f.write(str(recipient)) f.close()