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 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)
def total(self,driver): Service.open_menu(self.driver, '资源管理') Service.open_menu(self.driver, '培训资源') self.driver.find_element_by_css_selector("button.btn:nth-child(7)").click() # 获取数量 content = self.driver.find_element_by_xpath('//*[@id="content"]/div[3]/div/div[1]/div[2]/div[4]/div[1]/span[1]').text return re.findall(r"总共 (.*?)条记录", content)[0]
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 do_login(self, uname, psword, code, path): Service.open_startpage(self.driver, path) self.input_uasername(uname) self.input_password(psword) self.input_vcode(code) self.click_remember() self.click_login()
def query_score(self, query_info): Service.open_module(self.driver, "综合成绩") self.input_name(query_info["s_name"]) self.select_area(query_info["s_area"]) self.select_direction(query_info["s_direction"]) self.select_class(query_info["s_sclass"]) self.select_stage(query_info["s_stage"]) self.click_query_button()
def do_import(self, logging__week_info): Service.open_module(self.driver, "周考成绩") self.week_week_import() self.select_class_stu_week(logging__week_info["s_sclass"]) self.select_stage_week(logging__week_info["stage"]) self.select_week_stu(logging__week_info["week"]) self.upload_fail(logging__week_info["file"]) self.click_commit()
def technical_interview(self, base_config_path, technical_interview_data): driver = self.driver Service.miss_login(driver, base_config_path) self.driver.find_element_by_xpath( '/html/body/div[4]/div[2]/a[6]').click() time.sleep(6) self.click_interview() # self.choose_result(technical_interview_data['result']) self.input_question(technical_interview_data['question_content']) self.input_evalute(technical_interview_data['evalute_content']) self.click_save()
def mock_interview(self, base_config_path, mock_interview_data): driver = self.driver Service.miss_login(driver, base_config_path) self.driver.find_element_by_xpath( '/html/body/div[4]/div[2]/a[6]').click() time.sleep(6) self.click_job_manage() self.mock() self.input_salary(mock_interview_data['salary']) self.choose_ability() self.input_remark(mock_interview_data['mremark']) self.click_save_button() driver.switch_to.alert.accept()
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 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 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)
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 setUp(self): driver=Service.get_driver('..\\conf\\base.conf') login_info = {'userName': '******', 'userPass': '******', 'checkcode':'0000'} Login().do_login('..\\conf\\base.conf', driver, login_info) time.sleep(3) driver.find_element_by_css_selector('div.panel:nth-child(12) > div:nth-child(1) > a:nth-child(1)').click() time.sleep(3) driver.find_element_by_css_selector( '#list-8 > div:nth-child(1) > ul:nth-child(1) > li:nth-child(1) > a:nth-child(1)').click() time.sleep(3) number = driver.find_element_by_xpath('/html/body/div[9]/div[2]/div[2]/div[2]/div[4]/div[1]/span[1]') print(number.text) eles = driver.find_elements_by_class_name('page-number') print(eles) num = 0 totalcount = len(eles) print(totalcount + 1) for i in range(0, totalcount + 1): # eles[i].find_elements_by_tag_name('a').click() # print(eles[i]) driver.find_element_by_xpath("//ul[@class='pagination']/li[%d+2]/a[contains(@href,'#')]" % i).click() time.sleep(5) newnum = len(driver.find_elements_by_xpath('//*[@id="employee-table"]/tbody/tr')) num = num + newnum print(num) driver.quit()
def setUp(self): self.driver = Service.get_driver('..\\conf\\base.conf') login_info = { 'userName': '******', 'userPass': '******', 'checkcode': '0000' } Login().do_login('..\\conf\\base.conf', self.driver, login_info)
def test_login(self, one_subject, two_subject,expect): contents = {'one_subject': one_subject, 'two_subject': two_subject} self.finance.finance_query(contents) # 断言 if not Service.is_element_present(self.driver, By.LINK_TEXT, '修改'): actual = 'query-pass' else: actual = 'quey-fail' self.assertEqual(actual, expect)
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()
def do_leave_query(self, leave_query_data): self.leave() old_tolod = Service.get_num( self.driver, '//*[@id="content"]/div[2]/div/div/div/div[2]/div[2]/div[4]/div[1]/span[1]' ) self.quyu(leave_query_data['region_id']) self.status(leave_query_data['leave_status']) self.query()
def do_confirm(self, confirm_data): self.checking_in() old_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]' ) #self.student_name(confirm_data['stuName']) self.sele_attendance(confirm_data['attendance']) self.confirmAttenBtn() return old_total
def test_csv_generation(self): services = [ Service(details({ "Name of service": "test_name", "Abbr": "tn" })), Service(details({ "Name of service": "test_name_2", "Abbr": "tn2" })) ] table = tabular_map([("name_column", lambda s: s.name), ("abbr", lambda s: s.abbr)], services) assert_that( table, is_([["name_column", "abbr"], ["test_name", "tn"], ["test_name_2", "tn2"]]))
def test_login(self,userName,userPass,checkcode,expect): login_info ={'userName':userName,'userPass':userPass,'checkcode':checkcode} Login().do_login('..\\conf\\base.conf',self.driver,login_info) from selenium.webdriver.common.by import By flag= Service.is_element_present(self.driver,By.LINK_TEXT,'[注销]') if flag: actual= 'login_pass' else: actual = 'login_fail' self.assertEqual(actual,expect)
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)
def do_add(self, add_data): self.class_management() old_tolod = Service.get_num( self.driver, '//*[@id="cmDiv"]/div[2]/div[2]/div[4]/div[1]/span[1]') self.button_add() self.input_classname(add_data["c.class_no"]) self.direction(add_data["c.orientation"]) self.selec_time(add_data["c.opening_time"]) self.selec_teacher(add_data['c.class_headmaster_id']) self.confirm_save() return old_tolod
def click_interview(self): # 获取学生总数 num = Service.get_num( self.driver, '//*[@id="skills"]/div[2]/div[2]/div[4]/div[1]/span[1]') print(num) # 随机选择学生 studentnum = random.randint(1, 6) print(studentnum) self.driver.find_element_by_xpath( f'//*[@id="stuInfo_table"]/tbody/tr[{studentnum}]/td[9]/button' ).click() return studentnum
def test_login(self, login_userName, login_userPASS, login_checkcode, login_expect): contents = {'username': login_userName, 'password': login_userPASS, 'checkcode': login_checkcode} self.login.excute_login(contents) # 断言 if Service.is_element_present(self.driver, By.LINK_TEXT, '注销'): actual = 'success' elif self.driver.find_element_by_id('pwMsg').text == '用户名或密码错误': actual = 'error' elif self.driver.find_element_by_id('checkcodeMsg').text == '用户名或密码错误': actual = 'error' else: actual = 'error' self.assertEqual(actual, login_expect)
def test_alter_duty(self,teacher,duty_time,expect): alter_duty_info = {"teacher": teacher,"duty_time": duty_time} # 执行修改 self.tod.do_alter_duty(alter_duty_info) #获取修改的随机数 alternum = self.tod.click_alter() # 获取界面老师名字元素 teachername_list = Service.get_page_ele(self.driver, f'//*[@id="duty_table"]/tbody/tr[{alternum}]/td[2]') if teacher in teachername_list: actual = 'alter-success' else: actual = 'alter-fail' self.assertEqual(actual, expect)
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)
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)
def test_add_duty(self,teacher,duty_time,expect): add_duty_info = {"teacher":teacher,"duty_time":duty_time} self.tod.do_add_duty(add_duty_info) teachername_list = Service.get_page_ele(self.driver,'//*[@id="duty_table"]/tbody/tr[1]/td[2]') print(teacher) print(teachername_list) if teacher in teachername_list: actual = 'add-success' else: actual = 'add-fail' self.assertEqual(actual,expect)
def test_import_week_two(self, s_sclass, stage, file, expect): import_week_data_plus = { "s_sclass": s_sclass, "stage": stage, "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)