예제 #1
0
    def tearDown(self):
        if self.result:
            print("🐱‍👤 案例执行结果为:\n",initial_json(self.result))

        if self.testResult == "失败":
            loadProcessValue("#流程开关",realValue="流程失败")
            writeTextResult(myRow=self.myRow)
        elif self.testResult == "跳过":
            print("🎈案例",self.caseName,"在本流程中跳过...")
            global_config.set_value("TESTRESULT",self.testResult)
            writeTextResult()
예제 #2
0
    def test06_tray_up_to_positon(self):
        ''' 扫码进行托盘入仓位 '''
        # **************************** 案例公共信息初始化 ****************************
        self.caseName = (lambda: sys._getframe(1).f_code.co_name)()
        global_config.set_value("CASENAME",self.caseName)
        base_url = self.url + getInterfaceData("调用接口")

        # “仓位”字段为本案例的执行开关
        if self.terminateProcess != ("" and "拣配成功") \
                or makeJsonData("仓位",whetherToInitialize="是") == "中断":
            self.testResult = "跳过"
            return


        # 与库表中数据主键重复情况均需考虑是否用初始化
        if getInterfaceData("是否数据库初始化") == "是":
            DB().delete(tableName,deleteData)


        try:
            # **************************** 交易部分 ****************************
            header = \
                {
                "Authorization": "Bearer " + self.dict["TOKEN"],
                "Content-Type": "application/json"
            }

            params = \
                {
                    "sl": makeJsonData("仓位"),
                    "trays": [
                        makeJsonData("托盘")
                    ]
                }
            params = json.dumps(params).replace("'","\"")

            self.result = myRequest(base_url, headers=header, data=params)

            # **************************** 校验部分 ****************************
            checkTheMessage("code",varNameInExcel="code")
            checkTheMessage("msg",varNameInExcel="msg")

            # **************************** 常规部分 ****************************
            self.testResult = "成功"
        except Exception as e:
            self.testResult = "失败"
            raise e
        finally:
            # 在excel中写值脚本不可写入try/except,否则html报告中无法区别体现“失败”和“异常”
            global_config.set_value("TESTRESULT",self.testResult)
            self.terminateProcess = True
            loadProcessValue("#流程开关",realValue="库存调整成功")
            writeTextResult(myRow=self.myRow)
예제 #3
0
    def test02_get_available_boxes(self):
        ''' 查询已有箱子,筛选出实物箱子 '''
        # **************************** 案例公共信息初始化 ****************************
        self.caseName = (lambda: sys._getframe(1).f_code.co_name)()
        global_config.set_value("CASENAME",self.caseName)
        base_url = self.url + getInterfaceData("调用接口")

        # 与库表中数据主键重复情况均需考虑是否用初始化
        if getInterfaceData("是否数据库初始化") == "是":
            DB().delete(tableName,deleteData)

        try:
            # **************************** 交易部分 ****************************
            header = \
                {
                "Authorization": "Bearer " + self.dict["TOKEN"],
                "Content-Type": "application/json"
            }

            for i in range(len(self.dict["#旧箱号"])):
                boxName = self.dict["#旧箱号"][i]
                params = \
                    {
                        "limit": "10",
                        "no": boxName,
                        "page": 1,
                        "pos": {}
                    }

                params = json.dumps(params).replace("'","\"")

                self.result = myRequest(base_url, headers=header, data=params)

                # **************************** 校验部分 ****************************
                checkTheMessage("code",varNameInExcel="code")
                checkTheMessage("msg",varNameInExcel="msg")

                # **************************** 返回值部分 ****************************
                # 将非实物箱子剔除待调拨范围
                boxInfo = self.result["rst"]["data"]["items"][0]
                if boxInfo.get("physics"):
                    if boxInfo["physics"].get("package") != "纸箱":
                        self.dict["#旧箱号"].remove(boxName)

            # **************************** 常规部分 ****************************
            self.testResult = "成功"
        except Exception as e:
            self.testResult = "失败"
            raise e
        finally:
            # 在excel中写值脚本不可写入try/except,否则html报告中无法区别体现“失败”和“异常”
            global_config.set_value("TESTRESULT",self.testResult)
            writeTextResult()
예제 #4
0
    def test04_box_uptray(self):
        ''' 完成越库上架 '''
        # **************************** 案例公共信息初始化 ****************************
        self.caseName = (lambda: sys._getframe(1).f_code.co_name)()
        global_config.set_value("CASENAME",self.caseName)
        base_url = self.url + getInterfaceData("调用接口")

        if self.terminateProcess != "":
            self.testResult = "跳过"
            return


        # 与库表中数据主键重复情况均需考虑是否用初始化
        if getInterfaceData("是否数据库初始化") == "是":
            DB().delete(tableName,deleteData)


        try:
            # **************************** 交易部分 ****************************
            header = \
                {
                "Authorization": "Bearer " + self.dict["TOKEN"],
                "Content-Type": "application/json"
            }

            params = \
                {
                    "box_codes": self.dict["BOXARRAY"],
                    "sl": self.dict["SL"],
                    "tray": self.dict["TRAY"],
                    "wid": self.dict["CANGKU"]
                }
            params = json.dumps(params).replace("'","\"")

            self.result = myRequest(base_url, headers=header, data=params)

            # **************************** 校验部分 ****************************
            checkTheMessage("code",varNameInExcel="code")
            checkTheMessage("msg",varNameInExcel="msg")

            # **************************** 常规部分 ****************************
            self.testResult = "成功"
        except Exception as e:
            self.testResult = "失败"
            raise e
        finally:
            # 在excel中写值脚本不可写入try/except,否则html报告中无法区别体现“失败”和“异常”
            global_config.set_value("TESTRESULT",self.testResult)
            self.terminateProcess = True
            loadProcessValue("#流程开关",realValue="上架成功")
            writeTextResult(myRow=self.myRow)
예제 #5
0
    def test02_pick_boxes(self):
        ''' 对每个箱子分别拣配(有n个箱子,则此案例中循环n次) '''
        # **************************** 案例公共信息初始化 ****************************
        self.caseName = (lambda: sys._getframe(1).f_code.co_name)()
        global_config.set_value("CASENAME", self.caseName)
        base_url = self.url + getInterfaceData("调用接口")

        if self.terminateProcess != "":
            self.testResult = "跳过"
            return

        # 与库表中数据主键重复情况均需考虑是否用初始化
        if getInterfaceData("是否数据库初始化") == "是":
            DB().delete(tableName, deleteData)

        try:
            # **************************** 交易部分 ****************************
            header = \
                {
                "Authorization": "Bearer " + self.dict["TOKEN"],
                "Content-Type": "application/json"
            }

            for i in range(0, self.dict["BOXACCOUNT"]):
                params = \
                    {
                        "bill_code": makeJsonData("出库拣配单号"),
                        "box_code": combineJson(self.dict,"BOXARRAY",i),
                        "phase": "BoxPhase",
                        "platform": "pda",
                        "sns": []
                    }
                params = json.dumps(params).replace("'", "\"")

                self.result = myRequest(base_url, headers=header, data=params)

                # **************************** 校验部分 ****************************
                checkTheMessage("code", varNameInExcel="code")
                checkTheMessage("msg", varNameInExcel="msg")

            # **************************** 常规部分 ****************************
            self.testResult = "成功"
        except Exception as e:
            self.testResult = "失败"
            raise e
        finally:
            # 在excel中写值脚本不可写入try/except,否则html报告中无法区别体现“失败”和“异常”
            global_config.set_value("TESTRESULT", self.testResult)
            writeTextResult()
    def setUp(self):
        self.dict = global_config._global_dict                              # 全局变量字典
        self.moduleName = "报销单审批流"                                     # 当前流程名称
        global_config.set_value("MODULENAME",self.moduleName)

        self.url = Environment_Select[self.dict.get("ENVIRONMENT")]         # 环境基础地址
        self.caseName = None                                                # 被测案例的案例名

        self.myRow = global_config.get_value('TESTROW')                     # 调用数据行
        self.result = None                                                  # 当前案例响应报文
        self.testResult = None                                              # 当前案例执行状态(在最后一个案例中还作为流程执行状态)
        self.terminateProcess = makeProcessData("#流程开关")                 # 案例执行开关

        if self.terminateProcess == "":
            for (k,v) in self.dict.items():
                if k != "TESTROW" and k != "TESTLOOPTIME":
                    print("🔼 全局变量 %s 的值为: %s" %(k,v))
예제 #7
0
    def test03_get_adjust_type(self):
        ''' 获取调整类型 '''
        # **************************** 案例公共信息初始化 ****************************
        self.caseName = (lambda: sys._getframe(1).f_code.co_name)()
        global_config.set_value("CASENAME",self.caseName)
        base_url = self.url + getInterfaceData("调用接口")

        # 与库表中数据主键重复情况均需考虑是否用初始化
        if getInterfaceData("是否数据库初始化") == "是":
            DB().delete(tableName,deleteData)

        try:
            # **************************** 交易部分 ****************************
            header = \
                {
                "Authorization": "Bearer " + self.dict["TOKEN"],
                "Content-Type": "application/json"
            }

            params = \
                {
                    "enumnames": [
                        "adjust_type"
                    ]
                }

            params = json.dumps(params).replace("'","\"")

            self.result = myRequest(base_url, headers=header, data=params)

            # **************************** 校验部分 ****************************
            checkTheMessage("code",varNameInExcel="code")
            checkTheMessage("msg",varNameInExcel="msg")

            # **************************** 返回值部分 ****************************
            # 获取调整类型代码
            adjustType = self.result["rst"]["data"]["adjust_type"].get(self.dict["#调整类型"])
            loadProcessValue("#调整类型",realValue=adjustType)
            global_config.set_value("#调整类型", adjustType)


            # **************************** 常规部分 ****************************
            self.testResult = "成功"
        except Exception as e:
            self.testResult = "失败"
            raise e
        finally:
            # 在excel中写值脚本不可写入try/except,否则html报告中无法区别体现“失败”和“异常”
            global_config.set_value("TESTRESULT",self.testResult)
            writeTextResult()
