def action(self, *all_data): suite_number = all_data[0][0] # 用例集编号 case_number = all_data[0][1] # 用例标识 url = all_data[0][5] # 请求url method = all_data[0][6] # 请求方式 # headers = all_data[0][7] # 请求头部 front_process = all_data[0][9] # 前置处理 data = all_data[0][10] # 请求数据 rule = all_data[0][11] # 匹配规则 expect_result = all_data[0][12] # 预期结果 rear_process = all_data[0][13] # 后置处理 is_execute = all_data[0][15] # 是否执行 depend_value = all_data[0][16] # 被依赖value col_num = all_data[1] if is_execute.upper() == 'Y': exe.exe_case(suite_number, case_number, url, method, data, rule, expect_result, depend_value, col_num, front_process, rear_process) else: # 用例执行否 logger.info( "---------------[{}]用例开始执行---------------".format(case_number)) my_excel.xlutils_excel(col_num + 2, 20, date_time(), "用例执行时间") # 写入执行时间 my_excel.xlutils_excel(col_num + 2, 19, '跳过', "用例执行结果") logger.info("【{}】用例跳过".format(case_number)) global SkipCount SkipCount += 1
def __init__(self): self.device_name = None pipeline = os.popen("adb devices") # cmd获取设备名称 adb_version = os.popen( "adb shell getprop ro.build.version.release") # cmd获取Android系统版本 adb_devices = pipeline.read() try: self.device_name = adb_devices.split()[4] except Exception as msg: logger.error("请检查移动设备是否连接正常,异常信息{}".format(msg)) raise # 初始化信息 self.desired_caps = {} self.desired_caps["platformName"] = "Android" self.desired_caps["platformVersion"] = adb_version = adb_version.read() self.desired_caps["deviceName"] = self.device_name self.desired_caps["appPackage"] = "com.yunke.enterprisep" self.desired_caps["appActivity"] = ".module.main.MainActivity" self.desired_caps["unicodeKeyboard"] = True # 隐藏手机中的软键盘 self.desired_caps["resetKeyboard"] = True self.desired_caps["noReset"] = True # desired_caps = {"platformName": "Android", # "platformVersion": adb_version, # "deviceName": self.device_name, # "appPackage": "com.yunke.enterprisep", # "appActivity": ".module.main.MainActivity", # "unicodeKeyboard": True, # "resetKeyboard": True, # "noReset": True # } logger.info("[{}]driver初始化‖platformVersion:{},deviceName:{}".format( os.path.basename(__file__), adb_version, self.device_name))
def test_customer_002(self): """添加客户""" logger.info("*{}用例{}\{}开始执行{}*".format("=" * 20, __name__, sys._getframe().f_code.co_name, "=" * 20)) driver_app.start_activity("com.yunke.enterprisep", ".module.main.MainActivity") # 启动Activity self.pg.findAndroidUiautomator("管客户").click() self.pg.findAndroidUiautomator("添加").click() self.pg.findAndroidUiautomator("录入客户").click() self.pg.findAndroidUiautomator("请输入姓名").click() self.pg.findAndroidUiautomator("录入客户").click() # self.pg.findAndroidUiautomator("请输入姓名").send_keys("gaozuxin") self.pg.sendKeys(self.pg.findAndroidUiautomator("请输入姓名"), "gaozuxin") self.pg.findAndroidUiautomator("请输入手机").click() # self.pg.findAndroidUiautomator("请输入手机").send_keys("18637607203") self.pg.sendKeys(self.pg.findAndroidUiautomator("请输入手机"), "18637607403") # self.pg.findAndroidUiautomator("请输入手机").send_keys("18637607203") try: self.pg.findAndroidUiautomator("请输入邮箱").click() # self.pg.findAndroidUiautomator("请输入邮箱").send_keys("*****@*****.**") self.pg.sendKeys(self.pg.findAndroidUiautomator("请输入邮箱"), "*****@*****.**") self.pg.findAndroidUiautomator("请输入QQ").click() # self.pg.findAndroidUiautomator("请输入QQ").send_keys("120983257") self.pg.sendKeys(self.pg.findAndroidUiautomator("请输入QQ"), "120983257") except Exception as msg: print("异常原因" + str(msg)) self.pg.findAndroidUiautomator("请输入微信号").click() # self.pg.findAndroidUiautomator("请输入微信号").send_keys("XIN507197") self.pg.sendKeys(self.pg.findAndroidUiautomator("请输入微信号"), "XIN507197") self.pg.findAndroidUiautomator("请输入职位").click() # self.pg.findAndroidUiautomator("请输入职位").send_keys("tester") self.pg.sendKeys(self.pg.findAndroidUiautomator("请输入职位"), "tester") self.pg.findAndroidUiautomator("请选择性别").click() self.pg.findAndroidUiautomator("确定").click() self.pg.findAndroidUiautomator("保存").click() # self.assertEqual('gaozuxin', islogin, msg="注册并登录失败") logger.info("*{}用例{}\{}执行结束{}*".format("=" * 20, __name__, sys._getframe().f_code.co_name, "=" * 20))
def takeScreenshot(self): rq = time.strftime("%Y-%m-%d %H_%M_%S", time.localtime()) try: self._driver.get_screenshot_as_file( os.path.dirname(os.path.dirname(os.path.dirname(__file__))) + r'\result\screenshots\{}.png'.format(rq)) logger.info("[{}]已截屏并保存{}.png!".format(os.path.basename(__file__), rq)) except Exception as e: logger.error("[{}]无法截屏!{}".format(os.path.basename(__file__), e))
def connect(self, port=4723): url = 'http://localhost:%s/wd/hub' % str(port) try: driver = webdriver.Remote(url, self.desired_caps) logger.info("[{}]启动接口为:{},手机ID为:{}".format( os.path.basename(__file__), port, self.device_name)) except Exception as msg: logger.error("[{}]appium启动失败,请检查appium服务是否开启;异常原因:{}".format( os.path.basename(__file__), msg)) os.popen("taskkill /f /im adb.exe") raise return driver
def request_post(url, data): header_dict = {'Content-Type': 'application/json'} try: r = requests.post(url=url, headers=header_dict, json=data) # 发送请求 data_str = r.text # logger.debug("###" + data_str) logger.info("请求url:{};请求头:{};请求数据:{};服务器响应:{}".format( url, header_dict, data, data_str)) except Exception as e: data_str = -1 logger.error("请求url:{};请求头:{};请求数据:{};系统异常信息:{}".format( url, header_dict, data, e)) return data_str
def test_customer_001(self): """给客户打电话""" logger.info("*{}用例{}\{}开始执行{}*".format("=" * 20, __name__, sys._getframe().f_code.co_name, "=" * 20)) driver_app.start_activity("com.yunke.enterprisep", ".module.main.MainActivity") # 启动Activity self.pg.findAndroidUiautomator("管客户").click() self.pg.findId('com.yunke.enterprisep:id/iv_phone').click() # 点击拨打电话按钮 time.sleep(1) self.pg.takeScreenshot() time.sleep(2) self.pg.findId('com.android.dialer:id/floating_end_call_action_button').click() # 点击挂断电话按钮 time.sleep(0.5) self.pg.takeScreenshot() # self.assertEqual('gaozuxin', islogin, msg="注册并登录失败") logger.info("*{}用例{}\{}执行结束{}*".format("="*20, __name__, sys._getframe().f_code.co_name, "="*20))
def tearDownClass(cls): # mysql.close() logger.info( "************************************{}end*************************************" .format(__name__))
def setUpClass(cls): warnings.simplefilter("ignore", ResourceWarning) cls.pg = BasePage(driver_app) logger.info("{}{}start{}".format("*" * 25, __name__, "*" * 25))
def __init__(self): logger.info("-" * 32 + date_time_chinese() + "-" * 32)