def setUp(self): print("每条case执行之前") self.file_path = "/Users/qing.li/PycharmProjects/hm/selenium_/imooc/image/imooc_code_%s.png" % (time.time()) self.driver = webdriver.Chrome() self.driver.get("http://www.5itest.cn/register") self.driver.maximize_window() self.register = RegisterBusiness(self.driver) # self.register_function = RegisterFunction(self.driver, self.file_path) self.register_code = GetCode(self.driver, self.file_path)
class RegisterHandle(object): def __init__(self, driver): self.registerp = RegisterPage(driver) self.registerg = GetCode(driver) #在邮箱输入框内输入邮箱 def send_email(self, email): self.registerp.find_email_element().send_keys(email) #在用户名输入框内输入用户名 def send_username(self, username): self.registerp.find_username_element().send_keys(username) #在密码输入框内输入密码 def send_password(self, password): self.registerp.find_password_element().send_keys(password) #在验证码输入框内输入验证码 def send_code(self, file_name): text = self.registerg.code_online(file_name) self.registerp.find_code_text_element().send_keys(text) #获取报错的文字信息 def get_user_text(self, info): #添加容错处理 try: if info == 'email_error': test = self.registerp.find_email_error_element().text elif info == 'name_error': test = self.registerp.find_username_error_element().text elif info == 'password_error': test = self.registerp.find_password_error_element().text elif info == 'code_error': test = self.registerp.find_code_error_element().text except: test = None return test #点击注册按钮 def click_register_button(self): self.registerp.find_register_btn_element().click() #获取注册按钮的文字 def get_register_text(self): return self.registerp.find_register_btn_element().text
class Register(): def __init__(self, driver): self.base = Base(driver) self.read_config = ReadConfig( r'F:\xw\example\web_projrct\Config\el.ini', 'Register') self.getcode = GetCode(driver) #注册 def register(self, email, user, password): register_email = self.read_config.get_value('register_email') register_name = self.read_config.get_value('register_name') register_password = self.read_config.get_value('register_password') register_input_code = self.read_config.get_value('register_input_code') register_get_code = self.read_config.get_value('register_get_code') register_btn = self.read_config.get_value('register_btn') self.base.element_input(register_email, email) self.base.element_input(register_name, user) self.base.element_input(register_password, password) code = self.getcode.get_code(register_get_code) self.base.element_input(register_input_code, code) self.base.element_click(register_btn)
def send_user_code(self, file_name): #self.register_p.get_code_element().send_keys(file_name) get_code_text = GetCode(self.driver) code = get_code_text.code_online(file_name) self.register_p.get_code_element().send_keys(code)
def __init__(self, driver): self.base = Base(driver) self.read_config = ReadConfig( r'F:\xw\example\web_projrct\Config\el.ini', 'Register') self.getcode = GetCode(driver)
def get_code_num(self, key, filename): element = self.get_element(key) get_c = GetCode(self.driver) get_c.get_code_image(element, filename) text = get_c.get_code_num(filename) return text
def send_user_code(self, code_text): get_code_image = GetCode(self.driver) code_image = get_code_image.get_code_image() self.register_p.get_code_text_element().send_keys(code_text)
def __init__(self, driver): self.driver = driver self.get_code_text = GetCode(self.driver) self.register_p = RegisterPage(self.driver)
def get_code_text(self): get_code = GetCode(self.driver) time.sleep(5) file_name = "F:\\myfile\\python\\code\\seleniumpython\\Image\\test001.png" code = get_code.code_online(file_name) print(code)
def __init__(self, driver): self.registerp = RegisterPage(driver) self.registerg = GetCode(driver)
def send_user_code(self, file_name): get_code_text = GetCode(self.driver) self.loger.info("huoqu yanzhengma qian :") code = get_code_text.code_online(file_name) self.register_p.get_code_element().send_keys(code) self.loger.info("huoqu yanz ma hou ")
def send_user_code(self, file_path): get_code_text = GetCode(self.driver, file_path) code = get_code_text.get_code_picture() self.register_p.get_code_element().send_keys(code)
def send_user_code(self,file_name): get_code_text = GetCode(self.fd) code = get_code_text.code_online(file_name) self.send_value("code_image", code, "注册页面_输入验证码")
def __init__(self, driver): self.driver = driver self.register_page = RegisterPage(self.driver) self.get_c = GetCode(self.driver)
class RegisterHandle: def __init__(self, driver): self.driver = driver self.register_page = RegisterPage(self.driver) self.get_c = GetCode(self.driver) def send_user_email(self, email): try: self.register_page.get_user_email_element().clear() self.register_page.get_user_email_element().send_keys(email) except: print("邮箱输入失败") def send_user_name(self, username): try: self.register_page.get_user_name_element().clear() self.register_page.get_user_name_element().send_keys(username) except: print("用户名输入失败") def send_user_passwd(self, password): try: self.register_page.get_user_password_element().clear() self.register_page.get_user_password_element().send_keys(password) except: print("密码输入失败") def send_user_code(self, code): try: self.register_page.get_user_code_text_element().clear() self.register_page.get_user_code_text_element().send_keys(code) except: print("验证码输入失败") def click_register_button(self): try: self.register_page.get_register_button_element().click() except: print("注册按钮点击失败") def get_user_text(self, info): try: if info == "email_error": return self.register_page.get_email_error_element().text elif info == "username_error": return self.register_page.get_username_error_element().text elif info == "password_error": return self.register_page.get_password_error_element().text else: return self.register_page.get_code_error_element().text except: return None def get_code_num(self, filename="../pic/code.png"): self.get_c.get_code_image( self.register_page.get_user_code_img_element(), filename) code_num = self.get_c.get_code_num(filename) return code_num def get_random_user(self): return ''.join(random.sample("1234567890abcde", 8))
def send_register_captcha(self, file_name): get_code_text = GetCode(self.driver) captcha = get_code_text.discern_captcha_image(file_name) self.rp.get_captcha_code().send_keys(captcha)
def send_user_code(self, file_name): get_code_text = GetCode(self.driver) code = get_code_text.code_online(file_name) self.find_element.get_element('code_text').send_keys(code)
def send_login_captcha(self, file_name): get_code_text = GetCode(self.driver) #captcha = get_code_text.discern_captcha_image(file_name) self.lp.get_login_captcha_code().send_keys('1212')