예제 #8
0
    def test03_get_list_info03(self):
        ''' 查询参数信息 '''
        # **************************** 案例公共信息初始化 ****************************
        self.caseName = (lambda: sys._getframe(1).f_code.co_name)()
        global_config.set_value("CASENAME",self.caseName)
        base_url = self.url + getInterfaceData("调用接口")

        if self.terminateProcess != "":
            self.testResult = "跳过"
            return


        # 与库表中数据主键重复情况均需考虑是否用初始化
        if getInterfaceData("是否数据库初始化") == "是":
            DB().delete(tableName,deleteData)


        try:
            # **************************** 交易部分 ****************************
            header = \
                {
                "Authorization": "Bearer " + self.dict["TOKEN"],
                "Content-Type": "application/json"
            }

            params = \
                {
                    "whCode": self.dict["CANGKU"]
                }
            params = json.dumps(params).replace("'","\"")

            self.result = myRequest(base_url, headers=header, data=params)

            # **************************** 校验部分 ****************************
            checkTheMessage("code",varNameInExcel="code")
            checkTheMessage("msg",varNameInExcel="msg")

            # **************************** 返回值部分 ****************************
            global_config.set_value("SL",
                                    combineJson(self.result,"rst"))

            # **************************** 常规部分 ****************************
            self.testResult = "成功"
        except Exception as e:
            self.testResult = "失败"
            raise e
        finally:
            # 在excel中写值脚本不可写入try/except,否则html报告中无法区别体现“失败”和“异常”
            global_config.set_value("TESTRESULT",self.testResult)
            writeTextResult()
예제 #9
0
    def test02_get_box_info(self):
        ''' 根据“出库拣配单号”查询箱号 '''
        # **************************** 案例公共信息初始化 ****************************
        self.caseName = (lambda: sys._getframe(1).f_code.co_name)()
        global_config.set_value("CASENAME", self.caseName)
        base_url = self.url + getInterfaceData("调用接口")

        if self.terminateProcess != "":
            self.testResult = "跳过"
            return

        # 与库表中数据主键重复情况均需考虑是否用初始化
        if getInterfaceData("是否数据库初始化") == "是":
            DB().delete(tableName, deleteData)

        try:
            # **************************** 交易部分 ****************************
            header = \
                {
                "Authorization": "Bearer " + self.dict["TOKEN"],
                "Content-Type": "application/json"
            }

            params = \
                {
                    "code":makeJsonData("出库拣配单号")
                }

            params = json.dumps(params).replace("'", "\"")

            self.result = myRequest(base_url, headers=header, data=params)

            # **************************** 校验部分 ****************************
            checkTheMessage("code", varNameInExcel="code")
            checkTheMessage("msg", varNameInExcel="msg")

            # **************************** 返回值部分 ****************************
            # 获取拣配单下箱号信息
            boxInfo = eval(combineJson(self.result, "rst", "data", "allBoxes"))
            boxArray = []
            for i in range(len(boxInfo)):
                if boxInfo[i].get("physics"):
                    # 非实物箱子均不处理
                    if combineJson(boxInfo, i, "physics", "package") == "纸箱":
                        boxArray.append(boxInfo[i]["code"])

            global_config.set_value("箱号", boxArray)

            # 获取箱子个数
            global_config.set_value("箱子总数", len(boxInfo))

            if self.dict["箱子总数"] > len(self.dict["箱号"]):
                print("********** 有 %d 个箱子无需下架 **********" %
                      (self.dict["箱子总数"] - len(self.dict["箱号"])))
                self.dict["箱子总数"] = len(self.dict["箱号"])

            # 获取“销售放货出库(分销)”情况下各箱的物料信息
            # if self.dict["下架类型"] == "销售放货出库(分销)" \
            #         and self.dict["箱子总数"] != 0:
            if self.dict["箱子总数"] != 0:
                materialInfo = eval(
                    combineJson(self.result, "rst", "data", "materials"))
                materialArray = {}
                for i in range(0, len(materialInfo)):
                    boxName = materialInfo[i].get("code")
                    if boxName in boxArray:
                        if materialArray.get(boxName) is None:
                            materialArray[boxName] = []

                        infoToAdd = \
                            {
                                # "check": True,
                                "code": boxName,
                                "count": combineJson(materialInfo,i,"count"),
                                "key": combineJson(materialInfo,i,"key"),
                                "mid": combineJson(materialInfo,i,"mid"),
                                "name": combineJson(materialInfo,i,"name"),
                                "newbox": [],
                                "record": combineJson(materialInfo,i,"record"),
                                # "sale_record": combineJson(materialInfo,i,"sale_record"),
                                "sapid": combineJson(materialInfo,i,"sapid"),
                                "status": combineJson(materialInfo,i,"status"),
                                "sns": []
                            }
                        materialArray[boxName].append(infoToAdd)

                print(materialArray)
                global_config.set_value("MATERIALARRAY", materialArray)

            # **************************** 常规部分 ****************************
            self.testResult = "成功"
        except Exception as e:
            self.testResult = "失败"
            raise e
        finally:
            # 在excel中写值脚本不可写入try/except,否则html报告中无法区别体现“失败”和“异常”
            global_config.set_value("TESTRESULT", self.testResult)
            if self.dict["箱子总数"] != 0:
                writeTextResult()
            else:
                loadProcessValue("#流程开关", realValue="无箱子可下架")
                writeTextResult(myRow=self.myRow)
예제 #10
0
    def test01_get_list_info01(self):
        ''' 登陆壳后,根据“入库单号”查询箱号及仓库号(不填“入库单号”则跳过此案例) '''
        # **************************** 案例公共信息初始化 ****************************
        self.caseName = (lambda: sys._getframe(1).f_code.co_name)()
        global_config.set_value("CASENAME",self.caseName)
        login_url = self.url + getInterfaceData("登陆接口")
        base_url = self.url + getInterfaceData("调用接口")

        # “箱号-01”字段为本案例的执行开关
        if self.terminateProcess != "" \
                or makeJsonData("箱号-01") != "":

            # 用于获取箱号信息
            boxArray = []
            for i in range(1,30):
                varName = "箱号-0%s" %i
                varValue = makeJsonData(varName)
                if varValue != "" and varValue is not None:
                    boxArray.append(varValue)
                else:
                    break
            global_config.set_value("BOXARRAY",boxArray)
            global_config.set_value("CANGKU",makeJsonData("仓库号"))

            self.testResult = "跳过"
            return

        # 与库表中数据主键重复情况均需考虑是否用初始化
        if getInterfaceData("是否数据库初始化") == "是":
            DB().delete(tableName,deleteData)

        try:
            # **************************** 登陆部分 ****************************
            username = makeJsonData("经办登录名")
            password = makeJsonData("登陆密码")

            token = get_token(login_url,username,password)

            # **************************** 交易部分 ****************************
            header = \
                {
                "Authorization": "Bearer " + token,
                "Content-Type": "application/json"
            }

            params = \
                {
                    "code":makeJsonData("入库单号")
                }

            params = json.dumps(params).replace("'","\"")

            self.result = myRequest(base_url, headers=header, data=params)

            # **************************** 校验部分 ****************************
            checkTheMessage("code",varNameInExcel="code")
            checkTheMessage("msg",varNameInExcel="msg")

            # **************************** 返回值部分 ****************************
            # 获取“token”
            global_config.set_value("TOKEN",token)

            # 获取箱号信息
            boxInfo = eval(combineJson(self.result,"rst","data","boxes"))
            boxArray = []
            for i in range(0,len(boxInfo)):
                boxArray.append(boxInfo[i]["code"])
            global_config.set_value("BOXARRAY",boxArray)
            # 获取仓库编号
            global_config.set_value("CANGKU",
                                    combineJson(self.result,"rst","data","to"))

            # **************************** 常规部分 ****************************
            self.testResult = "成功"
        except Exception as e:
            self.testResult = "失败"
            raise e
        finally:
            # 在excel中写值脚本不可写入try/except,否则html报告中无法区别体现“失败”和“异常”
            global_config.set_value("TESTRESULT",self.testResult)
            writeTextResult()
