自动化测试pytest.ini文件

[pytest]
#生成allure报告
addopts= -vs --alluredir=report --clean-alluredir
#指定路径
testpaths= ./testcase
#指定文件
python_files= test_*.py
#指定class
python_classes=Test*
#指定方法
python_functions=test_*
#指明要执行的case
markers=
        login
        order
        smoke

addopts详解:

  • -s 详细输出
  • -v 输出具体运行的case

--alluredir= report 生成临时报告

--clean-alluredir 清空临时报告

#标记marker
@pytest.mark.login
#执行顺序
@pytest.mark.run(order=1)
def test_login(self,browser_fixture):

conftest.py:管理fixture,一个文件夹下只能有一个conftest.py

@pytest.fixture(scope='class',params=[url])
def browser_fixture(request):
    driver = webdriver.Chrome()
    driver.get(request.param)
    print('打开浏览器'+request.param)
    yield driver
    driver.quit()
    print('关闭浏览器')

常用读取文件方法

readexcel.py

from openpyxl import Workbook, load_workbook


class ReadExcel():
    # 定义方法:读取指定目录下Excel文件某个sheet单元格的值
    def read_excel(filepath,index,x,y):
        #wb=Workbook()
        wb=load_workbook(filepath)
        sheetname=wb.sheetnames[index]
        sheet=wb[sheetname]

        return sheet.cell(x,y).value

    def write_excel(filepath,index,x,y,newstr):
        wb = load_workbook(filepath)
        sheetname = wb.sheetnames[index]
        sheet = wb[sheetname]
        sheet.cell(x,y).value=newstr
        wb.save(filepath)

readfile.py

class ReadFile:
    def get_txtfile(self,filename):
        # 获取登录参数
        with open(filename, 'r', encoding='utf-8') as loginfile:
            login_dict = {}
            for loginline in loginfile.readlines():
                loginline = loginline.strip()
                k = loginline.split(' ')[0]
                v = loginline.split(' ')[1]
                login_dict[k] = v

            loginfile.close()
            return login_dict

    def get_txtfile1(filename):
        # 获取登录参数
        with open(filename, 'r', encoding='utf-8') as loginfile:
            login_dict = {}
            for loginline in loginfile.readlines():
                loginline = loginline.strip()
                k = loginline.split(' ')[0]
                v = loginline.split(' ')[1]
                login_dict[k] = v

            loginfile.close()
            return login_dict

    def get_jsonfile(self,filename):
        with open(filename,'r',newline='') as file:
            lcookie=json.load(file)
        file.close()
        return lcookie

    def get_jsonfile1(filename):
        with open(filename,'r',newline='') as file:
            lcookie=json.load(file)
        file.close()
        return lcookie

readyml

def read_yaml():
    fileNamePath = os.path.split(os.path.realpath(__file__))[0]
    yamlpath = os.path.join(fileNamePath, 'nfig.yaml')
    with open(yamlpath,'r',encoding='utf-8') as ymalfile:
        conf=ymalfile.read()
    mysqlyaml=yaml.load(conf)
    #print(mysqlyaml)
    return  mysqlyaml

Allure Framework

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值