def text_click_jietu(browser,text): result = element_exit_by_link_text(browser,text) if result==True: browser.find_element_by_link_text(text).click() sleep(2) jietu(browser,text) else: print("链接未找到。。。。。")
def test_02_different_new_password(self): try: change_password(self.browser,"s1234567","s1111111","s2222222") sleep(2) # 断言 tips_ele = self.browser.find_element_by_xpath('/html/body/div[1]/div/table/tbody/tr[2]/td[2]/div/table/tbody/tr[2]/td/div/table/tbody/tr/td[2]') self.assertIsNotNone(tips_ele) except Exception as e: jietu(self.browser,"修改密码报错") raise e
def test_01_wrong_old_password(self): try: change_password(self.browser,"s123123123","s1111111","s1111111") sleep(2) # 断言 tips = self.browser.find_element_by_xpath('/html/body/div[1]/div/table/tbody/tr[2]/td[2]/div/table/tbody/tr[2]/td/div/table/tbody/tr/td[2]').text self.assertEqual("旧密码输入错误!",tips) except Exception as e: jietu(self.browser,"修改密码报错") raise e
def test_05_login_by_null_username_correct_password(self): try: login_by_different_username_password(self.browser, "", "s1234567") sleep(2) tips_ele = self.browser.find_element_by_xpath( '/html/body/div[1]/div/table/tbody/tr[2]/td[2]/div/table/tbody/tr[2]/td/div/table/tbody/tr/td[2]' ) self.assertIsNotNone(tips_ele) except Exception as e: jietu(self.browser, "登录异常") raise e
def test_03_login_by_wrong_username_correct_password(self): try: login_by_different_username_password(self.browser, "supppp", "s1234567") sleep(2) # 使用错误提示信息的内容进行断言 tips_ele = self.browser.find_element_by_xpath( '/html/body/div[1]/div/table/tbody/tr[2]/td[2]/div/table/tbody/tr[2]/td/div/table/tbody/tr/td[2]' ) tips = tips_ele.text self.assertEqual("登录名或密码错误,请重试!", tips) except Exception as e: jietu(self.browser, "登录异常") raise e
def test_01_login_by_correct_username_password(self): try: login_by_different_username_password(self.browser, "sup", "s1234567") sleep(2) # 使用登录后的用户名进行断言 username_ele = self.browser.find_element_by_xpath( '/html/body/div[1]/table/tbody/tr/td[2]/table/tbody/tr[3]/td[1]/label' ) username = username_ele.text self.assertEqual(username, "苏鹏") except Exception as e: jietu(self.browser, "登录异常") raise e
def login_sup(browser): try: browser.get("http://127.0.0.1:8080/oa") # 设置动态等待,判断所有符合class属性为logininput的元素全部加载完成,然后再执行后续脚本 # 用到的方法:presence_of_all_elements_located WebDriverWait(browser,10).until(ec.presence_of_all_elements_located((By.CLASS_NAME,"loginInput"))) # 输入用户名 browser.find_element_by_xpath('//input[@class="loginInput"]').send_keys("sup") # 输入密码 browser.find_element_by_xpath('//input[@name="password"]').send_keys("s1234567") # 设置动态等待,判断登录按钮的value值是否出现预期的登录两个字 # 用到的方法:text_to_be_present_in_element_value WebDriverWait(browser,10).until(ec.text_to_be_present_in_element_value((By.ID,"button_submit"),"登录")) # 点击登录按钮 browser.find_element_by_xpath('//input[@id="button_submit"]').click() except Exception as e: jietu(browser,"登录报错") raise e
def test_06_login_button_clickable(self): try: self.browser.get("http://172.21.5.51:8080/oa") sleep(2) # 输入用户名 self.browser.find_element_by_xpath( '//input[@class="loginInput"]').clear() self.browser.find_element_by_xpath( '//input[@class="loginInput"]').send_keys("sup") # 输入密码 self.browser.find_element_by_xpath( '//input[@name="password"]').send_keys("s1234567") # 获取登录按钮的状态 button_status = self.browser.find_element_by_xpath( '//input[@id="button_submit"]').is_enabled() self.assertTrue(button_status) except Exception as e: jietu(self.browser, "登录异常") raise e
def change_password(browser,oldpassword,newpassword,passwordagain): try: browser.find_element_by_xpath('//a[@title="密码修改"]').click() sleep(2) # 输入旧密码,需要切入框架,先定位框架 iframe_element = browser.find_element_by_xpath('//iframe[contains(@src,"/oa/common/tools/updatePassword.jsp?uuid=")]') browser.switch_to.frame(iframe_element) browser.find_element_by_xpath('//input[@id="oldpassword"]').send_keys(oldpassword) sleep(2) browser.find_element_by_xpath('//input[@id="newpassword"]').send_keys(newpassword) sleep(2) browser.find_element_by_xpath('//input[@id="passwordagain"]').send_keys(passwordagain) # 点击保存按钮 browser.find_element_by_xpath('//button[@id="button_save"]').click() # 操作完成后切出到默认框架 browser.switch_to.default_content() except Exception as e: jietu(browser,"修改密码报错") raise e