예제 #11
0
    def test01_get_box_info(self):
        ''' 登陆相应环境壳后,根据“出库拣配单号”查询箱号 '''
        # **************************** 案例公共信息初始化 ****************************
        self.caseName = (lambda: sys._getframe(1).f_code.co_name)()
        global_config.set_value("CASENAME", self.caseName)
        login_url = self.url + getInterfaceData("登陆接口")
        base_url = self.url + getInterfaceData("调用接口")

        # 与库表中数据主键重复情况均需考虑是否用初始化
        if getInterfaceData("是否数据库初始化") == "是":
            DB().delete(tableName, deleteData)

        try:
            # **************************** 登陆部分 ****************************
            username = makeJsonData("经办登录名")
            password = makeJsonData("登陆密码")

            token = get_token(login_url, username, password)

            # **************************** 交易部分 ****************************
            header = \
                {
                "Authorization": "Bearer " + token,
                "Content-Type": "application/json"
            }

            params = \
                {
                    "code":makeJsonData("出库拣配单号")
                }

            params = json.dumps(params).replace("'", "\"")

            self.result = myRequest(base_url, headers=header, data=params)

            # **************************** 校验部分 ****************************
            checkTheMessage("code", varNameInExcel="code")
            checkTheMessage("msg", varNameInExcel="msg")

            # **************************** 返回值部分 ****************************
            # 获取“token”
            global_config.set_value("TOKEN", token)

            # 获取拣配单下箱号信息
            boxInfo = eval(combineJson(self.result, "rst", "data", "boxes"))
            boxArray = []
            for i in range(0, len(boxInfo)):
                if combineJson(boxInfo, i, "physics", "package") == "纸箱":
                    boxArray.append(boxInfo[i]["code"])
            global_config.set_value("BOXARRAY", boxArray)

            # 获取箱子个数
            global_config.set_value("BOXACCOUNT", len(boxInfo))

            # **************************** 常规部分 ****************************
            self.testResult = "成功"
        except Exception as e:
            self.testResult = "失败"
            raise e
        finally:
            # 在excel中写值脚本不可写入try/except,否则html报告中无法区别体现“失败”和“异常”
            global_config.set_value("TESTRESULT", self.testResult)
            writeTextResult()
    def test04_pick_boxes(self):
        ''' 扫描SN(若m个旧箱子中共有n种物料,则此案例请求n次) '''
        # **************************** 案例公共信息初始化 ****************************
        self.caseName = (lambda: sys._getframe(1).f_code.co_name)()
        global_config.set_value("CASENAME", self.caseName)
        base_url = self.url + getInterfaceData("调用接口")


        if self.terminateProcess != "" \
                or len(self.dict["#旧箱号"]) == 0:
            self.testResult = "跳过"
            return

        # 与库表中数据主键重复情况均需考虑是否用初始化
        if getInterfaceData("是否数据库初始化") == "是":
            DB().delete(tableName, deleteData)

        try:
            # **************************** 交易部分 ****************************
            header = \
                {
                "Authorization": "Bearer " + self.dict["TOKEN"],
                "Content-Type": "application/json"
            }

            for i in range(len(self.dict["#旧箱号"])):
                boxName = combineJson(self.dict, "#旧箱号", i)
                boxInfo = self.dict["MATERIALARRAY"].get(boxName)

                for j in range(len(boxInfo)):
                    sn = None
                    for k in range(len(boxInfo[j]["sns"])):
                        # 拼接SN
                        if sn is None:
                            sn = boxInfo[j]["sns"][k]
                        else:
                            sn = sn + u"\n" + boxInfo[j]["sns"][k]

                    params = \
                        {
                            "bill_code": makeJsonData("#出库拣配单号"),
                            "box_code": boxName,
                            "material_sn": {
                                "mid": combineJson(boxInfo,j,"mid"),
                                "sapid": combineJson(boxInfo,j,"sapid"),
                                "sn": [
                                    sn
                                ]
                            },
                            "phase": "SnPhase",
                            "platform": "pda"
                        }
                    params = json.dumps(params).replace("'", "\"")

                    self.result = myRequest(base_url,
                                            headers=header,
                                            data=params)

                    # **************************** 校验部分 ****************************
                    checkTheMessage("code", varNameInExcel="code")
                    checkTheMessage("msg", varNameInExcel="msg")

            # **************************** 常规部分 ****************************
            self.testResult = "成功"
        except Exception as e:
            self.testResult = "失败"
            raise e
        finally:
            # 在excel中写值脚本不可写入try/except,否则html报告中无法区别体现“失败”和“异常”
            global_config.set_value("TESTRESULT", self.testResult)
            writeTextResult()
    def test03_pick_boxes(self):
        ''' 登陆相同环境的PDA后,对每个箱子分别拣配(有n个箱子,则此案例中循环请求n次),拣配后查询各箱子的“status”,若为2则为整箱,跳过扫sn '''
        # **************************** 案例公共信息初始化 ****************************
        self.caseName = (lambda: sys._getframe(1).f_code.co_name)()
        global_config.set_value("CASENAME", self.caseName)
        login_url = self.url + getInterfaceData("登陆接口")
        base_url = self.url + getInterfaceData("调用接口")

        if self.terminateProcess != "":
            self.testResult = "跳过"
            return

        # 与库表中数据主键重复情况均需考虑是否用初始化
        if getInterfaceData("是否数据库初始化") == "是":
            DB().delete(tableName, deleteData)

        try:
            # **************************** 登陆部分 ****************************
            username = makeJsonData("经办登录名")
            password = makeJsonData("登陆密码")

            time.sleep(1)
            token = get_token(login_url, username, password)

            # **************************** 交易部分 ****************************
            header = \
                {
                "Authorization": "Bearer " + token,
                "Content-Type": "application/json"
            }

            boxNum = deepcopy(len(self.dict["#旧箱号"]))
            boxes = deepcopy(self.dict["#旧箱号"])

            for i in range(boxNum):
                boxName = boxes[i]
                print("📦 第 %d 次扫描箱子,箱号为:%s" % (i + 1, boxName))
                params = \
                    {
                        "bill_code": makeJsonData("#出库拣配单号"),
                        "box_code": boxName,
                        "phase": "BoxPhase",
                        "platform": "pda",
                        "sns": []
                    }
                params = json.dumps(params).replace("'", "\"")

                self.result = myRequest(base_url, headers=header, data=params)

                # **************************** 校验部分 ****************************
                checkTheMessage("code", varNameInExcel="code")
                checkTheMessage("msg", varNameInExcel="msg")

                # **************************** 返回值部分 ****************************
                materialsInfo = self.result["rst"]["data"].get("materials")
                boxInfo = eval(
                    combineJson(self.result, "rst", "data", "bill",
                                "allBoxes"))

                if "materialsArray" not in locals().keys():
                    materialsArray = {}

                for j in range(len(boxInfo)):
                    if boxInfo[j].get("NO") == boxName:
                        if boxInfo[j]["status"] == 2:
                            self.dict["#旧箱号"].remove(boxName)
                            global_config.set_value("#旧箱号", self.dict["#旧箱号"])
                            self.dict["#新箱号"].append(boxName)
                            global_config.set_value("#新箱号", self.dict["#新箱号"])
                        elif boxInfo[j]["status"] == 0:
                            for k in range(len(materialsInfo)):
                                if materialsInfo[k].get("ms"):
                                    newMaterial = materialsInfo[k]["ms"][0]
                                else:
                                    newMaterial = materialsInfo[k]
                                if newMaterial.get("code") == boxName:
                                    if materialsArray.get(boxName) is None:
                                        materialsArray[boxName] = []
                                    materialsArray[boxName].append(newMaterial)

            global_config.set_value("MATERIALARRAY", materialsArray)

            # 获取“token”
            global_config.set_value("TOKEN", token)

            # **************************** 常规部分 ****************************
            self.testResult = "成功"
        except Exception as e:
            self.testResult = "失败"
            raise e
        finally:
            # 在excel中写值脚本不可写入try/except,否则html报告中无法区别体现“失败”和“异常”
            global_config.set_value("TESTRESULT", self.testResult)
            writeTextResult()
