class CALC_CaseMethod: def __init__(self, dev, failkey): self.driver = dev self.test = Action(self.driver) self.Case = TestCase() self.failkey = failkey def case_if_base(self): """检查是否可以正常启动""" try: self.driver.activate_app(calc_pkg) except: self.test.start_activity(calc_pkg, calc_acivity) self.Case.assertTrue(self.test.wait_if_activity(calc_acivity), '启动 计算器 失败,超时5秒未检测到主界面') time.sleep(1) def case_get_add_result(self): self.case_if_base() int_a = random.randint(0, 9) int_b = random.randint(0, 9) time.sleep(0.2) self.test.find_byid(f'{calc_number_test}{int_a}').click() self.test.find_byid(calc_op_add).click() self.test.find_byid(f'{calc_number_test}{int_b}').click() self.test.find_byid(calc_eq).click() time.sleep(0.1) tmp = self.test.find_byid(calc_show_result).text if (int_a + int_b) != int(tmp): self.Case.fail(f'计算结果失败,{int_a} + {int_b} = {tmp}') time.sleep(0.5) self.test.find_byid(calc_clr).click() tmp = self.test.find_byid(calc_show_result).text if tmp not in '': self.Case.fail(f'计算结果未清除') time.sleep(0.5) def case_get_sub_result(self): self.case_if_base() int_a = random.randint(0, 9) int_b = random.randint(0, 9) time.sleep(0.2) self.test.find_byid(f'{calc_number_test}{int_a}').click() self.test.find_byid(calc_op_sub).click() self.test.find_byid(f'{calc_number_test}{int_b}').click() self.test.find_byid(calc_eq).click() time.sleep(0.1) tmp = self.test.find_byid(calc_show_result).text tmp_new = re.search('\d+', tmp).group(0) if int_a >= int_b: if (int_a - int_b) != int(tmp): self.Case.fail( f'计算结果失败 int_a >= int_b: {int_a} - {int_b} = {tmp}') else: try: int(tmp) self.Case.fail( f'计算结果失败 - not in tmp: {int_a} - {int_b} = {tmp}') except ValueError: pass if (int_b - int_a) != int(tmp_new): self.Case.fail(f'计算结果失败 tmp_new: {int_a} - {int_b} = {tmp}') time.sleep(0.5) self.test.find_byid(calc_clr).click() tmp = self.test.find_byid(calc_show_result).text if tmp not in '': self.Case.fail(f'计算结果未清除') time.sleep(0.5) def case_get_mul_result(self): self.case_if_base() int_a = random.randint(0, 9) int_b = random.randint(0, 9) time.sleep(0.2) self.test.find_byid(f'{calc_number_test}{int_a}').click() self.test.find_byid(calc_op_mul).click() self.test.find_byid(f'{calc_number_test}{int_b}').click() self.test.find_byid(calc_eq).click() time.sleep(0.1) tmp = self.test.find_byid(calc_show_result).text if (int_a * int_b) != int(tmp): self.Case.fail(f'计算结果失败: {int_a} * {int_b} = {tmp}') time.sleep(0.5) self.test.find_byid(calc_clr).click() tmp = self.test.find_byid(calc_show_result).text if tmp not in '': self.Case.fail(f'计算结果未清除') time.sleep(0.5) def case_get_div_result(self): self.case_if_base() int_a = random.randint(0, 9) int_b = random.randint(0, 9) time.sleep(0.2) self.test.find_byid(f'{calc_number_test}{int_a}').click() self.test.find_byid(calc_op_div).click() self.test.find_byid(f'{calc_number_test}{int_b}').click() self.test.find_byid(calc_eq).click() time.sleep(0.1) tmp = self.test.find_byid(calc_show_result).text try: tmp = float(tmp) except ValueError: if int_b != 0: self.Case.fail(f'计算结果失败 ValueError: {int_a} / {int_b} = {tmp}') else: return tmp = round(tmp, 2) if round(int_a / int_b, 2) != tmp: self.Case.fail(f'计算结果失败: {int_a} / {int_b} = {tmp}') time.sleep(0.5) self.test.find_byid(calc_clr).click() tmp = self.test.find_byid(calc_show_result).text if tmp not in '': self.Case.fail(f'计算结果未清除') time.sleep(0.5) def case_switch_UI_check(self): self.case_if_base() if self.test.find_byid(calc_number_1) is None: self.Case.fail("未找到‘1’按钮") if self.test.find_byid(calc_number_2) is None: self.Case.fail("未找到‘2’按钮") if self.test.find_byid(calc_number_3) is None: self.Case.fail("未找到‘3’按钮") if self.test.find_byid(calc_number_4) is None: self.Case.fail("未找到‘4’按钮") if self.test.find_byid(calc_number_5) is None: self.Case.fail("未找到‘5’按钮") if self.test.find_byid(calc_number_6) is None: self.Case.fail("未找到‘6’按钮") if self.test.find_byid(calc_number_7) is None: self.Case.fail("未找到‘7’按钮") if self.test.find_byid(calc_number_8) is None: self.Case.fail("未找到‘8’按钮") if self.test.find_byid(calc_number_9) is None: self.Case.fail("未找到‘9’按钮") if self.test.find_byid(calc_eq) is None: self.Case.fail("未找到‘=’按钮") if self.test.find_byid(calc_number_0) is None: self.Case.fail("未找到‘0’按钮") if self.test.find_byid(calc_dec_point) is None: self.Case.fail("未找到点按钮") if self.test.find_byid(calc_del) is None: self.Case.fail("未找到删除按钮") if self.test.find_byid(calc_op_div) is None: self.Case.fail("未找到‘÷’按钮") if self.test.find_byid(calc_op_mul) is None: self.Case.fail("未找到’ב按钮") if self.test.find_byid(calc_op_sub) is None: self.Case.fail("未找到“-”按钮") if self.test.find_byid(calc_op_add) is None: self.Case.fail("未找到“+”按钮") self.test.swipe_Left(600, 1) time.sleep(1) if self.test.find_byid(calc_advanced_INV) is None: self.Case.fail("未找到“INV”按钮") if self.test.find_byid(calc_advanced_DEG) is None: self.Case.fail("未找到“DEG”按钮") if self.test.find_byid(calc_advanced_pct) is None: self.Case.fail("未找到“%”按钮") if self.test.find_byid(calc_advanced_sin) is None: self.Case.fail("未找到“sin”按钮") if self.test.find_byid(calc_advanced_cos) is None: self.Case.fail("未找到“cos”按钮") if self.test.find_byid(calc_advanced_tan) is None: self.Case.fail("未找到“tan”按钮") if self.test.find_byid(calc_advanced_ln) is None: self.Case.fail("未找到“ln”按钮") if self.test.find_byid(calc_advanced_log) is None: self.Case.fail("未找到“log”按钮") if self.test.find_byid(calc_advanced_fact) is None: self.Case.fail("未找到“!”按钮") if self.test.find_byid(calc_advanced_pi) is None: self.Case.fail("未找到“π”按钮") if self.test.find_byid(calc_advanced_e) is None: self.Case.fail("未找到“e”按钮") if self.test.find_byid(calc_advanced_pow) is None: self.Case.fail("未找到“^”按钮") def case_calc_basic_button_check(self): self.case_if_base() for i in range(10): self.test.find_byid(f'{calc_number_test}{i}').click() time.sleep(1) result = self.test.find_byid(calc_show_formula).text if f'{i}' not in result: self.Case.fail(f"按钮‘{i}’功能未生效") else: self.test.find_byid(calc_del).click() time.sleep(1) self.test.find_byid(calc_dec_point).click() time.sleep(1) result = self.test.find_byid(calc_show_formula).text if '.' not in result: self.Case.fail("按钮‘.’功能未生效") else: self.test.find_byid(calc_del).click() time.sleep(1) self.test.find_byid(calc_number_0).click() time.sleep(1) result = self.test.find_byid(calc_show_formula).text if '0' in result: self.test.find_byid(calc_op_div).click() time.sleep(1) result = self.test.find_byid(calc_show_formula).text if '÷' not in result: self.Case.fail("按钮‘÷’功能未生效") else: self.test.find_byid(calc_del).click() time.sleep(1) self.test.find_byid(calc_op_mul).click() time.sleep(1) result = self.test.find_byid(calc_show_formula).text if '×' not in result: self.Case.fail("按钮‘×’功能未生效") else: self.test.find_byid(calc_del).click() time.sleep(1) self.test.find_byid(calc_op_sub).click() time.sleep(1) result = self.test.find_byid(calc_show_formula).text if '−' not in result: self.Case.fail("按钮‘-’功能未生效") else: self.test.find_byid(calc_del).click() time.sleep(1) self.test.find_byid(calc_op_add).click() time.sleep(1) result = self.test.find_byid(calc_show_formula).text if '+' not in result: self.Case.fail("按钮‘+’功能未生效") else: self.test.find_byid(calc_del).click() time.sleep(1) self.test.find_byid(calc_eq).click() time.sleep(1) result = self.test.find_byid(calc_show_result).text if '0' in result: more_list = self.test.find_list_byclass(ImageButton) for more in more_list: str_tmp = more.get_attribute('content-desc') if '更多选项' in str_tmp: more.click() time.sleep(1) break text_button_list = self.test.find_list_byclass(TextView) for t in text_button_list: str_tmp = t.text if '在结果中显示前导数' in str_tmp: t.click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) for text in text_list: str_tmp = text.text if '0 (精确)' not in str_tmp: self.Case.fail("结果显示错误") else: self.test.find_byclass(Button, '关闭').click() time.sleep(1) break break more_list = self.test.find_list_byclass(ImageButton) for more in more_list: str_tmp = more.get_attribute('content-desc') if '更多选项' in str_tmp: more.click() time.sleep(1) break text_button_list = self.test.find_list_byclass(TextView) for t in text_button_list: str_tmp = t.text if '以分数形式显示结果' in str_tmp: t.click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) for text in text_list: str_tmp = text.text if '0' not in str_tmp: self.Case.fail("结果显示错误") else: self.test.find_byclass(Button, '关闭').click() time.sleep(1) break break def case_clac_advance_button_check(self): self.case_if_base() self.test.swipe_Left(600, 1) time.sleep(1) INV = self.test.find_byid(calc_advanced_INV) INV.click() time.sleep(1) btext_list = self.test.find_list_byclass(Button) b_flag = True for btext in btext_list: str_tmp = btext.text if f'sin⁻¹' == f'sin' and f'sin' in str_tmp: self.Case.fail("未出现sin⁻¹按钮") b_flag = False continue if f'cos⁻¹' == f'cos' and f'cos' in str_tmp: self.Case.fail("未出现cos⁻¹按钮") b_flag = False continue if f'tan⁻¹' == f'tan' and f'tan' in str_tmp: self.Case.fail("未出现tan⁻¹按钮") b_flag = False continue if f'eˣ' == f'ln' and f'ln' in str_tmp: self.Case.fail("未出现eˣ按钮") b_flag = False continue if f'10ˣ' == f'log' and f'log' in str_tmp: self.Case.fail("未出现10ˣ按钮") b_flag = False continue if f'x²' == f'√' and f'√' in str_tmp: self.Case.fail("未出现x²按钮") b_flag = False break if not b_flag: self.Case.fail("INV 功能不完整") self.test.find_byid(calc_advanced_DEG).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) t_flag = False for t in text_list: str_tmp = t.text if 'DEG' in str_tmp: t_flag = True break if not t_flag: self.Case.fail("DEG 角度切换失败") self.test.find_byid(calc_advanced_DEG).click() time.sleep(1) self.test.find_byid(calc_advanced_pct).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if '%' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("% 功能失效") self.test.find_byid(calc_advanced_arcsin).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if 'sin⁻¹(' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("sin⁻¹按钮失效") self.test.find_byid(calc_advanced_arccos).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if 'cos⁻¹(' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("cos⁻¹按钮失效") self.test.find_byid(calc_advanced_arctan).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if 'tan⁻¹(' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("tan⁻¹按钮失败") self.test.find_byid(calc_advanced_exp).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if 'exp(' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("eˣ按钮失效") self.test.find_byid(calc_advacnced_tPow).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if '10^' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("10ˣ按钮失效") self.test.find_byid(calc_advanced_fact).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if '!' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("!按钮失效") self.test.find_byid(calc_advanced_pi).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if 'π' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("π按钮失效") self.test.find_byid(calc_advanced_e).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if 'e' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("e按钮失效") self.test.find_byid(calc_advanced_pow).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if '^' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("^按钮失效") self.test.find_byid(calc_advanced_lparen).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if '^(' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("(按钮失效") self.test.find_byid(calc_advanced_rparen).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if ')' in str_tmp: text_flag = True break if not text_flag: self.Case.fail(")按钮失效") self.test.find_byid(calc_advanced_sqr).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if ')²' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("x²按钮失效") self.test.find_byid(calc_advanced_INV).click() time.sleep(1) self.test.find_byid(calc_advanced_sin).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if 'sin(' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("sin按钮失效") self.test.find_byid(calc_advanced_cos).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if 'cos(' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("cos按钮失效") self.test.find_byid(calc_advanced_tan).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if 'tan(' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("tan按钮失效") self.test.find_byid(calc_advanced_ln).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if 'ln(' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("ln按钮失效") self.test.find_byid(calc_advanced_log).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if 'log(' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("log按钮失效") self.test.find_byid(calc_advanced_sqrt).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if '√' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("√按钮失效")
class Clock_CaseMethod: def __init__(self, dev, failkey): self.driver = dev self.test = Action(self.driver) self.Case = TestCase() self.failkey = failkey def case_if_base(self, Skip=False): """设置基础,检查是否可以正常启动""" self.driver.activate_app(clock_pkg) if not Skip: if self.test.wait_if_activity(Permissions_Activity): self.test.find_byid(Permission_allow_button).click() time.sleep(1) self.Case.assertTrue(self.test.wait_if_activity(clock_activity), '启动 时钟 失败,超时5秒未检测到主界面') self.test.set_PORTRAIT() time.sleep(1) def case_check_date_time(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.case_if_base(True) time.sleep(1) self.test.find_byacc('时钟').click() time.sleep(0.5) time_test = TimeUtils.str_A_P_M_time() tmp_time = self.test.find_byid(clock_show_time).text tmp_date = self.test.find_byid(clock_show_data).text if tmp_time not in time_test: self.Case.fail( f'失败,请检查是否与北京时间相差过大,若差1分钟则不是问题,手机时间 : {tmp_time},当前时间 : {time_test}' ) if tmp_date not in TimeUtils.str_date_week(): self.Case.fail( f'失败,请检查是否与北京时间相差过大,手机日期 : {tmp_date},当前日期 : {TimeUtils.str_date_week()}' ) def case_set_alarm(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.case_if_base(True) time.sleep(1) self.test.find_byacc('闹钟').click() time.sleep(0.5) self.test.find_byacc('展开闹钟').click() time.sleep(1) self.test.find_byid(clock_del_alarm).click() time.sleep(0.2) self.test.find_byacc('展开闹钟').click() time.sleep(0.2) for text_acc in ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']: tmp = self.test.find_byacc(text_acc) if tmp.get_attribute('checked') == 'false': tmp.click() time.sleep(0.2) time.sleep(0.2) self.test.find_byid_list(clock_show_time)[0].click() time.sleep(0.5) if self.test.find_byid(clock_set_time_simulation) is None: self.Case.fail(f'设定闹钟的 模拟时钟 刻度盘未显示') if TimeUtils.is_AM(): self.test.find_byid(clock_set_time_am).click() else: self.test.find_byid(clock_set_time_pm).click() self.test.find_byid(clock_set_time_mode).click() time.sleep(0.2) self.test.find_byid(clock_set_time_hour).send_keys( TimeUtils.get_hour()) self.test.find_byid(clock_set_time_minute).send_keys( TimeUtils.get_minute() + 2) self.test.find_byclass(Button, '确定').click() isFlga = False actions = TouchAction(self.driver) for x in range(122): actions.press(x=(self.test.get_windows_width() * 0.5), y=(self.test.get_windows_height() * 0.15)).release().perform() tmp = self.test.find_byid(clock_set_alarm_state) if tmp is not None: locat = tmp.location actions.long_press(x=locat['x'], y=locat['y']) actions.move_to(x=(self.test.get_windows_width() * 0.9), y=locat['y']) actions.release().perform() isFlga = True break time.sleep(1) self.driver.press_keycode(4, 0, 0) if not isFlga: self.Case.fail(f'闹钟在2分钟内未响,测试失败') self.Case.assertTrue(self.test.wait_if_activity(clock_activity), '闹钟 关闭 失败,超时5秒未检测到主界面') time.sleep(1) def case_check_timer_input(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.case_if_base(True) time.sleep(1) self.test.find_byacc('定时器').click() time.sleep(0.5) for x in range(10): self.test.find_byid(f'{clock_timer_x}{x}').click() time.sleep(0.1) tmp_time = self.test.find_byid(clock_show_timer).text if f'0{x}秒' not in tmp_time: self.Case.fail(f'定时器设定 {x} 秒失败') self.test.find_byid(clock_del_timer_time).click() time.sleep(0.2) def case_set_timer(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.case_if_base(True) time.sleep(1) self.test.find_byacc('定时器').click() time.sleep(0.5) self.test.find_byid(clock_timer_6).click() tmp_time = self.test.find_byid(clock_show_timer).text if f'06秒' not in tmp_time: self.Case.fail(f'定时器设定 6 秒失败') self.test.find_byid(clock_start_timer).click() time.sleep(1) self.test.find_byid(clock_start_timer).click() time.sleep(1) text_time = self.test.find_byid(clock_show_timer_started).text try: if 6 > int(text_time) > 4: self.Case.fail(f'定时器计时失败,6秒计时器,剩余{text_time}') except ValueError: self.Case.fail(f'定时器显示失败,显示为:{text_time}') time.sleep(0.5) self.test.find_byid(clock_del_timer).click() time.sleep(0.5) self.Case.assertIsNone(self.test.find_byid(clock_start_timer), '定时器未删除') time.sleep(1) def case_check_Stopwatch(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.case_if_base(True) time.sleep(1) self.test.find_byacc('秒表').click() time.sleep(0.5) self.Case.assertIsNotNone(self.test.find_byid(clock_show_stopwatch), '秒表 计数盘 未显示') tmp = self.test.find_byid(clock_show_stopwatch_time) self.test.find_byid(clock_start_timer).click() time.sleep(3) self.test.find_byid(clock_start_timer).click() try: tmp_time = 0 """ for x in range(10): tmp = self.test.find_byid(clock_show_stopwatch_time) if tmp is not None: tmp_time = int(tmp.text) """ tmp_time = int(tmp.text) if tmp_time == 0: self.Case.fail(f'未获取到,秒表时间') except ValueError: self.Case.fail(f'秒表时间显示错误,计时约三秒,{tmp_time}') if tmp_time < 2.9: self.Case.fail(f'秒表时间显示错误,计时约三秒,未超过2.9秒:时间为:{tmp_time}') self.test.find_byacc('重置').click() time.sleep(1) def case_check_clock_UI_switch(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.case_if_base(True) mode_list = self.test.find_list_byclass(TextView) for m in mode_list: str_tmp = m.text if '时钟' in str_tmp: m.click() time.sleep(1) break detail_clock = self.test.find_byid(clock_show_time) if detail_clock is None: self.Case.fail("未找到当前详细时间,进入的页面非时钟页面") cities = self.test.find_list_byclass(ImageButton) city_flag = False for city in cities: str_tmp = city.get_attribute('content-desc') if '城市' in str_tmp: city_flag = True break if not city_flag: self.Case.fail("未找到时区(城市)选择按钮,进入的页面非时钟页面") self.test.swipe_Right(600, 1) time.sleep(1) switch_list = self.test.find_list_byclass(Switch) if switch_list is None: alarm_list = self.test.find_list_byclass(TextView) alarm_flag = False for alarm in alarm_list: str_tmp = alarm.text if '没有闹钟' in str_tmp: alarm_flag = True break if not alarm_flag: self.Case.fail("未找到闹钟和没有闹钟提示,进入的页面非闹钟页面") add_list = self.test.find_list_byclass(ImageButton) add_flag = False for add in add_list: str_tmp = add.get_attribute('content-desc') if '添加闹钟' in str_tmp: add_flag = True break if not add_flag: self.Case.fail("未找到添加闹钟的按钮,切换的页面非闹钟页面") self.test.swipe_Left(600, 1) time.sleep(1) self.test.swipe_Left(600, 1) time.sleep(1) timer_text = self.test.find_byid(clock_show_timer) if timer_text is None: self.Case.fail("未找到定时器时刻表,切换的页面非定时器页面") del_list = self.test.find_list_byclass(ImageButton) del_flag = False for d in del_list: str_tmp = d.get_attribute('content-desc') if '删除' in str_tmp: del_flag = True break if not del_flag: self.Case.fail("未找到定时器删除按钮,切换的页面非定时器页面") self.test.swipe_Left(600, 1) time.sleep(1) stopwatch_veiw = self.test.find_byid(clock_stopwatch_veiw) if stopwatch_veiw is None: self.Case.fail("未找到秒表面板,切换的为非秒表页面") start_stop_button_list = self.test.find_list_byclass(ImageButton) start_flag = False for s in start_stop_button_list: str_tmp = s.get_attribute('content-desc') if '开始' in str_tmp: start_flag = True break if not start_flag: self.Case.fail("未找到秒表开始计时的按钮,切换的为非秒表页面") def case_clock_set_city_time(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.case_if_base(True) mode_list = self.test.find_list_byclass(TextView) for m in mode_list: str_tmp = m.text if '时钟' in str_tmp: m.click() time.sleep(1) break city_button = self.test.find_list_byclass(ImageButton) city_flag = False for city in city_button: str_tmp = city.get_attribute('content-desc') if '城市' in str_tmp: city.click() time.sleep(2) city_flag = True break if not city_flag: self.Case.fail("未找到城市按钮,确认当前页面为时钟页面") city_check_list = self.test.find_list_byclass(CheckBox) for city in city_check_list: str_tmp = city.get_attribute('content-desc') if '阿比让' in str_tmp: city.click() time.sleep(1) break back_list = self.test.find_list_byclass(ImageButton) for back in back_list: str_tmp = back.get_attribute('content-desc') if '转到上一层级' in str_tmp: back.click() time.sleep(2) break textview_list = self.test.find_list_byclass(TextView) city_flag = False for t in textview_list: str_tmp = t.text if '阿比让' in str_tmp: city_flag = True break if not city_flag: self.Case.fail("未找到选中的城市") city_button = self.test.find_list_byclass(ImageButton) city_flag = False for city in city_button: str_tmp = city.get_attribute('content-desc') if '城市' in str_tmp: city.click() time.sleep(2) city_flag = True break if not city_flag: self.Case.fail("未找到城市按钮,确认当前页面为时钟页面") city_check_list = self.test.find_list_byclass(CheckBox) for city in city_check_list: str_tmp = city.get_attribute('content-desc') if '阿比让' in str_tmp: city.click() time.sleep(1) break back_list = self.test.find_list_byclass(ImageButton) for back in back_list: str_tmp = back.get_attribute('content-desc') if '转到上一层级' in str_tmp: back.click() time.sleep(2) break def case_back_and_home_out_of_clock(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.case_if_base(True) mode_list = self.test.find_list_byclass(TextView) for m in mode_list: str_tmp = m.text if '时钟' in str_tmp: m.click() time.sleep(1) break self.driver.press_keycode(KEY_BACK, 0, 0) time.sleep(1) if self.test.wait_if_activity(clock_activity): self.Case.fail("在时钟界面按返回键无法退出界面") else: self.case_if_base(True) self.driver.press_keycode(KEY_HOME, 0, 0) time.sleep(1) if self.test.wait_if_activity(clock_activity): self.Case.fail("在时钟界面按HOME按钮无法退出界面") def case_preview_and_play_timer_sounds(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.case_if_base(True) mode_list = self.test.find_list_byclass(TextView) for m in mode_list: str_tmp = m.text if '定时器' in str_tmp: m.click() time.sleep(1) break more_list = self.test.find_list_byclass(ImageView) for more in more_list: str_tmp = more.get_attribute('content-desc') if '更多选项' in str_tmp: more.click() time.sleep(1) break set_list = self.test.find_list_byclass(TextView) for s in set_list: str_tmp = s.text if '设置' in str_tmp: s.click() time.sleep(1) break for i in range(3): self.test.swipe_Down(600, 1) time.sleep(0.1) setting_list = self.test.find_list_byclass(TextView) for sets in setting_list: str_tmp = sets.text if '定时器提示音' in str_tmp: sets.click() time.sleep(3) break sounds_list = self.test.find_list_byclass(TextView) sound_flag = False for sound in sounds_list: str_tmp = sound.text if '静音' in str_tmp: sound.click() time.sleep(2) sound_flag = True continue if sound_flag: sound.click() time.sleep(2) for i in range(3): self.test.swipe_Down(600, 1) time.sleep(0.2) sound_list = self.test.find_list_byclass(TextView) for s in sound_list: s.click() time.sleep(2) if not sound_flag: self.Case.fail("未找到任何铃声") def case_set_and_check_timer_sound(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.case_if_base(True) mode_list = self.test.find_list_byclass(TextView) for m in mode_list: str_tmp = m.text if '定时器' in str_tmp: m.click() time.sleep(1) break more_list = self.test.find_list_byclass(ImageView) for more in more_list: str_tmp = more.get_attribute('content-desc') if '更多选项' in str_tmp: more.click() time.sleep(1) break set_list = self.test.find_list_byclass(TextView) for s in set_list: str_tmp = s.text if '设置' in str_tmp: s.click() time.sleep(1) break for i in range(3): self.test.swipe_Down(600, 1) time.sleep(0.1) setting_list = self.test.find_list_byclass(TextView) for sets in setting_list: str_tmp = sets.text if '定时器提示音' in str_tmp: sets.click() time.sleep(3) break sounds_list = self.test.find_list_byclass(TextView) for sound in sounds_list: str_tmp = sound.text if 'Argon' in str_tmp: sound.click() time.sleep(2) break back_list = self.test.find_list_byclass(ImageButton) for back in back_list: str_tmp = back.get_attribute('content-desc') if '转到上一层级' in str_tmp: back.click() time.sleep(1) break setting_list = self.test.find_list_byclass(TextView) sound_check = False for sets in setting_list: str_tmp = sets.text if 'Argon' in str_tmp: sound_check = True break if not sound_check: self.Case.fail("定时器提示音设置失败") back_list = self.test.find_list_byclass(ImageButton) for back in back_list: str_tmp = back.get_attribute('content-desc') if '转到上一层级' in str_tmp: back.click() time.sleep(1) break self.test.find_byid(clock_timer_6).click() time.sleep(1) image_list = self.test.find_list_byclass(ImageButton) for i in image_list: str_tmp = i.get_attribute('content-desc') if '开始' in str_tmp: i.click() time.sleep(2) break for i in range(5): time.sleep(3) button_list = self.test.find_list_byclass(Button) for b in button_list: str_tmp = b.text if '删除' in str_tmp: b.click() time.sleep(2) break if self.test.find_byid(clock_show_timer) is None: self.Case.fail("删除定时器失败") def case_timer_add_one_minute_check(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.case_if_base(True) mode_list = self.test.find_list_byclass(TextView) for m in mode_list: str_tmp = m.text if '定时器' in str_tmp: m.click() time.sleep(1) break one_button = self.test.find_byid(clock_timer_1) for i in range(6): one_button.click() time.sleep(1) for i in range(4): self.test.find_byid(clock_del_timer_time).click() time.sleep(1) image_list = self.test.find_list_byclass(ImageButton) for i in image_list: str_tmp = i.get_attribute('content-desc') if '开始' in str_tmp: i.click() time.sleep(2) break add_list = self.test.find_list_byclass(Button) for adds in add_list: str_tmp = adds.text if '+1:00' in str_tmp: adds.click() time.sleep(1) break button_list = self.test.find_list_byclass(Button) for b in button_list: str_tmp = b.text if '删除' in str_tmp: b.click() time.sleep(2) break
class Gallery_CaseMethod: def __init__(self, dev, failkey): self.driver = dev self.test = Action(self.driver) self.Case = TestCase() self.failkey = failkey def case_if_base(self): """检查是否可以正常启动""" self.driver.activate_app(gallery_Pkg) self.Case.assertTrue(self.test.wait_if_activity(gallery_activity), '启动图库失败,超时5秒未检测到主界面') def case_swipe_view(self): self.case_if_base() time.sleep(1) root_view = self.test.find_byid(gallery_root_view) root_view.click() self.test.swipe_Right(200, 3) self.test.swipe_Left(200, 3) def case_swipe_L_view(self): self.case_if_base() time.sleep(1) self.test.find_byid(gallery_root_view).click() time.sleep(2) self.test.find_byid(action_bar_spinner).click() self.test.find_byclass(TextView, '幻灯片视图').click() self.test.swipe_Right(200, 3) self.test.find_byid(photopage_bottom).click() def case_get_picture_date(self): """返回 hms 时分秒int时间戳,仅相机拍照""" self.case_if_base() self.test.find_byid(gallery_root_view).click() time.sleep(2) self.test.find_byid(action_bar_spinner).click() self.test.find_byclass(TextView, '幻灯片视图').click() time.sleep(5) self.test.find_byacc('更多选项').click() tmp = self.test.find_list_byid(gallery_details_title, '详细信息') tmp.click() tmp_text = self.test.find_list_byid(gallery_picture_details_text, '标题').text tmp_time = int(tmp_text.split('_')[2]) return tmp_time def case_get_picture_size(self): """ 返回照片的尺寸,[int , int] :return: tmp_width , tmp_hight """ self.case_if_base() self.test.find_byid(gallery_root_view).click() time.sleep(2) self.test.find_byid(action_bar_spinner).click() self.test.find_byclass(TextView, '幻灯片视图').click() time.sleep(5) self.test.find_byacc('更多选项').click() tmp = self.test.find_list_byid(gallery_details_title, '详细信息') tmp.click() tmp_hight = self.test.find_list_byid(gallery_picture_details_text, '高度').text #width tmp_hight = int(tmp_hight.split(' ')[1]) tmp_width = self.test.find_list_byid(gallery_picture_details_text, '宽度').text # width tmp_width = int(tmp_width.split(' ')[1]) return tmp_width, tmp_hight def case_get_picture_flash(self): """ 返回照片是否使用闪光灯 :return: boolean """ self.case_if_base() self.test.find_byid(gallery_root_view).click() time.sleep(2) self.test.find_byid(action_bar_spinner).click() self.test.find_byclass(TextView, '幻灯片视图').click() time.sleep(5) self.test.find_byacc('更多选项').click() tmp = self.test.find_list_byid(gallery_details_title, '详细信息') tmp.click() tmp = self.test.find_list_byid(gallery_picture_details_text, '闪光灯').text #width if "未使用" in tmp: return False return True def case_get_title(self): """ 返回照片名称 :return: name(str) """ self.case_if_base() self.test.find_byid(gallery_root_view).click() time.sleep(2) self.test.find_byid(action_bar_spinner).click() self.test.find_byclass(TextView, '幻灯片视图').click() time.sleep(5) self.test.find_byacc('更多选项').click() tmp = self.test.find_list_byid(gallery_details_title, '详细信息') tmp.click() tmp_name = self.test.find_list_byid(gallery_picture_details_text, '标题').text #width return tmp_name def case_play_item(self): """预览第一张照片或者视频""" self.case_if_base() self.test.find_byid(gallery_root_view).click() time.sleep(2) self.test.find_byid(action_bar_spinner).click() self.test.find_byclass(TextView, '幻灯片视图').click() time.sleep(5) actions = TouchAction(self.driver) actions.press(x=self.test.get_windows_width() / 2, y=self.test.get_windows_height() / 2).release().perform() time.sleep(1) actions.press(x=self.test.get_windows_width() / 2, y=self.test.get_windows_height() / 2).release().perform() time.sleep(5)