Ejemplo n.º 1
0
def test_report(request):
    username = request.session.get('user', '')
    apis_list = Apis.objects.all()
    apis_count = Apis.objects.all().count()  #统计接口数
    db = pymysql.connect(user=getDatabases('user'),passwd=getDatabases('passwd'),db=getDatabases('db'),port=getDatabases('port'),host=getDatabases('host'),charset=getDatabases('charset'))
    cursor = db.cursor()
    sql1 = 'SELECT count(id) FROM apitest_apis WHERE apitest_apis.apistatus=1'
    aa=cursor.execute(sql1)
    apis_pass_count = [row[0] for row in cursor.fetchmany(aa)][0]
    sql2 = 'SELECT count(id) FROM apitest_apis WHERE apitest_apis.apistatus=0'
    bb=cursor.execute(sql2)
    apis_fail_count = [row[0] for row in cursor.fetchmany(bb)][0]
    db.close()
    return render(request, "report.html", {"user": username,"apiss": apis_list,"apiscounts": apis_count,"apis_pass_counts": apis_pass_count,"apis_fail_counts": apis_fail_count}) #把值赋给apiscounts这个变量
Ejemplo n.º 2
0
def writeBug(bug_id, interface_name, request, response, res_check, Product_id,
             tester):
    interface_name = interface_name.encode('utf-8')
    res_check = res_check.encode('utf-8')
    request = request.encode('utf-8')
    response = response.encode('utf-8')
    now = time.strftime("%Y-%m-%d %H:%M:%S")
    bugname = str(bug_id) + '_' + interface_name.decode() + '_出错了'
    bugdetail = '[请求数据]\n' + request.decode(
    ) + '\n' + '[预期结果]\n' + res_check.decode(
    ) + '\n' + '[响应数据]\n' + response.decode()
    print(bugdetail)
    sql = "INSERT INTO `bug_bug` ("\
    "`bugname`,`bugdetail`,`bugstatus`,`buglevel`, `bugcreater`, `bugassign`,`created_time`,`Product_id`)  "\
    "VALUES ('%s','%s','激活','3','%s', '%s', '%s', '%d');"%(bugname,pymysql.escape_string(bugdetail),tester,tester,now,Product_id)
    coon = pymysql.connect(user=getDatabases('user'),
                           passwd=getDatabases('passwd'),
                           db=getDatabases('db'),
                           port=getDatabases('port'),
                           host=getDatabases('host'),
                           charset=getDatabases('charset'))
    cursor = coon.cursor()
    cursor.execute(sql)
    coon.commit()
    cursor.close()
    coon.close()
Ejemplo n.º 3
0
def webauto_testcase2(self):  #流程 的 相关接口
    options = Options()
    #关掉沙盒,让Chrome在root权限下跑
    options.add_argument('--no-sandbox')
    options.add_argument('--disable-dev-shm-usage')
    #不打开浏览器
    #options.add_argument('--headless')
    #指定浏览器分辨率
    #options.add_argument('window-size=1920x1680')
    #谷歌文档提到需要加上这个属性来规避bug
    #options.add_argument('--disable-gpu')s
    #不加载图片
    #options.add_argument('blink-settings=imagesEnabled=false')
    self.driver2 = webdriver.Chrome(chrome_options=options)
    self.driver2.get("http://www.baidu.com")
    sql = "SELECT id,webfindmethod,webevelement,weboptmethod,webtestdata,webassertdata,`webtestresult` from webtest_webcasestep where webtest_webcasestep.Webcase_id=2 ORDER BY id ASC "
    coon = pymysql.connect(user=getDatabases('user'),
                           passwd=getDatabases('passwd'),
                           db=getDatabases('db'),
                           port=getDatabases('port'),
                           host=getDatabases('host'),
                           charset=getDatabases('charset'))
    cursor = coon.cursor()
    aa = cursor.execute(sql)
    info = cursor.fetchmany(aa)
    for ii in info:
        case_list = []
        case_list.append(ii)
        webtestcase(self, case_list)
    coon.commit()
    cursor.close()
    coon.close()
    self.driver2.quit()
