Exemple #1
0
def common_email():
    rc = read_config.ReadConfig()
    smtpserver = rc.get_email("smtpserver")
    login_name = rc.get_email("login_name")
    login_password = rc.get_email("login_password")
    sender = rc.get_email("sender")
    receiver = rc.get_email("receiver")
    subject = rc.get_email("subject")

    msg = MIMEMultipart('mixed')
    msg['Subject'] = subject
    msg['From'] = sender
    msg['To'] = receiver

    # 构造文本
    report_result = email_text()
    text = f"{report_result}\n测试报告请见附件"
    text_plain = MIMEText(text, 'plain', 'utf-8')
    msg.attach(text_plain)

    if report_path:
        send_file = MIMEApplication(open(report_path, 'rb').read())
        send_file.add_header('Content-Disposition', 'attachment', filename="测试报告.html")
        msg.attach(send_file)
        # 发送邮件
        smtp = smtplib.SMTP()
        smtp.connect(smtpserver)
        smtp.login(login_name, login_password)
        # 收件人多个时需要用列表
        smtp.sendmail(sender, receiver.split(";"), msg.as_string())
        smtp.quit()
    else:
        mylog().info("当天测试报告未生成")
Exemple #2
0
 def __init__(self):
     rc = read_config.ReadConfig('path.ini')
     path = rc.get_db('testdata', 'path')
     sheetname = rc.get_db('testdata', 'sheetname')
     self.logger = log.Logger()
     self.book = self.open_excel(path)
     self.sheet = self.book.sheet_by_name(sheetname)
Exemple #3
0
class TestLogin(BaseTest):
    readeConfigObj = read_config.ReadConfig("\\config\\server_config.ini")
    @pytest.mark.smoketest
    def test_01_login_success(self):
        # self.login_screen.permission()
        # 执行测试脚本时,取消以下三行注释 👇
        self.login_screen.server_opera(self.readeConfigObj.get_config('server', 'server'))
        self.login_screen.input_username('admin')
        self.login_screen.input_password('123456')
        self.login_screen.click_loginbtn()
        time.sleep(1)
        self.driver.assert_equal(self.login_screen.login_success(), '主页')
class DriverConfig:
    """初始化driver"""

    readeConfigObj = read_config.ReadConfig(r"\config\server_config.ini")

    def __new__(cls, *args, **kwargs):
        """使用单例模式将类型设置为运行时只有一个实例"""
        try:
            # hasattr()函数功能用来检测对象object中是否含有名为**的属性,如果有就返回True,没有就返回False
            if not hasattr(cls, '_instance'):
                orig = super(DriverConfig, cls)
                desired_caps = {
                    'platformName':
                    cls.readeConfigObj.get_config(
                        'desired_caps', 'platformName'),  # 平台 'Android'
                    'platformVersion':
                    cls.readeConfigObj.get_config('desired_caps',
                                                  'platformVersion'),  # 系统版本
                    'appPackage':
                    cls.readeConfigObj.get_config(
                        'desired_caps', 'appPackage'),  # APK包名 'com.universal'
                    'appActivity':
                    cls.readeConfigObj.get_config(
                        'desired_caps', 'appActivity'
                    ),  # 被测程序启动时的Activity '.activity.SplashActivity'
                    'unicodeKeyboard':
                    'true',  # 使用unicodeKeyboard的编码方式来发送字符串。是否支持unicode的键盘。如果需要输入中文,要设置为“true”
                    'resetKeyboard':
                    'true',  # 是否在测试结束后将键盘重置为系统默认的输入法。
                    'newCommandTimeout':
                    '120',  # Appium服务器等待appium客户端发送新消息的时间。默认为60秒。设置的时间内无请求,则关闭客户端(退出app)
                    'deviceName':
                    cls.readeConfigObj.get_config(
                        'desired_caps', 'deviceName'),  # 手机ID '333a0a4a'
                    'noReset':
                    True,  # true:不重新安装APP,false:重新安装app.每次启动APP不清除之前的状态
                    'automationName':
                    'Uiautomator2'  # 用于获取toast
                }
                # desired_caps['app'] = '/xxxxx.apk'  #
                # 指向.apk文件,如果设置appPackage和appActivity,那么这项会被忽略

                cls._instance = orig.__new__(cls)
                cls._instance.driver = webdriver.Remote(
                    cls.readeConfigObj.get_config('driver', 'driverIp'),
                    desired_caps)
            return cls._instance
        except Exception as msg:
            raise msg
