Example #1
0
def keyWordFunction(excelObj, caseStepSheet):
    excelObj.get_sheet_by_name(caseStepSheet)
    stepRows = excelObj.get_all_rows()
    totalStepNum = len(stepRows) - 1
    #print "totalStepNum:", totalStepNum
    successStepNum = 0
    for idx1, row1 in enumerate(stepRows[1:]):
        caseStepDescripion = row1[testStep_testStepDescribe - 1].value
        keyWord = row1[testStep_keyWords - 1].value
        locatorType = row1[testStep_locationType - 1].value
        locatorExpression = row1[testStep_locatorExpression - 1].value
        operateValue = str(
            row1[testStep_operateValue - 1].value) if isinstance(
                row1[testStep_operateValue -
                     1].value, long) else row1[testStep_operateValue - 1].value
        if (locatorType and locatorExpression):
            command = "%s('%s','%s',u'%s')" % (
                keyWord, locatorType, locatorExpression.replace("'", "\""),
                operateValue) if operateValue else "%s('%s','%s')" % (
                    keyWord, locatorType, locatorExpression.replace("'", "\""))
        elif operateValue:
            command = "%s(u'%s')" % (keyWord, operateValue)
        else:
            command = "%s()" % keyWord
        print caseStepDescripion
        #print "command:", command
        try:
            eval(command)
        except Exception, e:
            errorInfo = traceback.format_exc()
            captureScreenPath = captureScreen()
            writeResult(excelObj,
                        caseStepSheet,
                        "caseStep",
                        idx1 + 2,
                        u"fail",
                        errorInfo=errorInfo,
                        captureScreenPath=captureScreenPath)
            # excelObj.write_cell_content(idx1 + 2, testStep_testResult, u"fail", color='red')
            # excelObj.write_cell_current_time(idx1 + 2, testStep_runTime)
            # excelObj.write_cell_content(idx1 + 2, testStep_errorInfo, traceback.format_exc())
            # excelObj.write_cell_content(idx1 + 2, testStep_errorPic, captureScreen())
            # 写入错误截图需要封装函数,返回图片地址

        else:  # 没有报错
            successStepNum += 1
            writeResult(excelObj, caseStepSheet, "caseStep", idx1 + 2, u"pass")
Example #2
0
def run_test(sn, apk, testnum):
    logger(logname, sn + ": apk :" + apk + ", index :" + str(testnum))
    install_result = 'fail'
    uninstall_result = 'fail'
    launch_result = 'fail'
    apk_path = os.path.join(APK_FOLDER, apk)
    package_name, class_name = get_start_activity(apk_path)
    logger(
        logname, sn + ": run_test apk_path :" + apk_path + ", package_name :" +
        package_name + ";class_name = " + class_name)
    if Worker().installAPK(sn, apk):
        install_result = 'pass'
        time.sleep(2)

        if Worker().launchAPK(sn, class_name):
            launch_result = 'pass'
        else:
            launch_result = 'fail'
        time.sleep(90)
        os.system("adb -s %s shell input keyevent 3" % sn)
        time.sleep(2)
        if Worker().uninstallAPK(sn, package_name):
            uninstall_result = 'pass'
            time.sleep(2)
        else:
            uninstall_result = 'fail'
    else:
        install_result = 'fail'
        launch_result = 'fail'
        uninstall_result = 'fail'
    logger(logname, sn + ': result apk:' + apk)
    logger(
        logname, sn + ': result install:' + install_result + '; launch:' +
        launch_result + '; uninstall:' + uninstall_result)
    # 添加输出excel表格
    filepath = os.getcwd() + os.sep + "result_%s.txt" % (sn)
    writeResult(package_name, install_result, launch_result, uninstall_result,
                filepath)
    logger(logname,
           sn + ': ' + '>' * 20 + ' DONE %s ' % testnum + '<' * 20 + "\n" * 2)
Example #3
0
print(type(Xtr))
print(type(Ytr))
import sys
sys.exit(0)

from sklearn.ensemble import RandomForestClassifier
#from sklearn.naive_bayes import GaussianNB
#from sklearn.naive_bayes import MultinomialNB
#from sklearn.naive_bayes import ComplementNB
#from sklearn.naive_bayes import BernoulliNB
from sklearn.metrics import confusion_matrix
import numpy as np

rfc = RandomForestClassifier()
#rfc = ComplementNB()
rfc.fit(Xtr, Ytr)

print('train')
ypred_train = rfc.predict(Xtr)
util.showAcc(ypred_train, Ytr)

print('\nvalidation')
ypred_vali = rfc.predict(x_vali)
util.showAcc(ypred_vali, y_vali)


test_feature, test_cusid = util.getData('../newtest.csv', True)
predicted = rfc.predict(test_feature)

