def __init__(self): self.dbs = {} import os home = os.getenv('HOME') pro = Properties(home + '/habo/etl/python/resources/db.properties') self.property = pro.get_properties()
def setUp(self): properties = Properties('../testBaidu.properties') self.url = properties.getProperties().get('url') self.key = properties.getProperties().get('key') # 加载chrome驱动 self.driver = webdriver.Chrome() # 配置窗口尺寸 # driver.set_window_size("400", "600") self.driver.maximize_window() # 设置等待时长 self.driver.implicitly_wait(10)
def __init__(self): """ MysqlConnector的初始化方法,里面默认从/conf/jdbc.properties中读取关于mysql连接的基本信息 """ self._conn = None self._cursor = None try: properties = Properties('/conf/jdbc.properties').getProperties() self._conn = MysqlConnector.__getConn(properties) self._cursor = self._conn.cursor() except AttributeError as ex: MysqlConnector.__logger.info("数据库连接失败!") MysqlConnector.__logger.error("__init__(self)方法报错")
def __init__(self): """ Neo4j的初始化方法,里面默认从/conf/neo4j.properties中读取关于neo4j连接的基本信息 """ self._graph = None try: properties = Properties('/conf/neo4j.properties').getProperties() self._graph = Graph( host=properties['neo4j.host'], # neo4j服务地址 http_port=int(properties['neo4j.port']), # neo4j端口号 user=properties['neo4j.username'], # neo4j的用户名,默认neo4j password=properties['neo4j.password']) # neo4j的密码,默认neo4j except Exception as ex: self.__logger.info("数据库连接失败,数据库名/数据库用户名/数据库密码错误") self.__logger.exception(ex)
def __init__(self): """ MongoConnector的初始化方法,里面默认从/conf/jdbc.properties中读取关于mongodb连接的基本信息 """ self._mongoClient = None self._db = None try: properties = Properties('/conf/jdbc.properties').getProperties() self._mongoClient = MongoConnector.__getMongoClient(properties) self._db = self._mongoClient['%s' % (properties['mongodb.database'])] self._db.authenticate(properties['mongodb.username'], properties['mongodb.password'], mechanism=properties['mongodb.mechanism']) except Exception as ex: MongoConnector.__logger.info("数据库连接失败,数据库名/数据库用户名/数据库密码错误") MongoConnector.__logger.exception(ex)
# -*- coding: utf-8 -*- import time from load_driver import * from util.Properties import Properties # driver = load_firefox() driver = load_chrome() try: driver.get("https://www.imooc.com/") # 最大化浏览器窗口 driver.maximize_window() time.sleep(2) print(driver.title) # 加载本地属性文件 local_properties = Properties('local.properties').get_properties() # 添加 Cookie driver.add_cookie({'name': 'apsid', 'value': local_properties['apsid']}) # 刷新,变为已登录状态 driver.refresh() time.sleep(5) except Exception as e: print(e) finally: driver.quit() pass
def get_properties(): p = Properties() #print os.getcwd() p.load(open('C:\\Users\\song\\learn\\config\\config.properties')) return p
def __init__(self, prop_file): # self._properties = Properties('/conf/email.properties').getProperties() self._properties = Properties(prop_file).getProperties()
''' 创建节点与节点之间的关系 :param start_node: :param end_node: :param edges: :param rel_type: :param rel_name: :return: ''' count = 0 # 去重处理 set_edges = [] for edge in edges: set_edges.append('###'.join(edge)) for edge in set(set_edges): edge = edge.split('###') start_node_name = edge[0] end_node_name = edge[1] query = "match(p:%s),(q:%s) where p.name='%s'and q.name='%s' create (p)-[rel:%s{name:'%s'}]->(q)" % ( start_node, end_node, start_node_name, end_node_name, rel_type, rel_name) try: self._graph.run(query) count += 1 except Exception as ex: self.__logger.exception(ex) if __name__ == '__main__': properties = Properties('/conf/neo4j.properties').getProperties() print(properties)
import os from excep.myException import * from suite.testBaidu import * from util.HTMLTestRunner import * from util.Properties import Properties properties = Properties('../config.properties') reportPath = properties.getProperties().get('report_path') if not os.path.exists(reportPath): raise MyException('config exception', '配置文件中指定的报告路径不存在') else: pass now = time.strftime("%Y-%m-%d-%H_%M_%S", time.localtime(time.time())) HtmlFile = reportPath + now + ".html" current_time = time.strftime("%Y-%m-%d-%H_%M_%S", time.localtime(time.time())) testUnit = unittest.TestSuite() # 构建测试套件 testUnit.addTest(BaiDu("test_01")) fp = open(reportPath + current_time + ".html", "wb") runner = HTMLTestRunner(stream=fp, verbosity=2, title=u"自动化测试报告", description="自动化测试演示报告", tester='lvhong') runner.run(testUnit) fp.close()