예제 #14
0
 def setGlobalVar(self, varName, varValue):
     '''设置全工程全局变量键值
     :param varName:全局变量键名
     '''
     global_config.set_value(varName, varValue)
    def test03_checkpoint(self):
        ''' 遍历查询所有报销单数据有效性 '''
        # **************************** 案例公共信息初始化 ****************************
        self.caseName = (lambda: sys._getframe(1).f_code.co_name)()
        global_config.set_value("CASENAME",self.caseName)
        login_url = self.url + getInterfaceData("登陆接口")
        base_url = self.url + getInterfaceData("调用接口")

        if self.terminateProcess != "":
            self.testResult = "跳过"
            return


        # 与库表中数据主键重复情况均需考虑是否用初始化
        if getInterfaceData("是否数据库初始化") == "是":
            DB().delete(tableName,deleteData)

        try:
            # **************************** 登陆部分 ****************************
            username = makeJsonData("经办登录名")
            password = makeJsonData("登陆密码")

            token = get_token(login_url,username,password, errInfo=False)
            time.sleep(1)

            # **************************** 交易部分 ****************************
            header = \
                {
                "Authorization": "Bearer " + token,
                "Content-Type": "application/json"
            }


            md = self.dict["费用类型组合项"]
            result = []

            for i in range(len(md)):
                params = {
                        "approval_status": "1",
                        "certcode": "",
                        "code": md[i].get("报销单号"),
                        "costtype": "",
                        "finenddate": "",
                        "finfromdate": "",
                        "invoicetypestr": "",
                        "limit": "10",
                        "page": 1,
                        "profit_center": "",
                        "status": "valid",
                        "usercode": "",
                        "username": ""
                    }

                params = json.dumps(params).replace("'","\"")
                self.result = myRequest(base_url, headers=header, data=params)

                # **************************** 校验部分 ****************************
                if self.result.get("code") == 200 \
                        and self.result["rst"]["data"]["total"] > 0:
                    print("📈 第 ",i + 1," 条流程报销单新建成功")
                    md[i]["flag"] = "success"
                else:
                    print("📈 第 ",i + 1," 条流程报销单新建后查询失败,请手工校验!结果为:\n",self.result, "\n")
                    md[i]["flag"] = "fail"

                r = {}
                r["报销单号"] = md[i].get("报销单号")
                r["单据状态"] = md[i]["flag"]
                r["费用种类"] = md[i]["text1"]
                r["费用种类详情"] = md[i]["text2"]
                r["票据类型"] = md[i]["invoicetypestr"]
                r["报销金额"] = md[i].get("报销金额")
                result.append(r)

            print("📈 最终新建结果为:\n", result)

            # **************************** 常规部分 ****************************
            self.testResult = "成功"
        except Exception as e:
            self.testResult = "失败"
            raise e
        finally:
            # 在excel中写值脚本不可写入try/except,否则html报告中无法区别体现“失败”和“异常”
            global_config.set_value("TESTRESULT",self.testResult)
            self.terminateProcess = True
            loadProcessValue("#流程开关",realValue="流程结束")
            loadProcessValue("#单据数据",realValue=str(result))
            writeTextResult(myRow=self.myRow)
    def test02_get_limitperiod_and_createprocess(self):
        ''' (如有)查询该费用种类下额度信息,并创建审批流(此案例采取查询一条创建一条的方式) '''
        import datetime
        # **************************** 案例公共信息初始化 ****************************
        self.caseName = (lambda: sys._getframe(1).f_code.co_name)()
        global_config.set_value("CASENAME",self.caseName)
        login_url = self.url + getInterfaceData("登陆接口")
        base_url = getInterfaceData("调用接口").split("|")

        if self.terminateProcess != "":
            self.testResult = "跳过"
            return


        # 与库表中数据主键重复情况均需考虑是否用初始化
        if getInterfaceData("是否数据库初始化") == "是":
            DB().delete(tableName,deleteData)

        try:
            md = self.dict["费用类型组合项"]

            for i in range(len(md)):
                # **************************** 登陆部分 ****************************
                username = makeJsonData("经办登录名")
                password = makeJsonData("登陆密码")

                token = get_token(login_url, username, password, errInfo=False)
                time.sleep(1)

                header = \
                    {
                    "Authorization": "Bearer " + token,
                    "Content-Type": "application/json"
                }

                # ***** 查询额度信息 *****
                params = {
                        "amount": (10 + i),
                        "category": md[i]["category"],
                        "costtype": md[i]["costtype"],
                        "enddate": "2019-03",
                        "fromdate": "2019-03",
                        "hasfysqd": "0"
                    }

                params = json.dumps(params).replace("'","\"")
                self.result = myRequest(self.url + base_url[0],
                                        headers=header, data=params)

                # **************************** 校验部分 ****************************
                if self.result.get("code") == 200:
                    print("📈 第 ",i + 1," 条流程中“额度查询”响应成功")
                    md[i]["limit"] = self.result["rst"]["data"]["items"]
                else:
                    print("📈 第 ",i + 1," 条流程中“额度查询”响应失败,结果为:\n",self.result, "\n")
                    md[i]["flag"] = "fail"
                    continue



                # ***** 创建审批流 *****
                # **************************** 登陆部分(获取token放入原有) ****************************
                # header = \
                #     {
                #     "Authorization": "Bearer " + token,
                #     "Content-Type": "application/json",
                #     "cookie": "connect.sid=s%3A3YnGCJfqNt_oOj5s-YkGzL92etUSMwCH.4E1iphzTMXlihUbKyeft2yEDBA1T4XRUxU1%2BwtwPoQM"
                #     # "cookie": "connect.sid=s%3A8f76wCFMPoBLO2BtlGEZD71vioO9HsXy.Bb6vYQ7YpzLLpp0RWQbKy0BjIufZyiqHn8f9D0Vkrcc"
                # }


                # cookie = login_cookie(login_url, username, password)
                # time.sleep(1)
                # for item in cookie:
                #     if item.name == "connect.sid":
                #         cookieStr = "connect.sid=" + item.value
                # header["cookie"] = cookieStr


                # 此方法获取cookie不可用
                # cookie = get_cookie(login_url, username, password)
                # header["cookie"] = "connect.sid=" + cookie["connect.sid"]

                params = {
                        "doc": {
                            "model": {
                                "amount": str(10 + i),
                                "applydate": str(datetime.date.today()),
                                "corp": "1000",
                                "cost": {
                                    "accomcost": 0,
                                    "amount": str(10 + i),
                                    "attanum": "3",
                                    "category": md[i]["category"],
                                    "citytranscost": 0,
                                    "costtype": md[i]["costtype"],
                                    "enddate": "2019-03",
                                    "fromdate": "2019-03",
                                    "haszzs": "否",
                                    "invoicetype": md[i]["invoicetype"],
                                    "invoicetypestr": md[i]["invoicetypestr"],
                                    "jtjehz": 0,
                                    "othercost": 0,
                                    "tax": "",
                                    "tripcost": [
                                    ],
                                    "typestr": md[i]["text1"] + "-" + md[i]["text2"]
                                },
                                "department": {
                                    "_id": "5742a607779ec2cb7405180c",
                                    "name": "软件及应用事业部"
                                },
                                "division": "4000",
                                "extra": {
                                    "note": "自动化"
                                },
                                "finance": {
                                    "costcenter": "9100A21999",
                                    "costcenterstr": "软件事业部公共成本中心",
                                    "due": str(10 + i),
                                    "loan": 0,
                                    "returnmoney": "0"
                                },
                                "fysqd": [
                                ],
                                "hasfysqd": "0",
                                "isintegration": "0",
                                "jcfwxm": {
                                },
                                "limit": md[i]["limit"],
                                "profit_center": "8100A29001",
                                "user": {
                                    "_id": "5742a607779ec2cb74051a5d",
                                    "code": "00001853",
                                    "costype": "9100A21999",
                                    "login": "******",
                                    "name": "王乔晨"
                                }
                            }
                        }
                    }

                params = json.dumps(params).replace("'","\"")
                self.result = myRequest(self.url + base_url[1],
                                        headers=header, data=params)
                # self.result = requestWithCookie(self.url + base_url[1],
                #                         headers=header, data=params, cookies=cookie)

                # **************************** 校验部分 ****************************
                if self.result.get("code") == 200:
                    print("📈 第 ",i + 1," 条流程中“创建审批流”响应成功")
                    md[i]["nodeId"] = self.result["rst"]["nodeId"]
                    md[i]["processId"] = self.result["rst"]["processId"]
                    md[i]["报销金额"] = (10 + i)
                else:
                    print("📈 第 ",i + 1," 条流程中“创建审批流”响应失败,结果为:\n",self.result, "\n")
                    md[i]["flag"] = "fail"
                    continue


                # ***** 查询审批流信息 *****
                # del header["cookie"]

                params = {
                        "nodeId": md[i]["nodeId"],
                        "processId": md[i]["processId"]
                    }

                params = json.dumps(params).replace("'","\"")
                self.result = myRequest(self.url + base_url[2],
                                        headers=header, data=params)

                # **************************** 校验部分 ****************************
                if self.result.get("code") == 200:
                    print("📈 第 ",i + 1," 条流程中“查询审批流信息”响应成功")
                    md[i]["processlog"] = self.result["rst"]["processlog"]
                    md[i]["candidates"] = self.result["rst"]["candidates"]
                    md[i]["doc"] = self.result["rst"]["doc"]
                    md[i]["报销单号"] = self.result["rst"]["doc"]["model"]["code"]
                else:
                    print("📈 第 ",i + 1," 条流程中“查询审批流信息”响应失败,结果为:\n",self.result, "\n")
                    md[i]["flag"] = "fail"
                    continue


                # 费用类型为“固定费用”或“间接费用”,且额度充足时,自动审批
                # if md[i]["text1"] == "固定报销" \
                #     or md[i]["text1"] == "间接运营费用":
                if md[i]["text1"] == "固定报销":
                    continue


                # ***** 审批流 *****
                for j in range(len(md[i]["processlog"]) - 1):
                    # **************************** 登陆部分 ****************************
                    username = md[i]["candidates"][0]["receivers"][0]["login"]
                    token = get_token(login_url, username, password, errInfo=False)
                    time.sleep(1)

                    header = \
                        {
                        "Authorization": "Bearer " + token,
                        "Content-Type": "application/json"
                    }

                    # ***** (审批前)查询审批流信息 *****
                    # if j > 0:
                    params = {
                        "nodeId": md[i]["processlog"][j + 1]["nodeid"],
                        "processId": md[i]["processId"]
                    }

                    params = json.dumps(params).replace("'", "\"")
                    self.result = myRequest(self.url + base_url[2],
                                            headers=header, data=params)

                    # **************************** 校验部分 ****************************
                    if self.result.get("code") == 200:
                        print("📈 第 ", i + 1, " 条流程中第 ", j + 1, " 次“(审批前)查询审批流信息”响应成功")
                        md[i]["processlog"] = self.result["rst"]["processlog"]
                        md[i]["candidates"] = self.result["rst"]["candidates"]
                        md[i]["doc"] = self.result["rst"]["doc"]
                    else:
                        print("📈 第 ", i + 1, " 条流程中第 ", j + 1,
                              " 次“(审批前)查询审批流信息”响应失败,结果为:\n", self.result, "\n")
                        md[i]["flag"] = "fail"
                        break


                    # ***** (开始审批后)审批 *****
                    if len(md[i]["processlog"]) == j + 2:
                        # 最后一岗
                        candidates = []
                    else:
                        # 中间岗
                        candidates = md[i]["candidates"]
                    params = \
                        {
                            "candidates": candidates,
                            "doc": md[i]["doc"],
                            "nodeId": md[i]["processlog"][j + 1]["nodeid"],
                            "processId": md[i]["processId"]
                        }

                    params = json.dumps(params).replace("'","\"")
                    self.result = myRequest(self.url + base_url[3],
                                            headers=header, data=params)

                    # **************************** 校验部分 ****************************
                    if self.result.get("code") == 200:
                        print("📈 第 ",i + 1," 条流程中第 ", j + 1, " 次“查询审批流信息”响应成功")
                    else:
                        print("📈 第 ",i + 1," 条流程中第 ", j + 1, " 次“查询审批流信息”响应失败,结果为:\n",self.result, "\n")
                        md[i]["flag"] = "fail"
                        break


                    # ***** (审批后)查询审批流信息,用于获取下一岗nodeid *****
                    if len(md[i]["processlog"]) > j + 2:
                        params = {
                            "nodeId": md[i]["processlog"][j + 1]["nodeid"],
                            "processId": md[i]["processId"]
                        }

                        params = json.dumps(params).replace("'", "\"")
                        self.result = myRequest(self.url + base_url[2],
                                                headers=header, data=params)

                        # **************************** 校验部分 ****************************
                        if self.result.get("code") == 200:
                            print("📈 第 ", i + 1, " 条流程中第 ", j + 1, " 次“(审批后)查询审批流信息”响应成功")
                            md[i]["processlog"] = self.result["rst"]["processlog"]
                        else:
                            print("📈 第 ", i + 1, " 条流程中第 ", j + 1, " 次“(审批后)查询审批流信息”响应失败,结果为:\n", self.result, "\n")
                            md[i]["flag"] = "fail"
                            break

            self.testResult = "成功"
        except Exception as e:
            self.testResult = "失败"
            raise e
        finally:
            # 在excel中写值脚本不可写入try/except,否则html报告中无法区别体现“失败”和“异常”
            global_config.set_value("TESTRESULT",self.testResult)
            writeTextResult()
