def test_no_right_account(self): """创建学生 没有权限的账号""" try: self.xls = xls['使用非管理员权限的角色添加学生'] self.account = self.xls['account'] self.password = self.xls['password'] print(self.account) no_right_login_result, no_right_login_cookies = Login.Login( self.account, self.password) self.base_url = self.xls['base_url'] self.method = self.xls['method'] self.data = self.xls['data'].encode('utf-8') self.errno = self.xls['errno'] self.message = self.xls['message'] result = requests.post(self.base_url, data=self.data, headers=self.headers, cookies=no_right_login_cookies) result = result.json() try: self.assertEqual(result['errno'], self.errno) self.assertEqual(result['message'], self.message) except Exception as error: logging.error(error) except Exception as error: logging.error(error)
def test_account_error(self): """测试账号不存在""" logins = root.getElementsByTagName('account_error') username = logins[0].getAttribute('username') password = logins[0].getAttribute('password') self.result = Login.Login(username, password) self.assertEqual(self.result['errmsg'], '登录失败') self.assertEqual(self.result['errno'], 1001)
def test_login_pwd_error(self): """密码错误""" logins = root.getElementsByTagName('password_error') username = logins[0].getAttribute('username') password = logins[0].getAttribute('password') self.result = Login.Login(username, password) self.assertEqual(self.result['errmsg'], "登录失败") self.assertEqual(self.result['errno'], 1001)
def test_login_success(self): """测试登录成功""" logins = root.getElementsByTagName('success') username = logins[0].getAttribute('username') password = logins[0].getAttribute('password') # 分别赋值结果和返回的cookie信息 self.result, self.cookies = Login.Login(username, password) # cookies = r.cookies # cookies=(';'.join(['='.join(item) for item in cookies.items()])) self.assertEqual(self.result['errmsg'], 'OK') self.assertEqual(self.result['errno'], 0)
import common.Login as Login class Test(object): def test_open(self, driver): driver.get(Config.url + 'mainFrame?id=DACX') time.sleep(5) def test_b_api_add(self, driver): driver.find_element_by_xpath( "//li/div/span[contains(text(),'B接口')]").click() # driver.implicitly_wait(10) iframe = driver.find_element_by_tag_name("iframe") bapi_url = iframe.get_attribute("src") # driver.get(bapi_url) driver.switch_to.frame("iframe1080") time.sleep(8) driver.find_element_by_xpath("//td[contains(text(),'添加')]").click() driver.find_element_by_xpath("//input[0]").send_keys("scott0") driver.find_element_by_xpath("//input[1]").send_keys("scott1") driver.find_element_by_xpath("//input[2]").send_keys("scott2") driver.quit() if __name__ == '__main__': bean = Test() driver = Login.Test().test_login() bean.test_open(driver) bean.test_b_api_add(driver)
# 酒醒只在网上坐,酒醉还来网下眠; # 酒醉酒醒日复日,网上网下年复年。 # 但愿老死电脑间,不愿鞠躬老板前; # 奔驰宝马贵者趣,公交自行程序员。 # 别人笑我忒疯癫,我笑自己命太贱; # 不见满街漂亮妹,哪个归得程序员? # import unittest import requests import sys from common.Log import MyLog as Log import common.Login as Login from common.common import get_xls import logging sys.path.append('C:\\Users\\Administrator\\Desktop\\exam_api_test') login_result, cookies = Login.Login('10013000', '123456') xls = get_xls('create_student.xlsx', 'Sheet1') class CreateStudent(unittest.TestCase): def setUp(self): self.headers = { 'Accept': 'application/json, text/plain, */*', 'Content-Type': 'application/x-www-form-urlencoded', 'Content - Length': '297', 'Host': '192.168.1.10:8705', 'Origin': 'http: // 192.168.1.10: 8705', 'Proxy - Connection': 'keep - alive', 'Referer': 'http://192.168.1.10: 8705/' } log = Log.get_log()
import unittest import requests import sys from common.Log import MyLog as Log import common.Login as Login from common.common import get_xls import logging sys.path.append('C:\\Users\\Administrator\\Desktop\\exam_api_test') login_result, cookies = Login.Login('19900200002', '123456') xls = get_xls('get_exam.xlsx', 'Sheet1') class TestGetExam(unittest.TestCase): def setUp(self): self.headers = {'content-type': 'application/json'} log = Log.get_log() logger = log.get_logger() def test_GetExam_success(self): """测试请求成功""" try: self.xls = xls['测试通过'] self.base_url = self.xls['base_url'] self.data = self.xls['data'] self.errorno = self.xls['errno'] self.classid = self.xls['classid'] self.subjectid = self.xls['subjectId'] self.s = requests.Session() r = self.s.get(self.base_url, params=self.data) self.result = r.json() self.assertEqual(self.result['errno'], self.errorno)