Ejemplo n.º 1
0
def t_send():
    # 所要执行的测试用例所在的位置
    test_dir = Read().getValue('test_dir')
    # 测试报告所在的路径
    test_report = Read().getValue('test_report')
    # 查找想要执行的文件
    discover = unittest.defaultTestLoader.discover(test_dir,
                                                   pattern='ranZhi.py')
    # 使用HTMLTestRunner来生成testRunner,生成html测试报告
    now_time = time.strftime("%Y%m%d%H%M%S")
    file_name = test_report + '\\' + now_time + 'result.html'
    fp = open(file_name, 'wb')
    runner = HTMLTestRunner(stream=fp,
                            title="测试报告",
                            description="运行环境:firefox")
    runner.run(discover)
    fp.close()

    # 查找修改日期最新的测试方法
    new_report1 = new_report(test_report)
    f = open(new_report1, 'rb')
    message = f.read()
    text = MIMEText(message, 'html', 'utf-8')
    # 发送测试报告
    send_email(text)
Ejemplo n.º 2
0
 def open_url_use_browser(self, browser_path, url):
     if browser_path == Read().getValue('firefox_path'):
         return webdriver.Firefox()
     elif browser_path == Read().getValue('chrome_path'):
         return webdriver.Chrome()
     elif browser_path == Read().getValue('ie_path'):
         return webdriver.Ie()
Ejemplo n.º 3
0
def send_email(po):
    def _format_addr(s):
        name, addr = parseaddr(s)
        return formataddr(
            (Header(name, 'utf-8').encode(), addr))  #如果包含中文,需要通过Header对象进行编码。

    to_addr = Read().getValue(
        'to_addr')  #["*****@*****.**","*****@*****.**"]
    tempTo = to_addr
    from_addr = Read().getValue('from_addr')
    password = Read().getValue('password')
    smtp_server = Read().getValue('smtp_server')
    msg = MIMEMultipart()  # 生成邮件体
    msg.attach(po)
    msg['From'] = _format_addr('ff <%s>' % from_addr)
    msg['To'] = ''.join(tempTo)
    msg['To'] = _format_addr('小组人员 <%s>')
    msg['Subject'] = Header('测试邮件', 'utf-8').encode()

    server = smtplib.SMTP(smtp_server, 25)  # SMTP协议默认端口是25
    server.set_debuglevel(1)  #打印出和SMTP服务器交互的所有信息
    server.login(from_addr, password)

    server.sendmail(from_addr, tempTo, msg.as_string())
    server.quit()
Ejemplo n.º 4
0
 def threads(self):
     data = [
         Read().getValue('firefox_path'),
         Read().getValue('chrome_path'),
         Read().getValue('ie_path')
     ]
     threads = []
     for i in data:
         t = Thread(target=Base1.open_url_use_browser,
                    args=(i, Read().getValue('base_url')))
         threads.append(t)
     for thr in threads:
         thr.start()
Ejemplo n.º 5
0
def t_send():
    # 所要执行的测试用例所在的位置
    test_dir = Read().getValue('test_dir')
    # 测试报告所在的路径
    test_report = Read().getValue('test_report')
    # 查找想要执行的文件
    discover = unittest.defaultTestLoader.discover(test_dir,
                                                   pattern='ranzhi_test.py')
    # 使用HTMLTestRunner来生成testRunner,生成html测试报告
    now_time = time.strftime("%Y%m%d%H%M%S")
    file_name = test_report + '\\' + now_time + 'result.html'
    fp = open(file_name, 'wb')
    runner = HTMLTestRunner(stream=fp,
                            title="测试报告",
                            description="运行环境:firefox")
    runner.run(discover)
    fp.close()
Ejemplo n.º 6
0
def startBrowser():
    browsername = Read().getValue('browserName')
    url = Read().getValue('url')
    if browsername == 'firefox':
        log.info('启动Firefox浏览器')
        driver = webdriver.Firefox()
        log.info('Firefox打开网页')
        driver.get(url)
        return driver
    elif browsername == 'IE':
        log.info('启动IE浏览器')
        driver = webdriver.Ie()
        log.info('IE打开网页')
        driver.get(url)
        return driver
    elif browsername == 'Chrome':
        log.info('启动Chrome浏览器')
        driver = webdriver.Chrome()
        log.info('Chrome打开网页')
        driver.get(url)
        return driver
Ejemplo n.º 7
0
def send_email(po):
    def _format_addr(s):
        name, addr = parseaddr(s)
        return formataddr(
            (Header(name, 'utf-8').encode(), addr))  #如果包含中文,需要通过Header对象进行编码。

    to_addr = Read().getValue('to_addr')
    tempTo = to_addr
    #smtp_server = "smtp.163.com"
    smtp_server = Read().getValue('smtp_server')
    msg = MIMEMultipart()
    msg.attach(po)

    msg['From'] = _format_addr('ff <%s>' % Read().getValue('from_addr'))
    msg['To'] = ''.join(tempTo)
    msg['To'] = _format_addr('小组人员 <%s>')
    msg['Subject'] = Header('测试邮件', 'utf-8').encode()

    server = smtplib.SMTP(smtp_server, 25)  # SMTP协议默认端口是25
    server.set_debuglevel(1)  #打印出和SMTP服务器交互的所有信息
    server.login(Read().getValue('from_addr'), Read().getValue('password'))
    #发送指定人邮件
    #server.sendmail(from_addr, [to_addr], msg.as_string())
    #发送多人
    server.sendmail(Read().getValue('from_addr'), tempTo, msg.as_string())
    server.quit()