예제 #17
0
def box_uptray(login_url, base_url, multiRow, token):
    '''箱子上托盘主流程
    :param loopTime: 并发数量
    :param login_url: 登陆接口地址
    :param base_url: 上架接口地址
    :return:
    '''
    # **************************** 登陆部分 ****************************
    # username = makeProcessData("经办登录名",multiRow=multiRow)
    # password = makeProcessData("登陆密码",multiRow=multiRow)
    #
    # token = get_token(login_url,username,password)

    # **************************** 交易部分 ****************************
    header = \
        {
        "Authorization": "Bearer " + token,
        "Content-Type": "application/json"
    }

    params = \
        {
            "box_codes": [],
            "tray": makeProcessData("托盘",multiRow=multiRow)
        }

    # 用于迭代添加多个箱号数据
    for i in range(1, 100):
        if i < 10:
            varNum = "0%s" % i
        else:
            varNum = str(i)

        varName = "箱号-%s" % varNum
        varValue = makeProcessData(varName, multiRow=multiRow)

        if varValue != "" and varValue is not None \
                and varValue != "":
            params["box_codes"].append(varValue)
        else:
            break

    params = json.dumps(params).replace("'", "\"")
    result = myRequest(base_url, headers=header, data=params)

    # **************************** 校验部分 ****************************
    initRow = global_config.get_value("TESTROW")
    global_config.set_value("TESTROW", multiRow)

    # if result.get("code") == 200 and result.get("msg") == "OK":
    #     loadProcessValue("#流程开关",realValue="上架成功")
    # else:
    #     # 交易失败,在该数据行“#流程开关”中写入报错信息
    #     if result:
    #         loadProcessValue("#流程开关",realValue="报错:"+result.get("msg"))
    #     else:
    #         loadProcessValue("#流程开关",realValue="报错:系统未响应!")
    # initRow = global_config.get_value("TESTROW")
    # global_config.set_value("TESTROW",multiRow)

    if result.get("code") != 200 or result.get("msg") != "OK":
        # 交易失败,在该数据行“#流程开关”中写入报错信息
        if result:
            loadProcessValue("#流程开关", realValue="报错:" + result.get("msg"))
        else:
            loadProcessValue("#流程开关", realValue="报错:系统未响应!")
    else:
        loadProcessValue("#流程开关", realValue="上架成功")

    global_config.set_value("TESTROW", initRow)
    time.sleep(1)
예제 #18
0
    def test01_box_uptray(self):
        ''' 登陆500环境PDA后,扫码进行箱子上托盘 '''
        # **************************** 案例公共信息初始化 ****************************
        self.caseName = (lambda: sys._getframe(1).f_code.co_name)()
        global_config.set_value("CASENAME",self.caseName)
        login_url = self.url + getInterfaceData("登陆接口")
        base_url = self.url + getInterfaceData("调用接口")

        # 与库表中数据主键重复情况均需考虑是否用初始化
        if getInterfaceData("是否数据库初始化") == "是":
            DB().delete(tableName,deleteData)

        try:
            # **************************** 登陆部分 ****************************
            username = makeJsonData("经办登录名")
            password = makeJsonData("登陆密码")

            token = get_token(login_url,username,password)

            # **************************** 交易部分 ****************************
            header = \
                {
                "Authorization": "Bearer " + token,
                "Content-Type": "application/json"
            }

            params = \
                {
                    "box_codes": [
                        makeJsonData("箱号-01")
                    ],
                    "tray": makeJsonData("托盘")
                }

            # 用于迭代添加多个箱号数据
            for i in range(2,30):
                varName = "箱号-0%s" %i
                varValue = makeJsonData(varName)
                if varValue != "" and varValue is not None:
                    params["box_codes"].append(varValue)
                else:
                    break

            params = json.dumps(params).replace("'","\"")

            self.result = myRequest(base_url, headers=header, data=params)

            # **************************** 校验部分 ****************************
            checkTheMessage("code",varNameInExcel="code")
            checkTheMessage("msg",varNameInExcel="msg")

            # **************************** 返回值部分 ****************************
            # 获取“token”
            global_config.set_value("TOKEN",token)

            # **************************** 常规部分 ****************************
            self.testResult = "成功"
        except Exception as e:
            self.testResult = "失败"
            raise e
        finally:
            # 在excel中写值脚本不可写入try/except,否则html报告中无法区别体现“失败”和“异常”
            global_config.set_value("TESTRESULT",self.testResult)
            writeTextResult()
예제 #19
0
    def test05_pick_boxes(self):
        ''' 扫描SN(有n个箱子,则此案例中循环请求n次) '''
        import time
        # **************************** 案例公共信息初始化 ****************************
        self.caseName = (lambda: sys._getframe(1).f_code.co_name)()
        global_config.set_value("CASENAME",self.caseName)
        base_url = self.url + getInterfaceData("调用接口")


        if self.terminateProcess != "" \
                or self.dict["箱子总数"] == 0:
            self.testResult = "跳过"
            return

        # 与库表中数据主键重复情况均需考虑是否用初始化
        if getInterfaceData("是否数据库初始化") == "是":
            DB().delete(tableName,deleteData)


        try:
            # **************************** 交易部分 ****************************
            header = \
                {
                "Authorization": "Bearer " + self.dict["TOKEN"],
                "Content-Type": "application/json"
            }

            for i in range(self.dict["箱子总数"]):
                boxName = combineJson(self.dict,"箱号",i)

                params = \
                    {
                        "bill_code": makeJsonData("出库拣配单号"),
                        "box_code": boxName,
                        "material_sns": self.dict["MATERIALARRAY"][boxName],
                        "phase": "SubmitPhase",
                        "platform": "pda"
                    }
                params = json.dumps(params).replace("'","\"")
                # print(params)

                self.result = myRequest(base_url, headers=header, data=params)

                # **************************** 校验部分 ****************************
                checkTheMessage("code",varNameInExcel="code")
                checkTheMessage("msg",varNameInExcel="msg")

            # **************************** 返回值部分 ****************************
            endPickTime = time.time()
            # 保存结束拣配时间
            print("结束拣配时间:", endPickTime)
            global_config.set_value("结束拣配时间", endPickTime)

            t = (endPickTime - self.dict["开始拣配时间"])/self.dict["SUM"]
            print("单箱平均拣配耗时:", t, "s")
            global_config.set_value("单箱平均拣配耗时", t)

            # **************************** 常规部分 ****************************
            self.testResult = "成功"
        except Exception as e:
            self.testResult = "失败"
            raise e
        finally:
            # 在excel中写值脚本不可写入try/except,否则html报告中无法区别体现“失败”和“异常”
            global_config.set_value("TESTRESULT",self.testResult)
            writeTextResult()
