def step(self, data, run_case): tc_id = run_case[TestSteps.STEP_TC_ID] #获取步骤 steps = data.get_steps_by_tc_id(tc_id) # allure报告 # feature是用例中的备注 allure.dynamic.feature(run_case[TestCases.CASES_NOTE]) # story是用例中的描述 allure.dynamic.story(run_case[TestCases.CASES_DESC]) # title是用例ID 和用例标题 allure.dynamic.title(run_case[CaseData.DATA_CASE_ID] + "-" + run_case[CaseData.DATA_NAME]) for step in steps: #log.debug("执行步骤{}".format(step)) #获取元素信息 elements = step[TestSteps.STEP_ELEMENT_NAME] element = data.get_elements_by_element(step[TestSteps.STEP_TC_ID], elements) #log.debug("元素信息{}".format(element)) #操作步骤 关键表映射 click_btn operate = self.get_keyword(step[TestSteps.STEP_OPERATE]) #操作判断,是否存在,不存在不执行步骤 if operate: # 定义方法参数:字典 param_value = dict() #根据getattr判断执行哪个方法 action_method = getattr(Action(self.driver), operate) log.debug("该关键字是{}".format(operate)) #定义具体的参数 by = element[Elements.ELE_BY] value = element[Elements.ELE_VALUE] # 1、获取by,value,send_value内容 send_value = step[TestSteps.STEP_DATA] # 2、send_value内容转换,通过case data数据内容 expect = run_case[CaseData.DATA_EXPECT_RESULT] param_value["by"] = by param_value["value"] = value param_value["expect"] = expect #判断假如有输入内容 字符转换 if send_value: data_input = run_case[CaseData.DATA_INPUT] print("输入参数: " + data_input) send = self.str_to_dict(data_input) param_value["send"] = send[send_value] # step记录测试步骤 with allure.step(step[TestSteps.STEP_NAME]): action_method(**param_value) else: log.error("没有operate信息:{}".format(operate))
def step(self, data, run_case): tc_id = run_case[TestSteps.STEP_TC_ID] #获取步骤 steps = data.get_steps_by_tc_id(tc_id) allure.dynamic.feature(run_case[TestCases.CASSE_NOTE]) allure.dynamic.story(run_case[TestCases.CASES_DESC]) allure.dynamic.title(run_case[CaseData.DATA_TC_ID] + "-" + run_case[CaseData.DATA_NAME]) for step in steps: log.debug("执行步骤:{}".format(step)) elements = step[TestSteps.STEP_ELEMENT] element = data.get_elements_by_element(step[TestSteps.STEP_TC_ID], elements) log.debug("元素信息:{}".format(element)) operate = self.get_keyword(step[TestSteps.STEP_OPERATE]) #定义方法参数:字典 param_value = dict() by = element[Elements.ELEMENTS_BY] value = element[Elements.ELEMENTS_VALUE] send_value = step[TestSteps.STEP_DATA] data_input = run_case[CaseData.DATA_INPUT] send = self.str_to_dict(data_input) expect = run_case[CaseData.DATA_EXPECT_RESULT] if send_value: data_input = run_case[CaseData.DATA_INPUT] send = self.str_to_dict(data_input) expect = run_case[CaseData.DATA_EXPECT_RESULT] param_value["by"] = by param_value["value"] = value param_value["send"] = send[send_value] param_value['expect'] = expect else: param_value["by"] = by param_value["value"] = value if operate: action_method = getattr(Action(self.driver), operate) log.debug("该关键字是:{}".format(operate)) print(action_method) with allure.step(step[TestSteps.STEP_NAME]): action_method(**param_value) else: log.error("没有operate信息:{}".format(operate))
def test_step_new(self): data = Data("../data/data.xls") run_list = data.run_list() run_case = run_list[0][0] tc_id = run_case[TestSteps.STEP_TC_ID] steps = data.get_steps_by_tc_id(tc_id) for step in steps: log.debug("执行步骤{}".format(step)) #获取元素信息 elements = step[TestSteps.STEP_ELEMENT_NAME] element = data.get_elements_by_element(step[TestSteps.STEP_TC_ID], elements) log.debug("元素信息{}".format(element)) #操作步骤 关键表映射 click_btn operate = self.get_keyword(step[TestSteps.STEP_OPERATE]) #操作判断,是否存在,不存在不执行步骤 if operate: # 定义方法参数:字典 param_value = dict() #根据getattr判断执行哪个方法 action_method = getattr(Action(self.driver), operate) log.debug("该关键字是{}".format(operate)) #定义具体的参数 by = element[Elements.ELE_BY] value = element[Elements.ELE_VALUE] # 1、获取by,value,send_value内容 send_value = step[TestSteps.STEP_DATA] # 2、send_value内容转换,通过case data数据内容 expect = run_case[CaseData.DATA_EXPECT_RESULT] param_value["by"] = by param_value["value"] = value param_value["expect"] = expect #判断假如有输入内容 字符转换 if send_value: data_input = run_case[CaseData.DATA_INPUT] send = self.str_to_dict(data_input) param_value["send"] = send[send_value] action_method(**param_value) else: log.error("没有operate信息:{}".format(operate))
def test_step_new(self): data = Data("../data/data.xls") run_list = data.run_list() run_case = run_list[0] print(run_case) tc_id = run_case[TestSteps.STEP_TC_ID] steps = data.get_steps_by_tc_id(tc_id) for step in steps: log.debug("执行步骤:{}".format(step)) #获取元素信息 elements = step[TestSteps.STEP_ELEMENT] element = data.get_elements_by_element(step[TestSteps.STEP_TC_ID], elements) log.debug("元素信息:{}".format(element)) #操作步骤 operate = self.get_keyword(step[TestSteps.STEP_OPERATE]) #定义方法参数:字典 param_value = dict() by = element[Elements.ELEMENTS_BY] value = element[Elements.ELEMENTS_VALUE] send_value = step[TestSteps.STEP_DATA] if send_value: data_input = run_case[CaseData.DATA_INPUT] send = self.str_to_dict(data_input) #expect = run_case[CaseData.DATA_EXPECT_RESULT] param_value["by"]= by param_value["value"] = value param_value["send"] = send[send_value] #param_value['expect']=expect else: param_value["by"] = by param_value["value"] = value #操作是否存在,不存在不执行 if operate: #根据getattr判断执行那个方法 action_method = getattr(Action(self.driver),operate) log.debug("该关键字是:{}".format(operate)) print(action_method) action_method(**param_value) else: log.error("没有operate信息:{}".format(operate))
def test_login(self, phone, password): Desire_driver = DesireCaps.appium_desired_caps() driver = Action(Desire_driver) # 点击密码登录 driver.click_btn(by="id", value="com.stoneenglish:id/quick_to_login") LogUtil.my_log("登陆日志:").info("点击选择密码登录") # 输入手机号 time.sleep(3) driver.click_btn(by="id", value="com.stoneenglish:id/login_tel") time.sleep(3) driver.send_keys(by="id", value="com.stoneenglish:id/login_tel", send=phone) LogUtil.my_log("登陆日志:").info("输入手机号") time.sleep(2) driver.click_btn(by="id", value="com.stoneenglish:id/login_password") driver.send_keys(by="id", value="com.stoneenglish:id/login_password", send=password) LogUtil.my_log("登陆日志:").info("输入密码") time.sleep(3) driver.click_btn(by="id", value="com.stoneenglish:id/login_ok") driver.is_toast_exist(expect="登录成功") driver.assert_toast_result(expect="登录成功")
def setUp(self): LogUtil.my_log("setUpC开启:" + nowtime).info("setUp开启...初始化driver.launch_app()") self.driver.launch_app() self.Page_driver = Action(self.driver)
class Login(unittest.TestCase): @classmethod #setup类 def setUpClass(cls): #初始化Appium LogUtil.my_log("setUpClass开启:" + nowtime).info("setUpClass开启...初始化Appium") cls.driver = DesireCaps.appium_desired_caps() # setup方法,初始化起点APP def setUp(self): LogUtil.my_log("setUpC开启:" + nowtime).info("setUp开启...初始化driver.launch_app()") self.driver.launch_app() self.Page_driver = Action(self.driver) @ddt.file_data("Test_Login_Ddt.yml") @ddt.unpack def test_login(self, phone, password): # 点击密码登录 self.Page_driver.click_btn(by="id", value="com.stoneenglish:id/quick_to_login") LogUtil.my_log("登陆日志:").info("点击选择密码登录") # 输入手机号 time.sleep(3) self.Page_driver.click_btn(by="id", value="com.stoneenglish:id/login_tel") time.sleep(3) self.Page_driver.send_keys(by="id", value="com.stoneenglish:id/login_tel", send=phone) LogUtil.my_log("登陆日志:").info("输入手机号") time.sleep(2) self.Page_driver.click_btn(by="id", value="com.stoneenglish:id/login_password") self.Page_driver.send_keys(by="id", value="com.stoneenglish:id/login_password", send=password) LogUtil.my_log("登陆日志:").info("输入密码") time.sleep(3) self.Page_driver.click_btn(by="id", value="com.stoneenglish:id/login_ok") self.Page_driver.is_toast_exist(expect="登录成功") self.Page_driver.assert_toast_result(expect="登录成功") # setup方法,初始化起点APP def tearDown(self): LogUtil.my_log("tearDown关闭:" + nowtime).info("tearDown关闭...driver.close_app()") self.driver.close_app() @classmethod def tearDownClass(cls): # 初始化Appium LogUtil.my_log("tearDownClassguanbi:" + nowtime).info("tearDownClass...关闭driver") cls.driver.quit()
def test_step(self): data = Data("../data/data.xls") run_list = data.run_list() print(run_list) print(run_list[0][0]) #根据测试用例执行步骤 #1、根据tc_id获取步骤列表 run_case = run_list[0][0] tc_id = run_case[TestSteps.STEP_TC_ID] steps = data.get_steps_by_tc_id(tc_id) #2、循环步骤列表,一步一步执行 for step in steps: print("执行步骤{}".format(step)) #2.3 执行appium,完成整体流程;setup tear #1.click operate = step[TestSteps.STEP_OPERATE] elements = step[TestSteps.STEP_ELEMENT_NAME] element = data.get_elements_by_element(step[TestSteps.STEP_TC_ID], elements) print(element) by = element[Elements.ELE_BY] value = element[Elements.ELE_VALUE] if operate == "click": #elements = step[TestSteps.STEP_ELEMENT_NAME] #element = data.get_elements_by_element(step[TestSteps.STEP_TC_ID],elements) #print(element) #by = element[Elements.ELE_BY] #value = element[Elements.ELE_VALUE] Action(self.driver).click_btn(by, value) #pass #2.text elif operate == "text": #1、获取by,value,send_value内容 send_value = step[TestSteps.STEP_DATA] #2、send_value内容转换,通过case data数据内容 data_input = run_case[CaseData.DATA_INPUT] print(data_input) #3、字符串转换成字典 #1.通过,分割得到username=13718418220 password=123456 res = {} #2.通过=分割 for i in str(data_input).split(","): c = i.split("=") res[c[0]] = c[1] #print(res) #4、send_value内容获取最后结果send send = res[send_value] #print(send) #5、send_keys发送 Action(self.driver).send_keys(by, value, send) #3.toast elif operate == "verify_toast": #1.使用get_toast获取toast具体信息 #text,case data期望结果 text = run_case[CaseData.DATA_EXPECT_RESULT] #调用方法获取toast toast = Action(self.driver).is_toast_exist(text) print(toast) #2.toast结果进行验证 #self.assertIn(text,toast) self.assertTrue(toast) time.sleep(2)