class Driver(): # 获取项目绝对路劲并且组合需要的新路径 x = Root_xpath() dir = x.get_root_path() # 获取浏览器驱动的路径 Chrome_driver_path = dir + '/tools/chromedriver.exe' Ie_driver_path = dir + '/tools/IEDriverServer.exe' # def __init__(self,driver): # self.driver = driver def open_browser(self): # def open_browser(self): #实例化配置文件类 config = configparser.ConfigParser() #获取配置文件路劲,并读取 # driver_config_xpath = os.path.dirname(os.path.abspath('.'))+'/config/driver.ini' # url_manage_xpath = os.path.dirname(os.path.abspath('.'))+'/config/url.ini' driver_config_xpath = self.dir + '/Data/Configs/driver.ini' url_manage_xpath = self.dir + '/Data/Configs/url.ini' config.read(driver_config_xpath) #读取config的驱动,url信息 browser = config.get('browserType', 'browserName') logger.info("即将启动的浏览器驱动为:%s 浏览器." % browser) config.read(url_manage_xpath) url = config.get("testServer", "URL") logger.info("即将进入的域名是: %s" % url) # 驱动启动,写日志 if browser == "Firefox": driver = webdriver.Firefox() logger.info("开始打开Firefox浏览器...") elif browser == "Chrome": option = webdriver.ChromeOptions() # option.add_argument('disable-infobars') # option.add_argument('headless') driver = webdriver.Chrome(self.Chrome_driver_path) logger.info("开始打开Chrome浏览器...") elif browser == "IE": driver = webdriver.Ie(self.Ie_driver_path) logger.info("开始打开IE浏览器...") # 打开网址并且写入日志 driver.get(url) logger.info("进入域名: %s" % url) driver.maximize_window() logger.info("浏览器窗口最大化.") driver.implicitly_wait(10) logger.info("浏览器最大等待时间为10秒") return driver # 退出浏览器 def quit_browser(self): logger.info("退出浏览器...") self.driver.quit()
class Logger(object): # 获取项目绝对路劲并且组合需要的新路径 x = Root_xpath() dir = x.get_root_path() def __init__(self, logger): ''''' 指定保存日志的文件路径,日志级别,以及调用文件 将日志存入到指定的文件中 ''' # 创建一个logger self.logger = logging.getLogger(logger) self.logger.setLevel(logging.DEBUG) # 创建一个handler,用于写入日志文件 logs_path = self.get_report_path() # 获取系统当前时间 month = time.strftime("%m", time.localtime(time.time())) day = time.strftime("%d", time.localtime(time.time())) logs_path = logs_path + r'/' + month + '月' report_statu = os.path.exists(logs_path) if report_statu == False: os.makedirs(logs_path) logs_path = logs_path + '/' + day +'日测试日志' + '.log' #创建日志输入端,fh输入到日志文件,ch输出到控制台,定义日志级别为info fh = logging.FileHandler(logs_path,encoding='utf-8') fh.setLevel(logging.INFO) ch = logging.StreamHandler() ch.setLevel(logging.INFO) # 定义handler的输出格式 formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(name)s[line:%(lineno)d] - %(message)s') fh.setFormatter(formatter) ch.setFormatter(formatter) # 给logger添加handler self.logger.addHandler(fh) self.logger.addHandler(ch) def getlog(self): return self.logger def get_report_path(self): root = Root_xpath() logs_path = root.get_root_path() logs_path = logs_path + '/Data/Logs' return logs_path
def get_report_path(self): root = Root_xpath() root_path = root.get_root_path() report_path = root_path + '/Data/Report' return report_path
def __init__(self): xpath = Root_xpath() self.excel_path = xpath.get_root_path() + '/Data/Excel/'
def get_report_path(self): root = Root_xpath() root_path = root.get_root_path() Screen_path = root_path + '/Data/Screenshots' return Screen_path
def __init__(self): self.config = configparser.ConfigParser() xpath = Root_xpath() self.xpath = xpath.get_root_path()
def get_report_path(self): root = Root_xpath() logs_path = root.get_root_path() logs_path = logs_path + '/Data/Logs' return logs_path