Ejemplo n.º 4
0
def appauto_testcase(self):            #app例
    desired_caps = {}
    desired_caps['platformName'] = 'Android'
    desired_caps['platformVersion'] = '4.4'
    desired_caps['deviceName'] = 'emulator-5554'
    desired_caps['appPackage'] = 'com.android.calculator2'
    desired_caps['appActivity'] = '.Calculator'
    time.sleep(1)
    self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
    time.sleep(1)
    sql="SELECT id,appfindmethod,appevelement,appoptmethod,appassertdata,`apptestresult` from apptest_appcasestep where apptest_appcasestep.Appcase_id=1 ORDER BY id ASC " 
    coon = pymysql.connect(user=getDatabases('user'),passwd=getDatabases('passwd'),db=getDatabases('db'),port=getDatabases('port'),host=getDatabases('host'),charset=getDatabases('charset'))
    cursor = coon.cursor()
    aa=cursor.execute(sql)
    info = cursor.fetchmany(aa)
    for ii in info:   
        case_list = []
        case_list.append(ii)
        apptestcase(self,case_list)
    coon.commit()
    cursor.close()
    coon.close()
    self.driver.quit()
Ejemplo n.º 5
0
def caseWriteResult(case_id, result):
    result = result.encode('utf-8')
    now = time.strftime("%Y-%m-%d %H:%M:%S")
    sql = "UPDATE apitest_apitest set apitest_apitest.apitestresult=%s,apitest_apitest.create_time=%s where apitest_apitest.id=%s;"
    param = (result, now, case_id)
    print('api autotest result is ' + result.decode())
    coon = pymysql.connect(user=getDatabases('user'),
                           passwd=getDatabases('passwd'),
                           db=getDatabases('db'),
                           port=getDatabases('port'),
                           host=getDatabases('host'),
                           charset=getDatabases('charset'))
    cursor = coon.cursor()
    cursor.execute(sql, param)
    coon.commit()
    cursor.close()
    coon.close()
Ejemplo n.º 6
0
def apitest_testcase(self):
    sql = "SELECT id,`apiname`,apiurl,apimethod,apiparamvalue,apiresult,`apistatus` from apitest_apistep where apitest_apistep.Apitest_id=2 "
    coon = pymysql.connect(user=getDatabases('user'),
                           passwd=getDatabases('passwd'),
                           db=getDatabases('db'),
                           port=getDatabases('port'),
                           host=getDatabases('host'),
                           charset=getDatabases('charset'))
    cursor = coon.cursor()
    aa = cursor.execute(sql)
    info = cursor.fetchmany(aa)
    print(info)
    for ii in info:
        case_list = []
        case_list.append(ii)
        #   CredentialId()
        interfaceTest(case_list)
    coon.commit()
    cursor.close()
    coon.close()
Ejemplo n.º 7
0
def seturl(set):
    global setvalue
    sql = "SELECT `setname`,`setvalue` from set_set"
    coon = pymysql.connect(user=getDatabases('user'),
                           passwd=getDatabases('passwd'),
                           db=getDatabases('db'),
                           port=getDatabases('port'),
                           host=getDatabases('host'),
                           charset=getDatabases('charset'))
    cursor = coon.cursor()
    aa = cursor.execute(sql)
    info = cursor.fetchmany(aa)
    print(info)
    coon.commit()
    cursor.close()
    coon.close()
    if info[0][0] == set:
        setvalue = info[0][1]
        print(setvalue)
    return setvalue
Ejemplo n.º 8
0
def apisauto_testcase():
    sql = "SELECT id,`apiname`,apiurl,apimethod,apiparamvalue,apiresult,`apistatus`,Product_id,apitester from apitest_apis "
    coon = pymysql.connect(user=getDatabases('user'),
                           passwd=getDatabases('passwd'),
                           db=getDatabases('db'),
                           port=getDatabases('port'),
                           host=getDatabases('host'),
                           charset=getDatabases('charset'))
    #    coon = pymysql.connect(user=settings.DATABASES["default"]["USER"],passwd=settings.DATABASES["default"]["PASSWORD"],db=settings.DATABASES["default"]["NAME"],port=3306,host=settings.DATABASES["default"]["HOST"],charset='utf8')
    cursor = coon.cursor()
    aa = cursor.execute(sql)
    info = cursor.fetchmany(aa)
    print(info)
    for ii in info:
        case_list = []
        case_list.append(ii)
        print(case_list)
        interfaceTest1(case_list)
    coon.commit()
    cursor.close()
    coon.close()