Beispiel #1
0
class GetCookie():
    def __init__(self,outjsonfile=None,outloginurl=None,outloginaccountxpath=None,
                 outloginaccounttext=None,outloginppasswordxpath=None,outloginpasswordtext=None,
                 outloginbuttonxpath=None):

        if outjsonfile==None:
            self.jsonfile = '../dataconfig/cookie.json'
        else:
            self.jsonfile = outjsonfile

        if outloginurl==None:
            self.loginurl ="https://bjw.halodigit.com:9090/nereus/manager/index#/login"
        else:
            self.loginurl = outloginurl

        if outloginaccountxpath==None:
            self.loginaccountxpath = "/html/body/div[1]/div[2]/form/div/div[1]/input"
        else:
            self.loginaccountxpath = outloginaccountxpath

        if outloginaccounttext==None:
            self.loginaccount = "*****@*****.**"
        else:
            self.loginaccount = outloginaccounttext

        if outloginppasswordxpath==None:
            self.loginppasswordxpath = "/html/body/div[1]/div[2]/form/div/div[2]/input"
        else:
            self.loginppasswordxpath = outloginppasswordxpath

        if outloginpasswordtext==None:
            self.loginpassword = "******"
        else:
            self.loginpassword = outloginpasswordtext

        if outloginbuttonxpath==None:
            self.loginbuttonxpath = "/html/body/div[1]/div[2]/form/div/a[1]/span"
        else:
            self.loginbuttonxpath = outloginbuttonxpath

        self.operationjson = OperationJson(file_path=self.jsonfile)   #实例化
        self.activeweb = ActiveWeb()  # 实例化


    def getCookie(self):
        # 登录
        self.activeweb.getUrl(self.loginurl)  # 打开网址
        self.activeweb.findElementByXpathAndInput(self.loginaccountxpath,self.loginaccount)
        self.activeweb.findElementByXpathAndInput(self.loginppasswordxpath,self.loginpassword)
        self.activeweb.findElementByXpathAndClick(self.loginbuttonxpath)
        self.activeweb.delayTime(3)
        # 获取cookie
        cookie = self.activeweb.getCookies()
        self.activeweb.closeBrowse()
        return cookie

    def writerCookieToJson(self):
        self.cookie = self.getCookie()
        self.operationjson.write_data(self.cookie)
        print("\ncookie信息‘%s’已经写入‘%s’文件里。\n" % (self.cookie,self.jsonfile))
Beispiel #2
0
 def write_cookie(self):
     op = OperationJson()
     ab = self.get_cookie()
     dc = {
         "accessToken": ab
     }
     op.write_data(dc)
Beispiel #3
0
class RunTest:

    def __init__(self):
        self.run_method = RunMethod()
        self.data = GetData()
        self.com_util = CommonUtil()
        self.operation_json = OperationJson()
        self.operation_depend = OperationDepend()

        # self.send_email = SendEmail()

    def go_on_run(self):
        """程序执行"""
        pass_count = []
        fail_count = []
        res = None
        # 获取用例数
        rows_count = self.data.get_case_lines()
        # 第一行索引为0
        for i in range(1, rows_count):
            is_run = self.data.get_is_run(i)
            if is_run:
                case_id = self.data.get_request_case(i)
                case_name = self.data.get_request_name(i)
                print(f"{case_id}-{case_name}")
                url = self.data.get_request_url(i)
                method = self.data.get_request_method(i)
                request_data = self.data.get_request_data(i)
                expect = self.data.get_expcet_data(i)
                header = self.data.is_header(i)
                depend_field = self.data.get_depend_field(i)
                depend_key = self.data.get_depend_key(i)
                depend_case = self.data.is_depend(i)

                # 判断是否存在依赖
                if depend_case:
                    request_data = self.operation_depend.get_depend_data(depend_case, depend_key, depend_field, request_data)

                res = self.run_method.run_main(method, url, request_data, header)
                if expect != None:
                    if self.com_util.is_contain(expect, res):
                        self.operation_json.write_data(case_id, res)
                        self.data.write_result(i, "Pass")
                        pass_count.append(i)
                    else:
                        self.data.write_result(i, "Fail")
                        self.data.write_result_error(i, res)
                        fail_count.append(i)
                else:
                    print(f"用例ID:case-{i},预期结果不能为空")

        print(f"通过用例数:{len(pass_count)}")
        print(f"失败用例数:{len(fail_count)}")
Beispiel #4
0
 def write_login_cookie(self):
     cookie = requests.utils.dict_from_cookiejar(self.response.cookies)
     loginInfo = self.response.content.decode("utf-8")
     logininfo_json = json.loads(loginInfo)
     id=logininfo_json.get("data").get("id")
     code = logininfo_json.get("data").get("code")
     orgId = logininfo_json.get("data").get("orgId")
     name = logininfo_json.get("data").get("name")
     reval= {"id":id,"code":code,"orgId":orgId,"name":name}
     cookie.setdefault("user_info",str(reval))
     cookis_str = ""
     for k in cookie:
         cookis_str = cookis_str+k+"="+cookie[k]+";"
     # print(cookis_str)
     op_json = OperationJson()
     op_json.write_data(cookis_str)
Beispiel #5
0
    def write_cookie(self):
        """
        写入cookie到json文件中
        :return:
        """
        cookie = requests.utils.dict_from_cookiejar(self.get_cookie())
        op_json = OperationJson()
        op_json.write_data(cookie)


#
# url = 'http://zz.fetv.cn/YcE/ashx/Login.ashx'
# data = {
#     "action": "getVerifyCode"
# }
# r = RunMain()
# res = r.run_main('post', url, data)
# # code = requests.utils.dict_from_cookiejar(res)['validateCookie'][8:]
#
# c = OperationCookie(res)
# c.write_cookie()

# data2 = {
#     "action": "userLogin",
#     "user": "******",
#     "psw": "123456",
#     "yzm": code
# }
# cookie2 = requests.post(url, data2).cookies
# print(requests.utils.dict_from_cookiejar(cookie2))
#
# url1 = 'http://zz.fetv.cn/YcE/ashx/NavigationList.ashx'
# data3 = {
#     'action': 'getNavigationList'
# }
# res = requests.post(url1, data3, cookies=cookie2)
# print(res.text)
Beispiel #6
0
 def write_cookie(self):
     cookie = requests.utils.dict_from_cookiejar(self.get_cookie())
     op_json = OperationJson()
     op_json.write_data(cookie)
Beispiel #7
0
 def write_token(self):
     op_json = OperationJson()
     op_json.write_data(self.get_response_token())