def login(self): logger.info("<--------------- start login --------------->") user_name = self.user_name user_pwd = self.user_pwd self.webdrive.action_cmd("login_baidu", "login_click", "click") self.webdrive.action_cmd("login_baidu", "login_name", "input", user_name) self.webdrive.action_cmd("login_baidu", "login_pwd", "input", user_pwd) self.webdrive.action_cmd("login_baidu", "login_btn", "click") logger.info("<--------------- login success --------------->")
def open_url(self): count = 1 while count <= self.TIMEOUT: try: self.drive.delete_all_cookies() self.drive.get(self.url) self.drive.maximize_window() logger.info('open url %s success !' % self.url) break except Exception as e: logger.error('login fail =>' + e.message) self.drive.close() self.drive.implicitly_wait(10) count += 1
def action_cmd(self, web_name, action_name, method, param=None, find_try_time=None): xpath = GetConfig("web_xpath.cfg").get_item(web_name, action_name) func_name = "action_" + method try: func = getattr(self, func_name) except AttributeError: logger.error('No method named : %s found !' % func_name) msg = "%s %s %s %s" % (action_name, xpath, method, param) logger.info(msg) res = func(xpath, param, find_try_time) return res
def test_login(self, testData): logger.info("执行登录接口开始") data = {} data["username"] = testData["username"] #admin data["password"] = testData["password"] #1234 print(data) # get_data = queue.Queue() # # forword = get_data.qsize() # # print(forword) # login_msg = get_data.put(data, timeout=5) # after = get_data.qsize() # # print(after) # # print(login_msg) # get_logindata = get_data.get() # # print(get_logindata) # username = get_data.get(data, timeout=5) # # # print(login_msg) # print(data) headers = {"Content-Typ": "application/json"} res = self.post(testData["url"], data, headers) print(res.json()) self.assertIn(testData["username"], res.json(), "请求成功")
def post(self, url, data={}, headers={}): logger.info("执行post请求开始") try: response = requests.post(url, data=data, headers=headers) logger.info("执行post请求成功") return response except BaseException as e: logger.info("请求失败!", str(e)) return ""
def delete(self, url, data={}, headers={}): logger.info("执行delete请求开始") try: response = requests.put(url, data=data, headers=headers) logger.info("执行delete请求成功") return response.content except BaseException as e: print() logger.info("执行delete请求失败!", str(e)) return ""