class Test_register(unittest.TestCase): def setUp(self) -> None: self.oper = OperationExcel(CONFIG_FILE) #实例化db self.db = DB() self.url = 'http://ecshop.itsoso.cn/ECMobile/?url=/user/signup' self.fk = Faker('zh_CN') def test_case_01(self): """正向数据注册""" name = self.fk.user_name() # 姓名 email = self.fk.email() # 邮箱 phone = self.fk.phone_number() # 手机号 password = self.fk.password() # 密码 id = self.fk.pyint() # 随机整数 add_list = [] add_list.extend([name,email,phone,password]) self.oper.write_excel(add_list) data = {"field": [{"id": id, "value": f"{phone}"}], "email": f"{email}", "name": f"{name}", "password": f"{password}"} response = Interface_register.regiester(method='post',url=self.url,data=data) self.result = get_result_one(response, 'succeed') self.assertEqual(self.result,1) sql = f"select count(*) from ecs_users where user_name = '{name}'" datas = self.db.find_one(sql) num = datas['count(*)'] self.assertEqual(num,1) del_sql = f"delete from ecs_users where user_name='{name}'" self.db.execute(del_sql) @ddt.data(*test_data) def test_case_02(self,data): """逆向数据注册""" data = {"field": [{"id": 123, "value": f"{data['phone']}"}], "email": f"{data['email']}", "name": f"{data['name']}", "password": f"{data['password']}"} response = Interface_register.regiester(method='post', url=self.url, data=data) result = get_result_one(response, 'succeed') self.assertEqual(result,0) #写一个sql语句 sql = f"select count(*) from ecs_users where user_name = '{data['name']}'" #执行sql datas = self.db.find_one(sql) num = datas['count(*)'] self.assertEqual(num,0) del_sql = f"delete from ecs_users where user_name='{data['name']}'" self.db.execute(del_sql)
import unittest from interface.interface_personal import InterfacePersonal from interface.interface_login import InterfaceLogin from common.get_result_easy import get_result_for_keyword from common.operationexcel import OperationExcel import os import ddt import json BASE_PATH = os.path.split(os.path.dirname(os.path.realpath(__file__)))[0] data_file = os.path.join(BASE_PATH, "data", "address_data.xlsx") oper_excel = OperationExcel(data_file) test_data = oper_excel.get_data_for_dict() @ddt.ddt class TestPersonal(unittest.TestCase): """ 个人中心测试用例 """ def setUp(self) -> None: # 登录 self.method = "post" url = "http://ecshop.itsoso.cn/ECMobile/?url=/user/signin" data = {"name": "u123", "password": "******"} response = InterfaceLogin.login(method=self.method, url=url, data=data) self.sid = get_result_for_keyword(response, "sid") # 获取登录返回值的sid self.uid = get_result_for_keyword(response, "uid") # 获取登录返回值的uid def test_1_waite_pay(self): """待付款"""
import unittest from common.get_result import get_result_one from interface.interface import Interface from scripts.test_login import Login from common.database import Database import ddt, os from common.operationexcel import OperationExcel ADDRESS_FILE = os.path.split(os.path.dirname(os.path.realpath(__file__)))[0] config = os.path.join(ADDRESS_FILE, 'data', 'address_data.xlsx') opear = OperationExcel(config) test_data = opear.get_data_for_dict() @ddt.ddt class TestAddress(unittest.TestCase): def setUp(self): self.session = Login.login() self.db = Database() def test_address_01(self): """新增地址--合法数据""" #测试之前先查看数量 sql = "select count(*) from ecs_user_address where user_id = (select user_id from ecs_users where user_name = 'hxj123456')" datas = self.db.one(sql) num = datas['count(*)'] add_url = "http://ecshop.itsoso.cn/ECMobile/?url=/address/add" #新增地址的网址 method = "post" add_data = { "address": { "default_address": 0, "consignee": "han123",
""" 登录模块---测试用例 编写人:廖松林 """ import time import unittest import ddt from page.login_page import LoginPage, url from common.base import open_browser from common.operationexcel import OperationExcel oper_excel = OperationExcel(r"D:\test\ECshop_第三组\data\testdata01.xlsx") test_data = oper_excel.get_data_for_dict() @ddt.ddt class TestLogin(unittest.TestCase): def setUp(self): """打开浏览器,打开被测网址""" driver = open_browser() self.login = LoginPage(driver) self.login.open_url(url) def tearDown(self): """关闭浏览器""" self.login.close() """编写测试用例""" @ddt.data(*test_data)
from common.operationexcel import OperationExcel import unittest from common.database import Database from common.get_result import get_result_one import ddt, os from faker import Faker from interface.interface import Interface BASE_PATH = os.path.split(os.path.dirname( os.path.realpath(__file__)))[0] # 获取当前目录--获取项目目录 ERROR_FILE = os.path.join(BASE_PATH, 'data', 'test_data.xlsx') # 将"data"文件夹添加到当前目录 error_oper = OperationExcel(ERROR_FILE) test_datas = error_oper.get_data_for_dict() @ddt.ddt class Test_Register(unittest.TestCase): def setUp(self): self.url = "http://ecshop.itsoso.cn/ECMobile/?url=/user/signup" # 请求地址 self.method = 'post' # 请求方式 # 实例化DB self.db = Database() self.fk = Faker('zh_CN') def test_case_01(self): """正向数据注册成功""" name = self.fk.user_name() # 姓名 email = self.fk.email() # 邮箱 phone = self.fk.phone_number() # 手机号
def setUp(self) -> None: self.oper = OperationExcel(CONFIG_FILE) #实例化db self.db = DB() self.url = 'http://ecshop.itsoso.cn/ECMobile/?url=/user/signup' self.fk = Faker('zh_CN')