def __init__(self, driver): '''获取操作系统信息''' platform1 = platform.platform( ) # 获取操作系统名称及版本号,'Windows-7-6.1.7601-SP1' version = platform.version() # 获取操作系统版本号,'6.1.7601' architecture = platform.architecture( ) # 获取操作系统的位数,('32bit', 'WindowsPE') machine = platform.machine() # 计算机类型,'x86' node = platform.node() # 计算机的网络名称,'hongjie-PC' processor = platform.processor( ) # 计算机处理器信息,'x86 Family 16 Model 6 Stepping 3, AuthenticAMD' uname = platform.uname( ) # 包含上面所有的信息汇总,uname_result(system='Windows', node='hongjie-PC', MASTER_HELPER.environment(platform=platform1, version=version, architecture=architecture, machine=machine, node=node, processor=processor, uname=uname) '''设置轮循时间及超时时间''' self.logger = logger.Logger().getLogger() self.driver = driver self.timeout = 10 self.t = 0.5
def update_department(self, depart_info): with allure.step("获取更新部门信息请求参数"): url = self.yaml_data["contacts"]["department"]["update_dep_url"] params = {"access_token": self.access_token} logging.debug("url:" + str(url)) logging.debug("params:" + str(params)) with allure.step("发出更新部门信息的请求"): self.send_post_json(url, depart_info, params=params)
def update_member(self, update_mem_info): with allure.step("获取更新成员请求参数"): url = self.yaml_data["contacts"]["member"]["update_mem_url"] params = {"access_token": self.access_token} logging.debug("url:" + str(url)) logging.debug("params:" + str(params)) with allure.step("发出更新成员的请求"): self.send_post_json(url, update_mem_info, params=params)
def delete_member(self, userid): with allure.step("获取删除成员请求参数"): url = self.yaml_data["contacts"]["member"]["delete_mem_url"] params = {"access_token": self.access_token, "userid": userid} logging.debug("url:" + str(url)) logging.debug("params:" + str(params)) with allure.step("发出删除成员的请求"): self.send_get(url, params=params)
def __init__(self): self.cf = CommonFunction() # 配置文件路径 with allure.step("获取配置文件路径"): file_path = "/Users/mac/auto_test/Weixin_InterfaceTest/config/config_data.yaml" # 获取配置文件内容 with allure.step("获取配置文件内容"): self.yaml_data = self.cf.get_yaml_data(file_path)
def delete_department(self, depa_id): with allure.step("获取删除部门请求参数"): url = self.yaml_data["contacts"]["department"]["delete_dep_url"] params = {"access_token": self.access_token, "id": depa_id} logging.debug("url:" + str(url)) logging.debug("params:" + str(params)) with allure.step("发出删除部门的请求"): self.send_get(url, params)
def delete_member_many(self, useridlist): with allure.step("获取删除成员请求参数"): url = self.yaml_data["contacts"]["member"]["delete_mem_url"] params = { "access_token": self.access_token, } logging.debug("url:" + str(url)) logging.debug("params:" + str(params)) with allure.step("发出删除成员的请求"): self.send_post_json(url, useridlist, params=params)
def get_department_list(self, depa_id=None): with allure.step("获取部门列表请求参数"): url = self.yaml_data["contacts"]["department"]["get_dep_list_url"] if depa_id: params = {"access_token": self.access_token, "id": depa_id} else: params = {"access_token": self.access_token} logging.debug("url:" + str(url)) logging.debug("params:" + str(params)) with allure.step("发出查询部门列表的请求"): self.send_get(url, params)
def judgment_access_token_is_valid(self, application_name, token_path): with allure.step("判断已经存在的yaml文件中的 access_token 是否有效"): url = self.yaml_data["ip_url"] access_token = self.cf.get_yaml_data(token_path).get( "access_token") params = {"access_token": access_token} res = requests.get(url, params=params) if res.json().get("errcode") == 40014 or res.json().get( "errcode") == 41001: with allure.step("token 失效,重新请求"): self.get_access_token(application_name)
def get_screen(self, file_name=time.strftime('%Y-%m-%d_%H-%S-%M', time.localtime(time.time()))): '''截图''' self.logger.info("在此时进行截图!!") try: dit = readYaml.read("project.yaml") file_name = r"{}\screen\{}.png".format(dit['project']['path'], file_name) self.driver.get_screenshot_as_file(file_name) with open(file_name, 'rb') as file: f = file.read() MASTER_HELPER.attach("截图", f, type=AttachmentType.PNG) self.logger.info("已成功生成截图,请确认!") except: raise Exception("截图失败!")
def get_access_token(self, application_name): with allure.step("获取 access_token 请求参数"): token_url = self.yaml_data["token_url"] corp_id = self.yaml_data["corp_id"] application_secret = self.yaml_data[application_name]["secret"] # 构造请求参数 with allure.step("构造获取token请求参数"): params = {"corpid": corp_id, "corpsecret": application_secret} with allure.step("发送 access_token 请求"): res = requests.get(token_url, params=params) # 获取 access_token with allure.step("获取 access_token"): access_token = res.json().get("access_token") # 将获取的 access_token 写入该应用专属配置文件 with allure.step("将获取的 access_token 写入该应用专属配置文件"): yaml_filename = str(application_name) + "_access_token.yaml" content = {"access_token": access_token} self.cf.write_yaml(yaml_filename, content)
def test_add_optometry_record(self): with helper.step("新增验光记录"): self.lg.login() self.op.add_optometry_record() time.sleep(2)
def test_draw_a_bill(self): with helper.step("进入视光销售--查询用户"): self.op.query_users() with helper.step("销售开单"): self.op.draw_a_bill() time.sleep(1)
def test_login_001(self): with MASTER_HELPER.step("登陆CRM"): self.login_page.crm_login()
def test_choose_discount(self): with helper.step("再开一单--选择优惠"): self.sa.choose_discount() time.sleep(2)
def test_bill_amount_wrong(self): with helper.step("再开一单--更换处方"): self.sa.replace_prescription() time.sleep(2)
def test_bill_amount_wrong(self): with helper.step("再开一单--订单数量为0"): self.sa.replace_prescription() time.sleep(2) assert self.sa.get_text(self.op.amount_tip) == '订单总额不允许为0'
def test_delete_optometry_record(self): with helper.step("删除验光记录"): self.op.delete_optometry_record() time.sleep(2)