Exemple #1
0
def change_caseid(caseid1, caseid2, i):
    TABLE_NAME = "cases_copy"
    opera_db = OperationDB()
    sql = "select case_id,post_action from {} where case_id>='{}' and case_id<='{}';".format(
        TABLE_NAME, caseid1, caseid2)
    data = opera_db.search_all(sql)
    print(data)
    for item in data:
        caseid = item.get("case_id")
        num = int(re.search("\d+(?=_)", caseid).group())
        num1 = num + i
        caseid_new = re.sub(str(num), str(num1), caseid)
        post_action = item.get("post_action")
        if post_action and "case_id" in post_action and (
                post_action.split("=")[1] >= caseid1
                and post_action.split("=")[1] <= caseid2):
            num2 = int(
                re.search("\d+(?=_)",
                          post_action.split("=")[1]).group())
            num3 = num2 + i
            post_action_new = re.sub(str(num2), str(num3), post_action)
        else:
            post_action_new = post_action
        sql1 = "update {} set case_id='{}',post_action='{}' where case_id='{}';".format(
            TABLE_NAME, caseid_new, post_action_new, caseid)
        opera_db.sql_DML(sql1)
Exemple #2
0
class Count:
    def __init__(self):
        self.op_db = OperationDB()
        self.chrome_result = self.get_chrome_result()
        self.firefox_result = self.get_firefox_result()
        self.edge_result = self.get_edge_result()

    def get_chrome_result(self):
        chrome_result = self.op_db.search_all(settings.GET_CHROME_RESULT)
        res = [r[settings.CHROME_RESULT] for r in chrome_result]
        return res

    def get_firefox_result(self):
        firefox_result = self.op_db.search_all(settings.GET_FIREFOX_RESULT)
        res = [r[settings.FIREFOX_RESULT] for r in firefox_result]
        return res

    def get_edge_result(self):
        edge_result = self.op_db.search_all(settings.GET_EDGE_RESULT)
        res = [r[settings.EDGE_RESULT] for r in edge_result]
        return res

    def get_result(self):
        chrome_pass = chrome_fail = firefox_pass = firefox_fail = edge_pass = edge_fail = 0
        for i in self.chrome_result:
            if i == "pass":
                chrome_pass += 1
            elif i == "fail":
                chrome_fail += 1
        for j in self.firefox_result:
            if j == "pass":
                firefox_pass += 1
            elif j == "fail":
                firefox_fail += 1
        for k in self.edge_result:
            if k == "pass":
                edge_pass += 1
            elif k == "fail":
                edge_fail += 1
        return str(chrome_pass), str(chrome_fail), str(firefox_pass), str(
            firefox_fail), str(edge_pass), str(edge_fail)
Exemple #3
0
class Count:
    def __init__(self):
        self.op_db = OperationDB()

    def count(self):
        pass_count = fail_count = 0
        result = self.op_db.search_all(settings.GET_RESULT_SQL)
        for d in result:
            if d.get(settings.RESULT) == "pass":
                pass_count += 1
            elif d.get(settings.RESULT) == "fail":
                fail_count += 1
        return str(pass_count), str(fail_count)
Exemple #4
0
class MailReport:
    def __init__(self):
        self.op_db = OperationDB()
        self.result = self.get_result()

    def get_result(self):
        result = self.op_db.search_all(settings.RESULT_SQL)
        return result

    def count(self):
        success_count = fail_count = type_all_count = type_index_count = 0
        for res in self.result:
            if res[settings.RESULT]:
                success_count += 1
                r = json.loads(res[settings.RESULT])
                if r[settings.RESULT_TYPE] == "ALL":
                    type_all_count += 1
                elif r[settings.RESULT_TYPE] == "INDEX":
                    type_index_count += 1
            else:
                fail_count += 1
        return success_count, fail_count, type_all_count, type_index_count

    def get_type_case(self):
        type_all_cases = [
            i[settings.SQL_EXP] for i in self.result
            if json.loads(i[settings.RESULT])[settings.RESULT_TYPE] == "ALL"
        ]
        type_index_cases = [
            i[settings.SQL_EXP] for i in self.result
            if json.loads(i[settings.RESULT])[settings.RESULT_TYPE] == "INDEX"
        ]
        return type_all_cases, type_index_cases

    def send_result_mail(self, report_file=None):
        count_tuple = self.count()
        type_cases = self.get_type_case()
        count = str(int(count_tuple[0]) + int(count_tuple[1]))
        content = settings.EMAIL_CONTENT.format(
            count, count_tuple[0], count_tuple[1], count_tuple[2],
            type_cases[0], count_tuple[3], type_cases[1], report_file,
            settings.DB_TYPE, settings.DB_HOST, settings.DB_USER,
            settings.DB_PASSWD, settings.DB_NAME, settings.TABLE_NAME)
        s = SendMail()
        sub = settings.EMAIL_SUB.format(time.strftime("%Y-%m-%d %H:%M:%S"))
        s.send_mail(settings.EMAIL_RECEIVER, sub, content)
Exemple #5
0
import unittest, ddt
from util.opera_db import OperationDB
from base.send_main import SendMain
from config import settings
from BeautifulReport.BeautifulReport import BeautifulReport
import time

op_db = OperationDB()
sql = settings.TEST_CASE_SQL
data = op_db.search_all(sql)


@ddt.ddt
class RunCase(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        op_db.sql_DML(settings.CLEAR_RESULT_SQL)

    @ddt.data(*data)
    @ddt.unpack
    def test01(self, *args, **kwargs):
        self._testMethodDoc = kwargs[settings.CASE_NAME]  #用例注释
        self.is_run = kwargs[settings.IS_RUN]
        if not self.is_run:
            self.skipTest("不执行")  #忽略测试
        self.sm = SendMain(kwargs)
        self.res = self.sm.run_main()
        self.assertTrue(self.res)

    def tearDown(self):
        if self.is_run and self.res:
Exemple #6
0
    os.path.abspath(os.path.join(os.getcwd(), "..\\Lib\\site-packages")))
from base.browser_engine import BrowserEngine
import unittest
import ddt
import multiprocessing
from case.run_main import RunMain
from util.opera_db import OperationDB
import HTMLTestRunner
from page.login_page import LoginPage
from config import settings
from pic.opera_pics import OperaPics
from log.log_record import LogRecord
from BeautifulReport import BeautifulReport

op_db = OperationDB()
data = op_db.search_all(settings.TEST_CASE_SQL)


@ddt.ddt
class Test(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        #清除以前的测试结果
        op_db.sql_DML(settings.CLEAR_RESULT_SQL)
        #cls.driver = BrowserEngine(parames).start_browser()
        cls.driver = BrowserEngine("chrome").start_browser()
        #lo = LoginPage(cls.driver)
        #lo.login(**{"username":"******","password":11223

    @ddt.data(*data)
    @ddt.unpack