コード例 #1
0
ファイル: mail.py プロジェクト: yzdx0000/AutoTestFramework
    def __init__(self, title, message=None, path=None, server=None, sender=None, password=None, receiver=None):
        """初始化Email

        :param title: 邮件标题,必填。
        :param message: 邮件正文,非必填。
        :param path: 附件路径,可传入list(多附件)或str(单个附件),非必填。
        :param server: smtp服务器,如果为空,则读取config.ini中的[email]/server,非必填。
        :param sender: 发件人,如果为空,则读取config.ini中的[email]/from,非必填。
        :param password: 发件人密码,如果为空,则读取config.ini中的[email]/password,如果读取失败,则需手动输入密码,非必填。
        :param receiver: 收件人,如果为空,则读取config.ini中的[email]/to,多收件人用“;”隔开,非必填。
        """
        self.logger = Logger(__name__).get_logger()

        self.title = title
        self.message = message
        self.files = path

        self.msg = MIMEMultipart('related')

        cf = DefaultConfig()
        if server:
            self.server = server
        else:
            self.server = cf.get('email', 'server')

        if sender:
            self.sender = sender
        else:
            self.sender = cf.get('email', 'from')

        if receiver:
            self.receiver = receiver
        else:
            self.receiver = cf.get('email', 'to')

        if password:
            self.password = password
        else:
            try:
                self.password = cf.get('email', 'pass')
            except NoOptionError:
                self.password = getpass(prompt=u'未在config.ini中检测到password,请输入password: ')
コード例 #2
0
ファイル: browser.py プロジェクト: yzdx0000/AutoTestFramework
    def _png_name(self, name):
        day = save_date()
        tm = save_time()

        fp = DefaultConfig().report_path + day + "\\image"
        img_type = ".png"

        if not os.path.exists(fp):
            os.makedirs(fp)

        return str(fp) + "\\" + str(tm) + "_" + name + img_type
コード例 #3
0
    def __init__(self, book, sheet=0):
        """Read workbook

        :param book: work_book name.Not path.
        :param sheet: index of sheet or sheet name.
        """
        self.logger = Logger(self.__class__.__name__).get_logger()
        self.book_name = '{0}\\{1}'.format(DefaultConfig().data_path, book)
        self.sheet_locator = sheet

        self.book = self._book()
        self.sheet = self._sheet()
コード例 #4
0
    def __init__(self, logger_name='root'):

        self.logger = logging.getLogger(logger_name)
        logging.root.setLevel(logging.NOTSET)

        cf = DefaultConfig()
        self.log_path = cf.log_path
        self.log_file_name = cf.get('logging', 'log_file_name')
        self.backup_count = cf.getint('logging', 'backup_count')

        self.console_output_level = cf.get('logging', 'console_output_level')
        self.file_output_level = cf.get('logging', 'file_output_level')

        self.console_output = cf.getint('logging', 'console_output')
        self.file_output = cf.getint('logging', 'file_output')

        self.formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
コード例 #5
0
    def upload_by_autoit(self, files):
        """autoit方式 —— 打开窗口,并上传文件(支持多文件上传,files参数传入list)"""
        self._window_open()
        self._files(files)
        self.logger.info('upload {} by autoit'.format(self.files))

        # 验证是否打开窗口
        if win32gui.FindWindow('#32770', self.window_name):
            self.window_open_flag = 1
        else:
            raise UploadWindowNotOpenError('未发现上传文件对话框!')

        upfile = os.path.abspath(DefaultConfig().base_path + '\\src\\resource\\' + AUTOITEXE[self.driver.name])
        os.system('{0} {1}'.format(upfile, self.files))  # 调用exe,上传文件

        self.window_open_flag = 0