util.writeResult('../output.csv', test_cusid, predicted)
    dataDrivenSourceSheet = row[testCase_dataSourceSheetName - 1].value
    ifExecute = row[testCase_isExecute - 1].value
    #print "ifExecute",ifExecute
    if ifExecute.lower() == 'y':
        # print u"用例名称:", row[0].value
        # print u"用例描述:", row[1].value
        # print u"调用框架类型:", frameWorkType
        # print u"用例步骤sheet名:", caseStepSheet
        # print u"数据驱动的数据源sheet名:", dataDrivenSourceSheet
        # print u"是否执行:", ifExecute
        if frameWorkType == u"关键字":
            print "#####执行关键字驱动框架#####"
            result = keyWordFunction(pe, caseStepSheet)
            print "result:", result
            if result:  #此条用例执行成功
                writeResult(pe, caseSheetName, "testCase", idx + 2, u"成功")
                # global caseSheetName
                # global caseStepSheet
                # global dataDrivenSourceSheet
                #writeResult(excelObj, sheetType, rowNo, result, errorInfo=None, captureScreenPath=None):
                # pe.get_sheet_by_name(caseSheetName)  # 把默认sheet获取到测试用例sheet上
                # pe.write_cell_content(idx + 2, testCase_testResult, u"成功",color="green")  # 在结果列中写入忽略
                # pe.write_cell_current_time(idx+2,testCase_runTime)#写入执行时间
            else:
                writeResult(pe, caseSheetName, "testCase", idx + 2, u"失败")
                # pe.get_sheet_by_name(caseSheetName)  # 把默认sheet获取到测试用例sheet上
                # pe.write_cell_content(idx + 2, testCase_testResult, u"失败",color="red")  # 在结果列中写入忽略
                # pe.write_cell_current_time(idx + 2, testCase_runTime)  # 写入执行时间

        elif frameWorkType == u"数据":
            print "#####执行数据驱动框架#####"
Example #5
0
def dataDrivenFunction(excelObj,caseStepSheet,dataDrivenSourceSheet):
    print u"步骤sheet:", caseStepSheet
    print u"数据源sheet", dataDrivenSourceSheet
    excelObj.get_sheet_by_name(dataDrivenSourceSheet)
    requiredContactNum = 0
    successfullyAddedContactNum = 0
    isExecuteCol = excelObj.get_single_col(5)
    emailCol = excelObj.get_single_col(1)
    #print "isExecuteCol:", isExecuteCol
    #print "emailCol:", emailCol
    excelObj.get_sheet_by_name(caseStepSheet)
    stepRows = excelObj.get_all_rows()
    totalStepNum = len(stepRows) - 1

    #print "totalStepNum:", totalStepNum
    for idx1, cell in enumerate(isExecuteCol[1:]):
        if cell.value == 'y':
            successStepNum = 0
            requiredContactNum += 1  # 记录一次需要添加的联系人
            for row in stepRows[1:]:
                caseStepDescripion = row[testStep_testStepDescribe-1].value
                keyWord = row[testStep_keyWords-1].value
                locatorType = row[testStep_locationType-1].value
                locatorExpression = row[testStep_locatorExpression-1].value
                operateValue = str(row[testStep_operateValue-1].value) if isinstance(row[testStep_operateValue-1].value, long) else row[testStep_operateValue-1].value
                # print "caseStepDescripion:",caseStepDescripion
                # print "keyWord:",keyWord
                # print "locatorType:",locatorType
                # print "locatorExpression:",locatorExpression
                # print "operateValue:",operateValue
                if operateValue and operateValue.isalpha():
                    excelObj.get_sheet_by_name(dataDrivenSourceSheet)
                    operateValue = excelObj.get_cell_content_by_coordinate(operateValue + str(idx1 + 2))
                    # print "operateValue:",operateValue
                if (locatorType and locatorExpression):
                    command = "%s('%s','%s',u'%s')" % (
                        keyWord, locatorType, locatorExpression.replace("'", "\""),
                        operateValue) if operateValue else "%s('%s','%s')" % (
                        keyWord, locatorType, locatorExpression.replace("'", "\""))
                elif operateValue:
                    command = "%s(u'%s')" % (keyWord, operateValue)
                print caseStepDescripion
                #print "command:", command
                try:
                    if operateValue != u"否":
                        eval(command)

                except Exception, e:  # 某个步骤执行失败
                    print u"执行步骤-%s-失败" % caseStepDescripion
                else:  # 执行步骤成功
                    print u"执行步骤-%s-成功" % caseStepDescripion
                    successStepNum += 1
                    #print "successStepNum:", successStepNum

            # print "successStepNum:",successStepNum
            if totalStepNum == successStepNum:#说明一条联系人添加成功
                #写结果
                print u"添加联系人-%s-成功"%emailCol[idx1+2].value
                successfullyAddedContactNum +=1#记录一次添加一条联系人成功
                writeResult(excelObj,dataDrivenSourceSheet,"dataSheet",idx1+2,u"pass",)
                # writeResult(excelObj, sheetName, sheetType, rowNo, result, errorInfo=None, captureScreenPath=None)
                # excelObj.get_sheet_by_name(dataDrivenSourceSheet)
                # excelObj.write_cell_current_time(idx1+2,dataSource_runTime)
                # excelObj.write_cell_content(idx1+2,dataSource_result,u"pass",color='green')
            else:#说明添加联系人没成功,写fail

                print u"添加联系人-%s-失败" % emailCol[idx1 + 2].value
                writeResult(excelObj, dataDrivenSourceSheet, "dataSheet", idx1 + 2, u"fail", )
                # writeResult(excelObj, sheetName, sheetType, rowNo, result, errorInfo=None, captureScreenPath=None)
                # excelObj.get_sheet_by_name(dataDrivenSourceSheet)
                # excelObj.write_cell_current_time(idx1 + 2, dataSource_runTime)
                # excelObj.write_cell_content(idx1 + 2, dataSource_result, u"fail",color="red")
        else:  # 忽略
            writeResult(excelObj, dataDrivenSourceSheet, "dataSheet", idx1 + 2, u"忽略", )