Exemple #5
0
class LoginScreen(BasePage):
    readeConfigObj = read_config.ReadConfig("\\config\\base_xpath.ini")
    # loginCenterBtn = readeConfigObj.get_config('login', 'loginCenter_btn')
    usernameText = readeConfigObj.get_config('login', 'username_text')
    passwordText = readeConfigObj.get_config('login', 'password_text')
    loginBtn = readeConfigObj.get_config('login', 'login_btn')
    loginSuccess = readeConfigObj.get_config('login', 'main_assets')
    permission_continue_btn = readeConfigObj.get_config(
        'login', 'permission_continue_btn')
    serverOpera = readeConfigObj.get_config('login', 'serverOpera')
    server_text = readeConfigObj.get_config('login', 'server_text')
    server_submit = readeConfigObj.get_config('login', 'server_submit')

    # driver = base_page.BasePage.get_driver()

    def server_opera(self, server):
        """配置服务"""
        with allure.step('配置服务地址:' + server):
            self.driver.click_element(self.serverOpera)
            self.driver.input_text(self.server_text, server)
            self.driver.click_element(self.server_submit)

    def permission(self):
        self.driver.click_element(self.permission_continue_btn)
        self.driver.click_element(self.permission_continue_btn)
        self.driver.click_element(self.permission_continue_btn)

    def input_username(self, username):
        with allure.step('使用:' + username):
            self.driver.input_text(self.usernameText, username)

    def input_password(self, password):
        self.driver.input_text(self.passwordText, password)

    def click_loginbtn(self):
        self.driver.click_element(self.loginBtn)

    # 验证是否登录成功
    def login_success(self):
        # self.driver.find_element_by_name(self.loginSuccess).text
        _text = self.driver.get_element_text(self.loginSuccess)
        return _text
class HomeScreen(BasePage):

    read_ConfigObj = read_config.ReadConfig("\\config\\base_xpath.ini")

    # 重大风险清单
    major_risk = read_ConfigObj.get_config('home', 'major_risk')
    # 风险点
    address_point = read_ConfigObj.get_config('home', 'risk_point')
    # 三违录入
    three_vio_add = read_ConfigObj.get_config('home', 'three_vio_add')
    # 三违查询
    three_vio_search = read_ConfigObj.get_config('home', 'three_vio_search')
    # 隐患录入
    risk_add = read_ConfigObj.get_config('home', 'risk_add')
    # 隐患整改
    risk_reform = read_ConfigObj.get_config('home', 'risk_reform')
    # 隐患复查
    risk_review = read_ConfigObj.get_config('home', 'risk_review')
    # 超期隐患
    risk_delay = read_ConfigObj.get_config('home', 'risk_delay')
    # 隐患数据上报
    risk_upload = read_ConfigObj.get_config('home', 'risk_upload')
    # 三违数据上报
    vio_upload = read_ConfigObj.get_config('home', 'vio_upload')
    # 同步数据
    synchronize = read_ConfigObj.get_config('home', 'synchronize')
    synchronize_submit = read_ConfigObj.get_config('home',
                                                   'synchronize_confirm')

    def sync_data(self):
        """同步数据"""
        self.driver.click_element(self.synchronize)
        self.driver.click_element(self.synchronize_submit)

    def select_module(self, loc):
        self.driver.click_element(loc)

    def get_toast(self, toast):
        """获取toast"""
        self.driver.is_toast_exist(toast)
Exemple #7
0
import requests
import hashlib
from common import read_config
from pathlib import Path
from common.log_trace import mylog

readconfig = read_config.ReadConfig()


class CommonHttp:
    def __init__(self):
        global scheme, host, port, timeout
        scheme = readconfig.get_http("scheme")
        host = readconfig.get_http("baseurl")
        port = readconfig.get_http("port")
        timeout = readconfig.get_http("timeout")

        self.data = {}
        self.headers = {}
        self.params = {}
        self.files = {}
        self.url = None

    def set_url(self, url=None):
        self.url = scheme + "://" + host + url if url else scheme + "://" + host
        return self.url

    def set_headers(self, headers):
        self.headers = headers

    def set_params(self, params):
Exemple #8
0
# -*- coding: utf-8 -*-
# @Time    : 2019/7/9/16:55
# @Author  : XY
# @File    : get_data.py


from common import project_path
from common import read_config
import re

config = read_config.ReadConfig(project_path.conf_path)


class GetData:
    '''可以用来动态的更改 删除 获取数据'''
    COOKIE = None
    token = None
    # LOAN_ID = None  # 新添加的标id初始值
    # normal_user = config.get_str('data', 'normal_user')
    # normal_pwd = config.get_str('data', 'normal_pwd')
    # normal_member_id = config.get_str('data', 'normal_member_id')


def replace(target):
    p2 = '#(.*?)#'
    while re.search(p2, target):  # 查找参数的字符就matach object , True
        m = re.search(p2, target)  # 在目标字符串里面根据正则表达式来查找,有匹配的字符串就返回对象
        key = m.group(1)  # 传参就是只返回匹配的字符串,也就是当前组的匹配字符
        print(key)
        value = getattr(GetData, key)  # 拿到我们需要去替换的值
        target = re.sub(p2, value, target, count=1)
Exemple #9
0
import os
import unittest
from common import read_config, config_email, HTMLTestRunner, log, get_project_path

log = log.logger
mail_info = read_config.ReadConfig().get_email_info()
username = mail_info['sender']
password = mail_info['password']
title = mail_info['subject']
receiver = mail_info['receiver'].split(",")
on_off = mail_info['on_off']

path = get_project_path.get_path()
report_path = os.path.join(path, "reports")

send_mail = config_email.ConfigEmail(
    username=username,
    password=password,
    receivers=receiver,
    title=title,
    content='test',
    file=os.path.join(report_path, "test_report.html")
)


class AllTest:
    def __init__(self):
        self.result_path = os.path.join(report_path, "test_report.html")
        self.case_list_file = os.path.join(path, "case_list.txt")
        self.case_file = os.path.join(path, "testCases")
        self.case_list = []