예제 #20
0
    def test02_get_box_info(self):
        ''' 根据“出库拣配单号”查询可下架的箱子信息 '''
        # **************************** 案例公共信息初始化 ****************************
        self.caseName = (lambda: sys._getframe(1).f_code.co_name)()
        global_config.set_value("CASENAME",self.caseName)
        base_url = self.url + getInterfaceData("调用接口")

        if self.terminateProcess != "":
            self.testResult = "跳过"
            return

        # 与库表中数据主键重复情况均需考虑是否用初始化
        if getInterfaceData("是否数据库初始化") == "是":
            DB().delete(tableName,deleteData)

        try:
            # **************************** 交易部分 ****************************
            header = \
                {
                "Authorization": "Bearer " + self.dict["TOKEN"],
                "Content-Type": "application/json"
            }

            params = \
                {
                    "code":makeJsonData("出库拣配单号")
                }

            params = json.dumps(params).replace("'","\"")

            t0 = time.time()
            self.result = myRequest(base_url, headers=header, data=params)
            t1 = time.time()
            print("⏰ 查询接口响应时间:", t1 - t0, "s")

            # **************************** 校验部分 ****************************
            checkTheMessage("code",varNameInExcel="code")
            checkTheMessage("msg",varNameInExcel="msg")

            # **************************** 返回值部分 ****************************

            # 获取拣配单下箱号信息
            boxInfo = eval(combineJson(self.result,"rst","data","allBoxes"))
            boxArray = []

            t2 = time.time()
            for i in range(len(boxInfo)):               # 正序
            # for i in range(len(boxInfo)-1, -1, -1):     # 倒序
                if boxInfo[i].get("physics"):
                    # 非实物箱子均不处理

                    # if (combineJson(boxInfo,i,"physics","package") == "纸箱"
                    #     or combineJson(boxInfo,i,"physics","package") == "胶合板托盘"
                    #     or combineJson(boxInfo,i,"physics","package") == "金属托盘") \
                    #         and boxInfo[i].get("code") not in boxArray:

                    # if combineJson(boxInfo,i,"physics","package") != "" \
                    if boxInfo[i].get("code") not in boxArray \
                            and boxInfo[i].get("status") != 2:
                        boxArray.append(boxInfo[i]["code"])
                        # print(boxArray)

            t3 = time.time()
            print("⏰ 遍历箱子信息时间:", t3 - t2, "s")
            global_config.set_value("t3", t3)

            global_config.set_value("箱号", boxArray)
            # 写入箱号/响应报文到临时文件,便于自动化/手工协同操作
            file = open(r"C:\Users\47612\Desktop\boxNum.txt", "w", encoding="utf-8")
            file.write(str(boxArray))
            file.close()

            # file = open(r"C:\Users\47612\Desktop\result.txt", "w", encoding="utf-8")
            # file.write(str(self.result))
            # file.close()

            # 获取箱子个数
            global_config.set_value("箱子总数",len(boxInfo))
            global_config.set_value("SUM",len(boxInfo))

            if self.dict["箱子总数"] > len(self.dict["箱号"]):
                print("********** 有 %d 个箱子无需下架 **********" %(self.dict["箱子总数"] - len(self.dict["箱号"])))
                self.dict["箱子总数"] = len(self.dict["箱号"])

            self.testResult = "成功"
        except Exception as e:
            self.testResult = "失败"
            raise e
        finally:
            # 在excel中写值脚本不可写入try/except,否则html报告中无法区别体现“失败”和“异常”
            global_config.set_value("TESTRESULT",self.testResult)
            if self.dict["箱子总数"] != 0:
                writeTextResult()
            else:
                loadProcessValue("#流程开关",realValue="无箱子可下架")
                writeTextResult(myRow=self.myRow)
    def test01_box_uptray(self):
        ''' 登陆500环境PDA后,扫码进行箱子上托盘 '''
        # **************************** 案例公共信息初始化 ****************************
        self.caseName = (lambda: sys._getframe(1).f_code.co_name)()
        global_config.set_value("CASENAME", self.caseName)
        login_url = self.url + getInterfaceData("登陆接口")
        base_url = self.url + getInterfaceData("调用接口")

        # 与库表中数据主键重复情况均需考虑是否用初始化
        if getInterfaceData("是否数据库初始化") == "是":
            DB().delete(tableName, deleteData)

        try:
            # 确定并发流程数
            multiAccount = eval(makeJsonData("并发流程数"))
            token = get_token(login_url, makeJsonData("经办登录名"),
                              makeJsonData("登陆密码"))
            errAccount = 0
            start = time.time()
            one_work_num = 1
            # pool = multiprocessing.Pool(4)
            pool = threadpool.ThreadPool(10)

            for i in range(multiAccount):
                multiRow = global_config.get_value("TESTROW") + i
                # myProcess = threading.Thread(target=box_uptray,args=(login_url,base_url,multiRow,token))

                requests = threadpool.makeRequests(
                    box_uptray(login_url, base_url, multiRow, token),
                    (login_url, base_url, multiRow, token))
                [pool.putRequest(req) for req in requests]
                pool.wait()

            #     pool.apply_async(box_uptray(login_url,base_url,multiRow,token))
            # pool.close()
            # pool.join()

            # coroutine = run_more(login_url,base_url,token)
            # tasks = [
            #     asyncio.ensure_future(coroutine),
            # ]
            # loop2 = asyncio.get_event_loop()
            # loop2.run_until_complete(asyncio.wait(tasks))

            # 主线程中等待所有子线程退出
            end = time.time()

            for i in range(multiAccount):
                multiRow = global_config.get_value("TESTROW") + i
                if makeProcessData("#流程开关",
                                   multiRow=multiRow).find("报错") != -1:
                    errAccount += 1
                print("第 %d 次进程中累计报错数为: %d" % (i + 1, errAccount))

            print(
                "========================================================================"
            )
            print("接口性能测试开始时间:", time.asctime(time.localtime(start)))
            print("接口性能测试结束时间:", time.asctime(time.localtime(end)))
            print("接口地址:", base_url)
            print("接口类型:", "post")
            print("线程数:", multiAccount)
            print("每个线程循环次数:", 1)
            print("每次请求时间间隔:", 0)
            print("总请求数:", multiAccount * one_work_num)
            # print("错误请求数:", len(error))
            print("总耗时(秒):", end - start)
            print("每次请求耗时(秒):", (end - start) / (multiAccount * one_work_num))
            print("每秒承载请求数(TPS):",
                  (multiAccount * one_work_num) / (end - start))
            print("平均响应时间(毫秒):", CT.thread_response_avg())
            print(
                "========================================================================"
            )

            # **************************** 常规部分 ****************************
            assert errAccount == 0, \
                "😭 箱子入托盘中,\n共需处理 '%s' 个流程, 有 '%d' 个失败!" \
                %(multiAccount,errAccount)
            print("😭 箱子入托盘中,\n共需处理 '%s' 个流程, 有 '%d' 个失败!" \
                %(multiAccount,errAccount))
        except AssertionError as e:
            self.testResult = "失败"
            raise AssertionError(e)
        except Exception as e:
            self.testResult = "失败"
            raise e
        finally:
            if errAccount == 0:
                self.testResult = "成功"

            # 在excel中写值脚本不可写入try/except,否则html报告中无法区别体现“失败”和“异常”
            global_config.set_value("TESTRESULT", self.testResult)
            self.terminateProcess = True
            writeTextResult(myRow=self.myRow)
    def test01_get_KJPZH(self):
        ''' 获取报销单详情,进行财务标记,获取会计凭证号 '''
        import datetime

        if self.terminateProcess != "":
            self.testResult = "跳过"
            return

        # **************************** 案例公共信息初始化 ****************************
        self.caseName = (lambda: sys._getframe(1).f_code.co_name)()
        global_config.set_value("CASENAME", self.caseName)
        login_url = self.url + getInterfaceData("登陆接口")
        base_url = getInterfaceData("调用接口").split("|")

        # 与库表中数据主键重复情况均需考虑是否用初始化
        if getInterfaceData("是否数据库初始化") == "是":
            DB().delete(tableName, deleteData)

        md = [{
            "单据状态": "success",
            "报销单号": "BXA201903003120",
            "报销金额": 10,
            "票据类型": "资料费",
            "费用种类": "间接运营费用",
            "费用种类详情": "管理费用"
        }, {
            "单据状态": "success",
            "报销单号": "BXA201903001008",
            "报销金额": 15,
            "票据类型": "生育保险",
            "费用种类": "福利支出",
            "费用种类详情": "保险"
        }]

        try:
            for i in range(len(md)):
                # ***** 业务标记 *****
                # **************************** 登陆部分 ****************************
                username = makeJsonData("经办登录名")
                password = makeJsonData("登陆密码")

                token = get_token(login_url, username, password, errInfo=False)
                time.sleep(1)

                # **************************** 查询部分 ****************************
                header = \
                    {
                    "Authorization": "Bearer " + token,
                    "Content-Type": "application/json"
                }

                params = {"code": md[i]["报销单号"]}
                params = json.dumps(params).replace("'", "\"")

                self.result = myRequest(self.url + base_url[0],
                                        headers=header,
                                        data=params)

                # 校验
                if self.result.get("code") == 200:
                    print("📈 第 ", i + 1, " 条报销单(", md[i]["报销单号"],
                          ")“单据查询”响应成功")

                    if self.result["rst"]["data"]["finance"].get("certcode"):
                        print("📈 第 ", i + 1, " 条报销单(", md[i]["报销单号"],
                              ")“单据查询”已做过财务标记")
                        md[i]["会计凭证号"] = self.result["rst"]["data"]["finance"][
                            "certcode"]
                        md[i]["标记状态"] = "成功"
                        continue
                    else:
                        doc = self.result["rst"]["data"]
                else:
                    print("📈 第 ", i + 1, " 条报销单(", md[i]["报销单号"],
                          ")“单据查询”响应失败,结果为:\n", self.result, "\n")
                    md[i]["标记状态"] = "失败"
                    continue

                # **************************** 财务标记部分 ****************************
                params = {
                    "certdate": str(datetime.date.today()),
                    "docs": [doc]
                }

                params = json.dumps(params).replace("'", "\"")

                self.result = myRequest(self.url + base_url[1],
                                        headers=header,
                                        data=params)

                # 校验
                if self.result.get("code") == 200 \
                        and len(self.result["rst"]["fail"]) == 0:
                    print("📈 第 ", i + 1, " 条报销单(", md[i]["报销单号"],
                          ")“财务标记”响应成功")
                    md[i]["标记状态"] = "成功"
                    md[i]["会计凭证号"] = self.result["rst"]["data"]["finance"][
                        "certcode"]
                else:
                    print("📈 第 ", i + 1, " 条报销单(", md[i]["报销单号"],
                          ")“财务标记”响应失败,结果为:\n", self.result, "\n")
                    md[i]["标记状态"] = "失败"
                    md[i]["会计凭证号"] = "未生成"
                    continue

            print("📈 最终标记结果为:\n", md)
            # **************************** 常规部分 ****************************
            self.testResult = "成功"
        except Exception as e:
            self.testResult = "失败"
            raise e
        finally:
            # 在excel中写值脚本不可写入try/except,否则html报告中无法区别体现“失败”和“异常”
            global_config.set_value("TESTRESULT", self.testResult)
            self.terminateProcess = True
            loadProcessValue("#流程开关", realValue="流程结束")
            loadProcessValue("#单据数据", realValue=str(md))
            writeTextResult(myRow=self.myRow)
예제 #23
0
    def test04_pick_boxes(self):
        ''' 登陆相同环境的PDA后,对每个箱子分别拣配(有n个箱子,则此案例中循环请求n次) '''
        # **************************** 案例公共信息初始化 ****************************
        self.caseName = (lambda: sys._getframe(1).f_code.co_name)()
        global_config.set_value("CASENAME",self.caseName)
        login_url = self.url + getInterfaceData("登陆接口")
        base_url = self.url + getInterfaceData("调用接口")


        if self.terminateProcess != "":
            self.testResult = "跳过"
            return

        # 与库表中数据主键重复情况均需考虑是否用初始化
        if getInterfaceData("是否数据库初始化") == "是":
            DB().delete(tableName,deleteData)


        try:
            # **************************** 登陆部分 ****************************
            username = makeJsonData("经办登录名")
            password = makeJsonData("登陆密码")

            time.sleep(1)
            token = get_token(login_url,username,password)

            # **************************** 交易部分 ****************************
            header = \
                {
                "Authorization": "Bearer " + token,
                "Content-Type": "application/json"
            }

            boxNum = deepcopy(len(self.dict["#旧箱号"]))
            boxes = deepcopy(self.dict["#旧箱号"])

            for i in range(boxNum):
                boxName = boxes[i]
                print("📦 第 %d 次扫描箱子,箱号为:%s" %(i+1,boxName))
                params = \
                    {
                        "bill_code": makeJsonData("#出库拣配单号"),
                        "box_code": boxName,
                        "phase": "BoxPhase",
                        "platform": "pda",
                        "sns": []
                    }
                params = json.dumps(params).replace("'","\"")

                self.result = myRequest(base_url, headers=header, data=params)

                # **************************** 校验部分 ****************************
                checkTheMessage("code",varNameInExcel="code")
                checkTheMessage("msg",varNameInExcel="msg")

            # **************************** 返回值部分 ****************************
            # 获取“token”
            global_config.set_value("TOKEN",token)

            # **************************** 常规部分 ****************************
            self.testResult = "成功"
        except Exception as e:
            self.testResult = "失败"
            raise e
        finally:
            # 在excel中写值脚本不可写入try/except,否则html报告中无法区别体现“失败”和“异常”
            global_config.set_value("TESTRESULT",self.testResult)
            self.terminateProcess = True
            loadProcessValue("#流程开关",realValue="拣配成功")
            writeTextResult(myRow=self.myRow)