def dataDrivenFunction(excelObj, caseStepSheet, dataDrivenSourceSheet):
    logging.info(u"步骤sheet:u'%s'" % caseStepSheet)
    logging.info(u"数据源sheet: u'%s'" % dataDrivenSourceSheet)
    excelObj.get_sheet_by_name(dataDrivenSourceSheet)
    requiredContactNum = 0
    successfullyAddedContactNum = 0
    isExecuteCol = excelObj.get_single_col(5)
    emailCol = excelObj.get_single_col(1)
    excelObj.get_sheet_by_name(caseStepSheet)
    stepRows = excelObj.get_all_rows()
    totalStepNum = len(stepRows) - 1
    #logging.info("totalStepNum: %s"%totalStepNum)
    for idx1, cell in enumerate(isExecuteCol[1:]):
        if cell.value == 'y':
            successStepNum = 0
            requiredContactNum += 1  # 记录一次需要添加的联系人
            for row in stepRows[1:]:
                caseStepDescripion = row[testStep_testStepDescribe - 1].value
                keyWord = row[testStep_keyWords - 1].value
                locatorType = row[testStep_locationType - 1].value
                locatorExpression = row[testStep_locatorExpression - 1].value
                operateValue = str(
                    row[testStep_operateValue - 1].value) if isinstance(
                        row[testStep_operateValue -
                            1].value, long) else row[testStep_operateValue -
                                                     1].value
                if operateValue and operateValue.isalpha():
                    excelObj.get_sheet_by_name(dataDrivenSourceSheet)
                    operateValue = excelObj.get_cell_content_by_coordinate(
                        operateValue + str(idx1 + 2))
                    logging.info("operateValue:u'%s'" % operateValue)
                if (locatorType and locatorExpression):
                    command = "%s('%s','%s',u'%s')" % (
                        keyWord, locatorType,
                        locatorExpression.replace("'", "\""),
                        operateValue) if operateValue else "%s('%s','%s')" % (
                            keyWord, locatorType,
                            locatorExpression.replace("'", "\""))
                elif operateValue:
                    command = "%s(u'%s')" % (keyWord, operateValue)
                logging.info(u'%s' % caseStepDescripion)
                try:
                    if operateValue != u"否":
                        eval(command)

                except Exception, e:  # 某个步骤执行失败
                    logging.info(u"执行步骤-u'%s'-失败" % caseStepDescripion)
                else:  # 执行步骤成功
                    logging.info(u"执行步骤-u'%s'-成功" % caseStepDescripion)
                    successStepNum += 1
            if totalStepNum == successStepNum:  #说明一条联系人添加成功
                #写结果
                logging.info(u"添加联系人-u'%s'-成功" % emailCol[idx1 + 2].value)
                successfullyAddedContactNum += 1  #记录一次添加一条联系人成功
                writeResult(
                    excelObj,
                    dataDrivenSourceSheet,
                    "dataSheet",
                    idx1 + 2,
                    u"pass",
                )
            else:  #说明添加联系人没成功,写fail
                logging.info(u"添加联系人-u'%s'-失败" % emailCol[idx1 + 2].value)
                writeResult(
                    excelObj,
                    dataDrivenSourceSheet,
                    "dataSheet",
                    idx1 + 2,
                    u"fail",
                )

        else:  # 忽略
            writeResult(
                excelObj,
                dataDrivenSourceSheet,
                "dataSheet",
                idx1 + 2,
                u"忽略",
            )