Ejemplo n.º 8
0
def send_email(text):
    def _format_addr(s):
        name, addr = parseaddr(s)
        return formataddr(
            (Header(name, 'utf-8').encode(), addr))  #如果包含中文,需要通过Header对象进行编码。

    from_addr = Read().getValue('from_addr')
    password = Read().getValue('password')
    to_addr = Read().getValue('to_addr')
    smtp_server = Read().getValue('smtp_server')
    msg = MIMEMultipart()
    msg.attach(text)

    msg['From'] = _format_addr('ff <%s>' % from_addr)
    msg['To'] = ','.join(to_addr)
    msg['To'] = _format_addr('管理员 <%s>' % to_addr)

    msg['Subject'] = Header('测试邮件', 'utf-8').encode()
    server = smtplib.SMTP(smtp_server, 25)
    server.set_debuglevel(1)
    server.login(from_addr, password)
    #发送多人
    server.sendmail(from_addr, msg['To'].split(','), msg.as_string())
    server.quit()
Ejemplo n.º 9
0
 def login(self):
     t_path = Read().getValue('excel_path')
     result = JudgeFile().judge(t_path)
     for i in result:
         driver = WebDriverEngine()
         driver.typeAndClear('xpath', "//input[@name='account']", i[0])
         sleep(1)
         driver.typeAndClear('xpath', "//input[@name='password']", i[1])
         sleep(1)
         driver.click('xpath', "//button[@type='submit']")
         sleep(1)
         element = driver.element_is_exists('xpath',
                                            "//button[contains(.,'确认')]")
         if element:
             driver.do_screenshot()
             driver.click('xpath', "//button[contains(.,'确认')]")
Ejemplo n.º 10
0
import xlrd
from utils.ReadProperties import Read
e_path=Read().getValue('excel_path')
class excelRead(object):
       def get_data(self):
        # 找到excel文件位置
        source = xlrd.open_workbook(e_path, 'r')
        # 打开excel文件
        table = source.sheet_by_index(0)
        # 获取excel一共有几行
        rows=table.nrows
        # 输出表格的正确内容,用list保存获取的结果
        list=[]
        for i in range(rows):
            # 获取每行的值
            # result=table.row_values(i)
            # return (result)
            list.append(table.row_values(i))
        return list
Ejemplo n.º 11
0
from utils.ReadProperties import Read

t_path = Read().getValue('txt_path')


class txtRead(object):
    def get_data(self):
        source = open(t_path, 'r')
        # 读取文件
        content = source.readlines()
        # 关闭文件
        source.close()
        return content
Ejemplo n.º 12
0
from selenium import webdriver
from commom.ElementFinder import ElementFinder
import time
import logging
from selenium.webdriver.common.action_chains import ActionChains
from utils.ReadProperties import Read
from commom.BrowserStartUp import startBrowser
from commom.Log import Log
logger = Log(logger='WebDriverEngine').getLog()
u_path = Read().getValue("url")


class WebDriverEngine():
    def getAllWindowTitles(self):
        # driver = webdriver.Firefox()
        driver = startBrowser()
        #获得当前窗口的句柄
        driver.current_window_handle
        #获得所有窗口的句柄
        allhandles = driver.window_handles
        list = []
        for handle in allhandles:
            driver.switch_to.window(handle)
            list.append(handle.title())
        driver.switch_to.window(allhandles)
        return len(list)

    def enterFrame(self, frameID):  #python接受任何类型的参数,不必重载
        driver = startBrowser()
        time.sleep(3)
        driver.switch_to.window(frameID)
Ejemplo n.º 13
0
def BaseUrl():
    base_path = Read().getValue('BaseUrl')
    return base_path
Ejemplo n.º 14
0
from commom.BrowserStartUp import startBrowser
from utils.ReadProperties import Read
import time
import os
from commom.Log import Log
logger=Log(logger='ElementFinder').getLog()
u_path=Read().getValue('url')
su_path=Read().getValue("scyurl")
p_path=Read().getValue('png_path')
class ElementFinder(object):
    driver = startBrowser()

    def findElement(self, locator):
        element = ElementFinder().findElementByPrefix(locator)
        return element

    def findElementByPrefix(self, locator):
        target = locator.strip()
        if target.startswith('name='):
            target = target[len('name='):]
            return self.driver.find_element_by_name(target)
        elif target.startswith('class='):
            locator = locator[len('class='):]
            return self.driver.find_element_by_class_name(locator)
        elif target.startswith('id='):
            locator = locator[len('id='):]
            return self.driver.find_element_by_id(locator)
        elif target.startswith('link='):
            locator = locator[len('link='):]
            return self.driver.find_element_by_link_text(locator)
        elif target.startswith('css='):
Ejemplo n.º 15
0
from commom.BrowserStartUp import startBrowser
from utils.ReadProperties import Read
import time
import os
from commom.Log import Log
logger=Log(logger='ElementFinder').getLog()
u_path=Read().getValue('url')
p_path=Read().getValue('png_path')
class ElementFinder(object):
    driver = startBrowser()
    def find_element(self, type, position):
        if type == 'xpath':
            element = self.driver.find_element_by_xpath(position)
            return element
        elif type == 'id':
            element = self.driver.find_element_by_id(position)
            return element
        elif type == 'name':
            element = self.driver.find_element_by_name(position)
            return element
        elif type == 'link_text':
            element = self.driver.find_element_by_link_text(position)
            return element
        else:
            print("不支持的类型")

    # 定位多个元素方法
    def find_elements(self, type, position):
        if type == 'xpath':
            element = self.driver.find_elements_by_xpath(position)
            return element