コード例 #6
0
ファイル: logger.py プロジェクト: yzdx0000/AutoTestFramework
    def __init__(self, logger_name='root'):

        self.logger = logging.getLogger(logger_name)
        logging.root.setLevel(logging.NOTSET)

        cf = DefaultConfig()
        self.log_path = cf.log_path
        self.log_file_name = cf.get('logging', 'log_file_name')
        self.backup_count = cf.getint('logging', 'backup_count')

        self.console_output_level = cf.get('logging', 'console_output_level')
        self.file_output_level = cf.get('logging', 'file_output_level')

        self.console_output = cf.getint('logging', 'console_output')
        self.file_output = cf.getint('logging', 'file_output')

        self.formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
コード例 #7
0
ファイル: mail.py プロジェクト: yzdx0000/AutoTestFramework
    def __init__(self,
                 title,
                 message=None,
                 path=None,
                 server=None,
                 sender=None,
                 password=None,
                 receiver=None):
        """初始化Email

        :param title: 邮件标题,必填。
        :param message: 邮件正文,非必填。
        :param path: 附件路径,可传入list(多附件)或str(单个附件),非必填。
        :param server: smtp服务器,如果为空,则读取config.ini中的[email]/server,非必填。
        :param sender: 发件人,如果为空,则读取config.ini中的[email]/from,非必填。
        :param password: 发件人密码,如果为空,则读取config.ini中的[email]/password,如果读取失败,则需手动输入密码,非必填。
        :param receiver: 收件人,如果为空,则读取config.ini中的[email]/to,多收件人用“;”隔开,非必填。
        """
        self.logger = Logger(__name__).get_logger()

        self.title = title
        self.message = message
        self.files = path

        self.msg = MIMEMultipart('related')

        cf = DefaultConfig()
        if server:
            self.server = server
        else:
            self.server = cf.get('email', 'server')

        if sender:
            self.sender = sender
        else:
            self.sender = cf.get('email', 'from')

        if receiver:
            self.receiver = receiver
        else:
            self.receiver = cf.get('email', 'to')

        if password:
            self.password = password
        else:
            try:
                self.password = cf.get('email', 'pass')
            except NoOptionError:
                self.password = getpass(
                    prompt=u'未在config.ini中检测到password,请输入password: ')
コード例 #8
0
ファイル: mail.py プロジェクト: yzdx0000/AutoTestFramework
        # 连接服务器并发送
        try:
            smtp_server = smtplib.SMTP(self.server)
        except (gaierror and error) as e:
            self.logger.exception(u'发送邮件失败,无法连接到SMTP服务器,检查网络以及SMTP服务器. %s', e)
        else:
            try:
                smtp_server.login(self.sender, self.password)
            except smtplib.SMTPAuthenticationError as e:
                self.logger.exception(u'用户名密码验证失败!%s', e)
            else:
                smtp_server.sendmail(self.sender, self.receiver.split(';'),
                                     self.msg.as_string())
            finally:
                smtp_server.quit()
                self.logger.info(u'发送邮件"{0}"成功! 收件人:{1}。如果没有收到邮件,请检查垃圾箱,'
                                 u'同时检查收件人地址是否正确'.format(
                                     self.title, self.receiver))


if __name__ == '__main__':
    tit = u'测试报告'
    tex = '这是今天的测试报告!请查看'
    p = DefaultConfig().get('path', 'report')
    from src.utils.support import get_newest_file_of_path
    newestfile = get_newest_file_of_path(p)
    filename = p + newestfile[0]
    print filename
    email = Email(title=tit, message=tex, path=[filename])
    email.send()
コード例 #9
0
    def __init__(self, fname):
        self.logger = Logger(__name__).return_logger()
        self.fpath = '{}\\{}'.format(DefaultConfig().data_path, fname)

        self._read()
コード例 #10
0
 def __init__(self, fname):
     self.fpath = '{}\\{}'.format(DefaultConfig().data_path, fname)
     self._yaml = None