예제 #24
0
    def test03_get_SN_info(self):
        ''' ***销售放货出库(分销)***查询SN信息 '''
        # **************************** 案例公共信息初始化 ****************************
        self.caseName = (lambda: sys._getframe(1).f_code.co_name)()
        global_config.set_value("CASENAME", self.caseName)
        base_url = self.url + getInterfaceData("调用接口")

        if self.terminateProcess != "":
            self.testResult = "跳过"
            return

        # 与库表中数据主键重复情况均需考虑是否用初始化
        if getInterfaceData("是否数据库初始化") == "是":
            DB().delete(tableName, deleteData)

        try:
            # **************************** 交易部分 ****************************
            header = \
                {
                "Authorization": "Bearer " + self.dict["TOKEN"],
                "Content-Type": "application/json"
            }

            for i in range(0, self.dict["箱子总数"]):  # self.dict["箱子总数"]:箱子个数
                boxName = combineJson(self.dict, "箱号", i)

                params = \
                    {
                        "choice": {
                            "boundCode": "",
                            "boxCode": boxName,
                            "endTime": "",
                            "group": "",
                            "isFullBox": "",
                            "ops": "",
                            "postingStatus": "",
                            "signCode": "",
                            "startTime": "",
                            "userName": "",
                            "wh": ""
                        },
                        "limit": "10",
                        "page": 1
                    }
                params = json.dumps(params).replace("'", "\"")

                self.result = myRequest(base_url, headers=header, data=params)

                # **************************** 校验部分 ****************************
                checkTheMessage("code", varNameInExcel="code")
                checkTheMessage("msg", varNameInExcel="msg")

                # **************************** 返回值部分 ****************************
                # materials = eval(combineJson(self.result,"rst","data","items",0,"bill","boxes",0,"materials"))

                boxInfo = eval(
                    combineJson(self.result, "rst", "data", "items", 0, "bill",
                                "boxes"))
                for h in range(len(boxInfo)):
                    if boxInfo[h].get("code") == boxName:
                        materials = boxInfo[h].get("materials")
                        break

                for j in range(0, len(
                        materials)):  # len(materials):该箱子中物料种类(含sn及不含sn的总和)
                    sn = materials[j].get("SN")
                    if sn is None:
                        continue

                    sapid = combineJson(materials, j, "sapid")

                    for k in range(
                            0, len(self.dict["MATERIALARRAY"][boxName])
                    ):  # len(self.dict["MATERIALARRAY"][boxName]):箱子中物料数量
                        mySapid = combineJson(self.dict, "MATERIALARRAY",
                                              boxName, k, "sapid")
                        if sapid == mySapid:
                            # 该物料下含SN且物料类型对应
                            self.dict["MATERIALARRAY"][boxName][k][
                                "sns"].append(sn)

            # **************************** 常规部分 ****************************
            self.testResult = "成功"
        except Exception as e:
            self.testResult = "失败"
            raise e
        finally:
            # 在excel中写值脚本不可写入try/except,否则html报告中无法区别体现“失败”和“异常”
            global_config.set_value("TESTRESULT", self.testResult)
            writeTextResult()
예제 #25
0
    def test01_get_boxes_info(self):
        ''' 登陆相应环境壳后,根据库存调整单查询拣配单及新旧箱子信息 '''
        # **************************** 案例公共信息初始化 ****************************
        self.caseName = (lambda: sys._getframe(1).f_code.co_name)()
        global_config.set_value("CASENAME",self.caseName)
        login_url = self.url + getInterfaceData("登陆接口")
        base_url = self.url + getInterfaceData("调用接口")

        # 与库表中数据主键重复情况均需考虑是否用初始化
        if getInterfaceData("是否数据库初始化") == "是":
            DB().delete(tableName,deleteData)

        try:
            # **************************** 登陆部分 ****************************
            username = makeJsonData("经办登录名")
            password = makeJsonData("登陆密码")

            token = get_token(login_url,username,password)

            # **************************** 交易部分 ****************************
            header = \
                {
                "Authorization": "Bearer " + token,
                "Content-Type": "application/json"
            }

            params = \
                {
                    "code": makeJsonData("库存调整单")
                }

            params = json.dumps(params).replace("'","\"")

            self.result = myRequest(base_url, headers=header, data=params)

            # **************************** 校验部分 ****************************
            checkTheMessage("code",varNameInExcel="code")
            checkTheMessage("msg",varNameInExcel="msg")

            # **************************** 返回值部分 ****************************
            # 获取新旧箱子信息及拣配单信息
            jianpidanhao = combineJson(self.result,"rst","data","info","outer","code")
            loadProcessValue("#出库拣配单号",realValue=jianpidanhao)
            global_config.set_value("#出库拣配单号",jianpidanhao)

            oldBoxesInfo = eval(combineJson(self.result, "rst", "outerMaterials", "out"))
            boxArray = []
            for i in range(len(oldBoxesInfo)):
                boxArray.append(oldBoxesInfo[i]["code"])

            loadProcessValue("#旧箱号",realValue=str(boxArray))
            global_config.set_value("#旧箱号", boxArray)

            # 获取调整类型代码
            adjustType = combineJson(self.result,"rst","data","type")
            global_config.set_value("#调整类型", adjustType)

            # 获取壳登陆信息
            global_config.set_value("TOKEN", token)


            # **************************** 常规部分 ****************************
            self.testResult = "成功"
        except Exception as e:
            self.testResult = "失败"
            raise e
        finally:
            # 在excel中写值脚本不可写入try/except,否则html报告中无法区别体现“失败”和“异常”
            global_config.set_value("TESTRESULT",self.testResult)
            writeTextResult()
예제 #26
0
    def test04_pick_boxes(self):
        ''' 对每个箱子分别拣配(有n个箱子,则此案例中循环请求n次),拣配后查询各箱子的“status”,若为2则为整箱,跳过扫sn '''
        # **************************** 案例公共信息初始化 ****************************
        self.caseName = (lambda: sys._getframe(1).f_code.co_name)()
        global_config.set_value("CASENAME", self.caseName)
        login_url = self.url + getInterfaceData("登陆接口")
        base_url = self.url + getInterfaceData("调用接口")

        if self.terminateProcess != "":
            self.testResult = "跳过"
            return

        # 与库表中数据主键重复情况均需考虑是否用初始化
        if getInterfaceData("是否数据库初始化") == "是":
            DB().delete(tableName, deleteData)

        try:
            # **************************** 登陆部分 ****************************
            username = makeJsonData("经办登录名")
            password = makeJsonData("登陆密码")

            token = get_token(login_url, username, password)

            # **************************** 交易部分 ****************************
            header = \
                {
                "Authorization": "Bearer " + token,
                "Content-Type": "application/json"
            }

            for i in range(0, self.dict["箱子总数"]):
                boxName = combineJson(self.dict, "箱号", i)
                print("第 %d 次扫描箱子,箱号为:%s" % (i + 1, boxName))
                params = \
                    {
                        "bill_code": makeJsonData("出库拣配单号"),
                        "box_code": boxName,
                        "phase": "BoxPhase",
                        "platform": "pda",
                        "sns": []
                    }
                params = json.dumps(params).replace("'", "\"")

                self.result = myRequest(base_url, headers=header, data=params)

                # **************************** 校验部分 ****************************
                checkTheMessage("code", varNameInExcel="code")
                checkTheMessage("msg", varNameInExcel="msg")

                # **************************** 返回值部分 ****************************
                if self.result["rst"]["data"]["bill"]["allBoxes"][0][
                        "status"] == 2:
                    self.dict["箱子总数"] += -1
                    self.dict["箱号"].remove(boxName)

            # 获取“token”
            global_config.set_value("TOKEN", token)

            # **************************** 常规部分 ****************************
            self.testResult = "成功"
        except Exception as e:
            self.testResult = "失败"
            raise e
        finally:
            # 在excel中写值脚本不可写入try/except,否则html报告中无法区别体现“失败”和“异常”
            global_config.set_value("TESTRESULT", self.testResult)
            writeTextResult()
