栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

web端自动化测试框架之selenium4从入门到项目实战-1-selenium环境搭建-7-配置文件

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

web端自动化测试框架之selenium4从入门到项目实战-1-selenium环境搭建-7-配置文件

1、编写配置文件

LocalElement.ini

[RegisterElement]
user_email=id>register_email
user_name=id>register_nickname
password=name>password
code_image=id>getcode_num
code_text=xpath>//*[@id="captcha_code"]
register-btn=css>#register-btn
2、安装Configparser
pip install Configparser

3、简单读取-low

 

import configparser

cf = configparser.ConfigParser()
cf.read("../config/LocalElement.ini")
print(cf.get('RegisterElement', 'user_email'))

 4、重构代码
# -*- coding: utf-8 -*- 
# @Time : 2021/12/23 19:39 
# @Author : jeffky
# @File : read_ini.py
import configparser
# "../config/LocalElement.ini"
class ReadIni(object):
    def __init__(self,file_name=None,node=None):
        if file_name==None:
            file_name="../config/LocalElement.ini"
        if node==None:
            node="RegisterElement"
        self.cf = self.load_ini(file_name)
        self.node =node
    #加载文件
    def load_ini(self,file_name):
        cf = configparser.ConfigParser()
        cf.read(file_name)
        return cf
    #获取value值
    def get_value(self,key):
        data = self.cf.get(self.node, key)
        return data
if __name__ == '__main__':
    read_ini = ReadIni()
    print(read_ini.get_value('code_text'))
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/679257.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号