コード例 #11
0
# -*- coding: utf-8 -*-
import os
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.action_chains import ActionChains
from time import sleep
from threading import Thread
from src.utils.config import DefaultConfig
import random
driver_path = DefaultConfig().driver_path
KEYWORDS = [u'selenium 兼容 灰蓝', u'selenium 时间 灰蓝', u'selenium 文件上传 灰蓝', u'selenium 坑 灰蓝',
            u'selenium editor 灰蓝', u'selenium 结构设计 灰蓝', u'selenium ActionChains 灰蓝', u'selenium alert 灰蓝',
            u'selenium checkbox 灰蓝', u'selenium Select 灰蓝', u'selenium 网页内嵌 灰蓝', u'selenium 映射表 灰蓝',
            u'selenium 导航栏 灰蓝', u'selenium active_element 灰蓝', u'selenium close 灰蓝', u'selenium Keys 灰蓝',
            u'selenium 输出报告 示例 灰蓝', u'selenium autoit命令行 灰蓝']


def clk(driver, url):
    """locate and click url"""
    locator = (By.XPATH, '//span[contains(text(), "{0}")]/../../../../a'.format(url))
    try:
        WebDriverWait(driver, 5, 0.5).until(EC.element_to_be_clickable(locator))
        try:
            moved_to_element = driver.find_element_by_xpath('//span[contains(text(), "{0}")]'.format(url))
            target_element = driver.find_element(*locator)
            ActionChains(driver).move_to_element(to_element=moved_to_element).click(target_element).perform()
            sleep(1)
コード例 #12
0
    def __init__(self, xml):
        self.logger = Logger(self.__class__.__name__).get_logger()
        self.xml = '{0}\\{1}'.format(DefaultConfig().data_path, xml)

        self.tree = self._tree()
        self.logger.info('read file: {0}'.format(self.xml))
コード例 #13
0
"""此类用来生成测试文件,从数据文件中读取测试用例,从xml中读取接口配置,组织到测试文件中。

一个接口是一个class,每一条测试用例是一个method。

"""

from src.utils.filereader.file_reader import *
from src.utils.config import DefaultConfig, Config
from src.utils.logger import Logger
from src.utils.utils_exception import UnSupportFileType, NoSectionError, NoOptionError
from src.utils.filereader.parsing import *
from src.utils.filereader.generators import parse_generator
from src.utils.testutil.tests import RestTest
from src.utils.testutil.testset import TestConfig, TestSet

DATA_PATH = DefaultConfig().data_path
logger = Logger(__name__).get_logger()


def parse_testsets(base_url, test_structure, vars=None):
    """ 将从YAML里读出来的Python数据结构的数据转化成一个testset列表
    这个数据结构是一个字典的列表,其中描述:
        - test
        - simple test(仅仅是一个URL,是一个最小的test)
        - config(所有test的通用配置)

    返回一个testsets的列表。
    """
    testsets = list()

    for test_set in test_structure:
コード例 #14
0
ファイル: browser.py プロジェクト: yzdx0000/AutoTestFramework
# -*- coding: utf-8 -*-

import os
import time
from selenium import webdriver
from src.utils.config import DefaultConfig
from selenium.common.exceptions import WebDriverException
from src.utils.utils_exception import (UnSupportBrowserTypeException,
                                       ParameterError)
from src.utils.support import save_time, save_date
from selenium.webdriver.common.action_chains import ActionChains

# todo:log
# todo([email protected]): 完善Browser Page类,添加注释

DRIVER_PATH = DefaultConfig().driver_path
ChromeDriver = DRIVER_PATH + '\\chromedriver.exe'
IEDriver = DRIVER_PATH + '\\IEDriverServer.exe'

TYPES = {
    'firefox': webdriver.Firefox,
    'chrome': webdriver.Chrome,
    'ie': webdriver.Ie
}
EXECUTABLE_PATH = {'firefox': 'wires', 'chrome': ChromeDriver, 'ie': IEDriver}


class Browser(object):
    """浏览器类,根据传入的参数打开不同的浏览器

    methods: