class TestLoginCase(): def setup_class(self): self.log = UserLog() self.logger = self.log.get_log() #初始化driver self.driver = BrowserEngine().init_driver() self.driver.get('http://58.246.240.154:7878/zl/179333') self.driver.maximize_window() self.login = LoginPage(self.driver) def teardown_class(self): self.log.close_handle() time.sleep(2) self.driver.close() def setup(self): self.logger.info("this is chrome") def teardown(self): self.driver.refresh() #用户名不存在 def test_login_name_error(self): name_error = self.login.login_name_error("s", "123") assert name_error == True #用户名为空 def test_login_name_none_error(self): name_none_error = self.login.login_name_none("1") assert name_none_error == True #密码错误 def test_login_password_error(self): password_error = self.login.login_password_error("ss", "1") assert password_error == True #密码为空 def test_login_password_none_error(self): password_none_error = self.login.login_password_none("ss") assert password_none_error == True #通过 def test_login_success(self): success = self.login.login_success("ss", "123") assert success == True
settings.PIC_RATIO * right, settings.PIC_RATIO * bottom)) img.save(settings.CODE_LOC) def distinguish_with_pytesseract(self): im = Image.open(settings.CODE_LOC) text = pytesseract.image_to_string(im) return text def distinguish(self): r = ShowapiRequest("http://route.showapi.com/184-4", "94789", "6de63c760b684ad1a928d0158cfaef95") r.addBodyPara("typeId", "34") r.addBodyPara("convert_to_jpg", "0") r.addBodyPara("needMorePrecise", "0") r.addFilePara("image", settings.CODE_LOC) #文件上传时设置 res = r.post() return res.json()["showapi_res_body"]["Result"] if __name__ == "__main__": driver = BrowserEngine("chrome").start_browser() log = LogRecord() logger = log.log_record() h = HandleCaptcha(driver, logger) driver.get("http://jgtest.qida.yunxuetang.com.cn/login.htm") get_ele = GetElement(driver, logger) get_ele.get_element("sms_login_type", "login_element").click() code = get_ele.get_element("code_img", "login_element") h.handle_captcha(code) #print(h.distinguish())