Exemplo n.º 1
0
common = BASE_DIR + '/public/common'
base = BASE_DIR + '/public/base'
conf_path = conf.replace('/', '\\')
public_path = public.replace('/', '\\')
common_path = common.replace('/', '\\')
base_path = base.replace('/', '\\')
sys.path.append(conf_path)
sys.path.append(public_path)
sys.path.append(base_path)
sys.path.append(common_path)
from public.common.send_email import send_mail
from public.pakeage.HTMLTestRunner3 import HTMLTestRunner
from public.common.get_config import r_config
from public.common.get_files import get_new_file

img_path = r_config(conf_path, 'image', 'img_path')
log_path = r_config(conf_path, 'log', 'log_path')
report_path = r_config(conf_path, 'report', 'report_path')
test_case_path = r_config(conf_path, 'test_case', 'test_case_path')

if __name__ == '__main__':
    now_time = time.strftime("%Y-%m-%d-%H-%M-%S")
    fp = open(report_path + now_time + "_result.html", 'wb')
    runner = HTMLTestRunner(fp,
                            title="网易邮箱测试报告",
                            description="运行环境:macOS Sierra, chrome")
    discover = unittest.defaultTestLoader.discover(test_case_path,
                                                   pattern='login_*.py')
    runner.run(discover)
    fp.close()
    file_path = get_new_file(report_path)
Exemplo n.º 2
0
# coding=utf-8

import os, sys, time, logging
from public.common.get_config import r_config

BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
conf_path = BASE_DIR + '/config/config.ini'
conf_path = conf_path.replace('/', '\\')
log_path = r_config(conf_path, "log", "log_path")


class Log():
    def __init__(self, conf_path):
        self.logname = os.path.join(
            log_path, '{0}.log'.format(time.strftime('%Y-%m-%d')))

    def __printconsole(self, level, message):
        # 创建一个logger
        logger = logging.getLogger()
        logger.setLevel(logging.DEBUG)
        # 创建一个handler,用于写入日志文件
        fh = logging.FileHandler(self.logname, 'a', encoding='utf-8')
        fh.setLevel(logging.DEBUG)
        # 再创建一个handler,用于输出到控制台
        ch = logging.StreamHandler()
        ch.setLevel(logging.DEBUG)
        # 定义handler的输出格式
        formatter = logging.Formatter(
            '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
        fh.setFormatter(formatter)
        ch.setFormatter(formatter)
Exemplo n.º 3
0
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By

BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
conf_path = BASE_DIR + '/config/config.ini'
conf_path = conf_path.replace('/', '\\')

from public.common.get_log import Log
from public.common.get_config import r_config
from selenium.webdriver.common.keys import Keys

img_path = r_config(conf_path, 'image', 'img_path')
log_path = r_config(conf_path, 'log', 'log_path')
success = "SUCCESS   "
fail = "FAIL   "
logger = Log(log_path)


class base_frame(object):
    def __init__(self, driver, base_url="http://www.baidu.com"):
        self.driver = driver
        self.base_url = base_url
        self.timeout = 30

    def my_print(self, msg):
        logger.info(msg)
Exemplo n.º 4
0
import os
from public.common.get_config import r_config
from selenium.webdriver import Remote
from selenium import webdriver

BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
conf_path = BASE_DIR + '/config/config.ini'
conf_path = conf_path.replace('/', '\\')
img_path = r_config(conf_path, "image", "img_path")
print(img_path)


def insert_img(driver, file_name):
    driver.get_screenshot_as_file(file_name)


# 启动浏览器驱动
def browser():
    driver = webdriver.Chrome()
    '''
    host = '127.0.0.1:4444' # 运行主机:端口号 (本机默认:127.0.0.1:4444)
    dc = {'browserName': 'chrome'} # 指定浏览器('chrome','firefox',)
    driver = Remote(command_executor='http://' + host + '/wd/hub',
                    desired_capabilities=dc)
    '''
    return driver


if __name__ == '__main__':
    driver = webdriver.Chrome()
    driver.get("https://www.baidu.com")