def setUpClass(cls): # 打开首页 cls.driver = Service.open_page() Login().do_login(cls.driver, data) sleep(2) cls.driver.find_element_by_partial_link_text("学员管理").click() sleep(2) cls.driver.find_element_by_partial_link_text("阶段考评").click() sleep(2) cls.tw = Month_test()
def test_stage_grade_query(self, area, cclass, name, expect): stage_query_data = (area, cclass, name) self.tw.stage_grade_query(self.driver, stage_query_data) #判断录入按钮,有则查询成功,没则失败 if Service.is_element_present( self.driver, By.CSS_SELECTOR, '#pe-result > tbody:nth-child(2) > tr:nth-child(3) > td:nth-child(9) > button:nth-child(1)' ): actual = "test_stage_grade_query_success" else: actual = "test_stage_grade_query_fail" #断言 self.assertEqual(expect, actual)
def test_login(self, uname, upass, vfcode, expect): # 将参数重新组织成字典 login_data = { 'username': uname, 'password': upass, 'verification': vfcode } self.login.do_login('..\\config\\base.conf', login_data) from selenium.webdriver.common.by import By if Service.is_element_present(self.driver, By.LINK_TEXT, '注销'): actual = 'success' self.driver.find_element_by_link_text('注销').click() else: actual = 'fail' self.driver.refresh() self.assertEqual(actual, expect)
def upload_stage(self, driver, value): stage1 = driver.find_element_by_xpath('//*[@id="import_ph"]') Service.select_value(stage1, value)
def input_name(self, driver, value): name = driver.find_element_by_xpath( '/html/body/div[8]/div[2]/div/div/div/div[1]/input') Service.input_ele(name, value)
def select_area(self, driver, value): area = driver.find_element_by_css_selector( 'select.sel-text:nth-child(1)') Service.select_value(area, value)
def select_stage(self, driver, value): stage2 = driver.find_element_by_xpath('//*[@id="ph_phase"]') Service.select_value(stage2, value)
def do_login(self, base_config_path, login_data): Service.open_page(self.driver, base_config_path) self.input_uname(login_data['username']) self.input_upass(login_data['password']) self.input_code(login_data['verification']) self.click_button()
def edit_grade(self, driver, value): edit_grade = driver.find_element_by_xpath( "/html/body/div[8]/div[2]/div/div/div/div[2]/div[2]/div[2]/table/tbody/tr[4]/td/div[1]/div[2]/div[2]/table/tbody/tr/td[3]" ) Service.send_input(edit_grade, value)
def record_entry_grade(self, driver, value): record_entry_grade = driver.find_element_by_xpath( "/html/body/div[9]/div/div/div[2]/form/div[2]/div[4]/input") Service.send_input(record_entry_grade, value)
def record_entry_weeks(self, driver, value): record_entry_weeks = driver.find_element_by_id("we_week") Service.select_value(record_entry_weeks, value)
def record_entry_stage(self, driver, value): record_entry_stage = driver.find_element_by_id("we_phase") Service.select_value(record_entry_stage, value)
def record_entry_class(self, driver, value): record_entry_class = driver.find_element_by_id("we_cl") Service.select_value(record_entry_class, value)
def click_psd(self, driver, passwd): self.driver.find_element_by_id('btn-decrypt').click() sepass = self.driver.find_element_by_name('secondPass') Service.send_input(sepass, passwd) time.sleep(5) self.driver.find_elements_by_class_name('btn.btn-info')[0].click()
def input_upass(self, password): upass = self.driver.find_element_by_xpath( '/html/body/div[1]/div/div/form/div/div[2]/input') Service.send_input(upass, password)
def input_code(self, verification): ucode = self.driver.find_element_by_xpath( '/html/body/div[1]/div/div/form/div/div[3]/input') Service.send_input(ucode, verification)
def select_class(self, driver, value): # 选择班级名 cname_ele = "/html/body/div[8]/div[2]/div/div/div/div[1]/select[2]" cname = driver.find_element_by_xpath(cname_ele) Service.select_value(cname, value)
def input_uname(self, username): uname = self.driver.find_element_by_xpath( '/html/body/div[1]/div/div/form/div/div[1]/input') Service.send_input(uname, username)
def input_name(self, driver, value): name_ele = "/html/body/div[8]/div[2]/div/div/div/div[1]/input" name = driver.find_element_by_xpath(name_ele) Service.send_input(name, value)
def btn_upload_class(self, driver, value): upload_class_ele = "import_cl" upload_class = driver.find_element_by_id(upload_class_ele) Service.select_value(upload_class, value)
def btn_upload_stage(self, driver, value): upload_stage_ele = "import_ph" upload_stage = driver.find_element_by_id(upload_stage_ele) Service.select_value(upload_stage, value)
def edit_grade(self, driver, value): edit_grade = driver.find_element_by_css_selector( '#phaseExam-form > div:nth-child(3) > div:nth-child(1) > input:nth-child(2)' ) Service.input_ele(edit_grade, value)
def btn_upload_week(self, driver, value): upload_week_ele = "import_we" upload_week = driver.find_element_by_id(upload_week_ele) Service.select_value(upload_week, value)
def select_class(self, driver, value): cclass = driver.find_element_by_xpath( '/html/body/div[8]/div[2]/div/div/div/div[1]/select[2]') Service.select_value(cclass, value)
def select_area(self, driver, value): area_ele = "/html/body/div[8]/div[2]/div/div/div/div[1]/select[1]" area = driver.find_element_by_xpath(area_ele) Service.select_value(area, value)
def upload_class(self, driver, value): class1 = driver.find_element_by_xpath('//*[@id="import_cl"]') Service.select_value(class1, value)
def btn_record_entry_input(self, driver): Service.get_random_btn(driver)
def select_class2(self, driver, value): class2 = driver.find_element_by_id('ph_cl') Service.select_value(class2, value)
def setUpClass(cls): cls.driver = Service.get_driver('..\\config\\base.conf') cls.login = Login(cls.driver)