예제 #27
0
    def test01_get_WithdrawType(self):
        ''' 登陆相应环境壳后,根据“出库拣配单号”/“SAP单据号”查询“出库类型” '''
        # **************************** 案例公共信息初始化 ****************************
        self.caseName = (lambda: sys._getframe(1).f_code.co_name)()
        global_config.set_value("CASENAME", self.caseName)
        login_url = self.url + getInterfaceData("登陆接口")
        base_url = self.url + getInterfaceData("调用接口")

        # 与库表中数据主键重复情况均需考虑是否用初始化
        if getInterfaceData("是否数据库初始化") == "是":
            DB().delete(tableName, deleteData)

        try:
            # **************************** 登陆部分 ****************************
            username = makeJsonData("经办登录名")
            password = makeJsonData("登陆密码")

            token = get_token(login_url, username, password)

            # **************************** 交易部分 ****************************
            header = \
                {
                "Authorization": "Bearer " + token,
                "Content-Type": "application/json"
            }

            params = \
                {
                    "choice": {
                        "EOBtime": "",
                        "SOBtime": "",
                        "code": makeJsonData("出库拣配单号"),
                        "contract": "",
                        "from": "",
                        "orderId": makeJsonData("SAP单据号"),
                        "purchaseId": "",
                        "status": "",
                        "type": ""
                    },
                    "limit": "10",
                    "page": 1
                }

            params = json.dumps(params).replace("'", "\"")

            self.result = myRequest(base_url, headers=header, data=params)

            # **************************** 校验部分 ****************************
            checkTheMessage("code", varNameInExcel="code")
            checkTheMessage("msg", varNameInExcel="msg")

            # **************************** 返回值部分 ****************************
            # 获取“token”
            global_config.set_value("TOKEN", token)

            if makeJsonData("出库拣配单号") == "":
                loadProcessValue("出库拣配单号", "rst", "data", "items", 0, "code")

            # 获取“出库类型”
            outBoundType = \
                {
                    "ZJ01": "销售放货出库(项目)",
                    "ZJ02": "销售放货出库(分销)",
                    "ZJ032": "销售维修出库",
                    "ZJ04": "样机借出出库",
                    "ZPRF": "采购退货出库"
                }

            withdrawType = outBoundType.get(
                combineJson(self.result, "rst", "data", "items", 0, "type"))
            loadProcessValue("#下架类型", realValue=withdrawType)
            global_config.set_value("下架类型", withdrawType)

            # **************************** 常规部分 ****************************
            self.testResult = "成功"
        except Exception as e:
            self.testResult = "失败"
            raise e
        finally:
            # 在excel中写值脚本不可写入try/except,否则html报告中无法区别体现“失败”和“异常”
            global_config.set_value("TESTRESULT", self.testResult)
            writeTextResult()
예제 #28
0
    def test08_check_undercarriage_result(self):
        ''' 查询下架结果 '''
        # **************************** 案例公共信息初始化 ****************************
        self.caseName = (lambda: sys._getframe(1).f_code.co_name)()
        global_config.set_value("CASENAME", self.caseName)
        login_url = self.url + getInterfaceData("登陆接口")
        base_url = self.url + getInterfaceData("调用接口")

        if self.terminateProcess != "":
            self.testResult = "跳过"
            return

        # 与库表中数据主键重复情况均需考虑是否用初始化
        if getInterfaceData("是否数据库初始化") == "是":
            DB().delete(tableName, deleteData)

        try:
            # **************************** 登陆部分 ****************************
            username = makeJsonData("经办登录名")
            password = makeJsonData("登陆密码")

            token = get_token(login_url, username, password)

            # **************************** 交易部分 ****************************
            header = \
                {
                "Authorization": "Bearer " + token,
                "Content-Type": "application/json"
            }

            params = \
                {
                    "choice": {
                        "EDHtime": "",
                        "SDHtime": "",
                        "boundCode": makeJsonData("出库拣配单号"),
                        "boxCode": "",
                        "type": "",
                        "wh": ""
                    },
                    "limit": "10",
                    "page": 1
                }
            params = json.dumps(params).replace("'", "\"")

            self.result = myRequest(base_url, headers=header, data=params)

            # **************************** 校验部分 ****************************
            checkTheMessage("code", varNameInExcel="code")
            checkTheMessage("msg", varNameInExcel="msg")
            assert len(
                self.result["rst"]["data"]["items"]) == self.dict["箱子总数"]

            # **************************** 常规部分 ****************************
            self.testResult = "成功"
        except Exception as e:
            self.testResult = "失败"
            raise e
        finally:
            # 在excel中写值脚本不可写入try/except,否则html报告中无法区别体现“失败”和“异常”
            global_config.set_value("TESTRESULT", self.testResult)
            self.terminateProcess = True
            loadProcessValue("#流程开关", realValue="下架成功")
            writeTextResult(myRow=self.myRow)
    def test01_get_costtype(self):
        ''' 遍历获取所有“费用种类-票据类型”组合项,并存入全局变量 '''
        import copy

        if self.terminateProcess != "":
            self.testResult = "跳过"
            return

        # **************************** 案例公共信息初始化 ****************************
        self.caseName = (lambda: sys._getframe(1).f_code.co_name)()
        global_config.set_value("CASENAME",self.caseName)
        login_url = self.url + getInterfaceData("登陆接口")
        base_url = self.url + getInterfaceData("调用接口")

        # 与库表中数据主键重复情况均需考虑是否用初始化
        if getInterfaceData("是否数据库初始化") == "是":
            DB().delete(tableName,deleteData)

        try:
            # **************************** 登陆部分 ****************************
            username = makeJsonData("经办登录名")
            password = makeJsonData("登陆密码")

            token = get_token(login_url,username,password, errInfo=False)
            time.sleep(1)

            # **************************** 交易部分 ****************************
            header = \
                {
                "Authorization": "Bearer " + token,
                "Content-Type": "application/json"
            }

            params = {}
            params = json.dumps(params).replace("'","\"")

            self.result = myRequest(base_url, headers=header, data=params)

            # **************************** 校验部分 ****************************
            checkTheMessage("code",varNameInExcel="code")
            checkTheMessage("msg",varNameInExcel="msg")

            # **************************** 返回值部分 ****************************
            # 获取“token”
            global_config.set_value("TOKEN",token)

            ct1 = self.result["rst"]["data"]["costtype"]
            costType = []
            for k1 in ct1.keys():
                # 用于划分模块执行
                if makeJsonData("费用种类") != "":
                    if ct1[k1]["text"] != makeJsonData("费用种类"):
                        continue

                myDict = {}
                if ct1[k1].get("status") == "x":
                    continue

                myDict["category"] = k1
                myDict["text1"] = ct1[k1]["text"]

                ct2 = ct1[k1]["sub"]
                md1 = copy.deepcopy(myDict)
                for k2 in ct2.keys():
                    if ct2[k2].get("status") == "x":
                        continue

                    myDict["costtype"] = k2
                    myDict["text2"] = ct2[k2]["text"]

                    ct3 = ct2[k2]["sub"]
                    md2 = copy.deepcopy(myDict)
                    for i, k3 in enumerate(ct3.keys()):
                        myDict["invoicetype"] = k3
                        myDict["invoicetypestr"] = ct3[k3]["text"]

                        myDict["flag"] = ""
                        costType.append(myDict)

                        if i + 1 == len(ct3):
                            myDict = copy.deepcopy(md1)
                        else:
                            myDict = copy.deepcopy(md2)

            # 获取“供应商编号”
            global_config.set_value("费用类型组合项", costType)

            # a = []
            # for k in range(5):
            #     a.append(self.dict["费用类型组合项"][k])
            # global_config.set_value("费用类型组合项", a)


            # **************************** 常规部分 ****************************
            self.testResult = "成功"
        except Exception as e:
            self.testResult = "失败"
            raise e
        finally:
            # 在excel中写值脚本不可写入try/except,否则html报告中无法区别体现“失败”和“异常”
            global_config.set_value("TESTRESULT",self.testResult)
            writeTextResult()
예제 #30
0
    def test01_box_uptray(self):
        ''' 登陆500环境PDA后,扫码进行箱子上托盘 '''
        # **************************** 案例公共信息初始化 ****************************
        self.caseName = (lambda: sys._getframe(1).f_code.co_name)()
        global_config.set_value("CASENAME", self.caseName)
        login_url = self.url + getInterfaceData("登陆接口")
        base_url = self.url + getInterfaceData("调用接口")

        # 与库表中数据主键重复情况均需考虑是否用初始化
        if getInterfaceData("是否数据库初始化") == "是":
            DB().delete(tableName, deleteData)

        try:
            # 确定并发流程数
            multiAccount = eval(makeJsonData("并发流程数"))
            token = get_token(login_url, makeJsonData("经办登录名"),
                              makeJsonData("登陆密码"))
            errAccount = 0
            start = time.time()
            maxNum = 10
            # multis = []

            p = multiprocessing.Pool(processes=maxNum)

            for i in range(multiAccount):
                multiRow = global_config.get_value("TESTROW") + i
                myProcess = p.apply_async(func=box_uptray,
                                          args=(
                                              login_url,
                                              base_url,
                                              multiRow,
                                              token,
                                          ))
                myProcess.daemon = True
                # multis.append(myProcess)

            p.close()
            p.join()

            end = time.time()

            for i in range(multiAccount):
                multiRow = global_config.get_value("TESTROW") + i
                if makeProcessData("#流程开关",
                                   multiRow=multiRow).find("报错") != -1:
                    errAccount += 1
                print("第 %d 次进程中累计报错数为: %d" % (i + 1, errAccount))

            print(
                "========================================================================"
            )
            print("接口性能测试开始时间:", time.asctime(time.localtime(start)))
            print("接口性能测试结束时间:", time.asctime(time.localtime(end)))
            print("接口地址:", base_url)
            print("接口类型:", "post")
            print("最大进程数:", maxNum)
            print("每个进程循环次数:", 1)
            print("每次请求时间间隔:", 0)
            print("总请求数:", multiAccount * 1)
            # print("错误请求数:", len(error))
            print("总耗时(秒):", end - start)
            print("每次请求耗时(秒):", (end - start) / (multiAccount * 1))
            print("每秒承载请求数(TPS):", (multiAccount * 1) / (end - start))
            print("平均响应时间(毫秒):", CM.multi_response_avg())
            print(
                "========================================================================"
            )

            # **************************** 常规部分 ****************************
            assert errAccount == 0, \
                "😭 箱子入托盘中,\n共需处理 '%s' 个流程, 有 '%d' 个失败!" \
                %(multiAccount,errAccount)
            print("😭 箱子入托盘中,\n共需处理 '%s' 个流程, 有 '%d' 个失败!" \
                %(multiAccount,errAccount))
        except AssertionError as e:
            self.testResult = "失败"
            raise AssertionError(e)
        except Exception as e:
            self.testResult = "失败"
            raise e
        finally:
            if errAccount == 0:
                self.testResult = "成功"

            # 在excel中写值脚本不可写入try/except,否则html报告中无法区别体现“失败”和“异常”
            global_config.set_value("TESTRESULT", self.testResult)
            self.terminateProcess = True
            writeTextResult(myRow=self.myRow)