def keyboard(key): """小键盘 q w e等字母""" screen = BasePage().get_window_size() keyboard_list = [ 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', 'a', 's', 'd', 'f', 'g', 'h', 'd', 'k', 'l', 'capslock', 'z', 'x', 'c', 'v', 'b', 'n', 'm', "backspace", ',', '.', '-', 'blank', "'", 'enter' ] if key.lower() in keyboard_list: i = keyboard_list.index(key.lower()) if i < 10: ClickBounds().click_bounds( 0.08888 * screen[0] * (i + 0.5) + 0.011 * screen[0] * (i + 1), 1365) elif i in range(10, 19): ClickBounds().click_bounds((0.08888 + 0.011) * screen[0] * (i - 9), 1515) # i +1-10 elif i in range(19, 28): ClickBounds().click_bounds( (0.08888 + 0.011) * screen[0] * (i - 18), 1680) # i+1-19 else: # 28--32 if i > 30: ClickBounds().click_bounds(0.08888 * screen[0] * (i - 25 + 0.5) + 0.011 * screen[0] * (i - 23), 1840) # else: ClickBounds().click_bounds( 0.08888 * screen[0] * (i - 28 + 0.5) + 0.011 * screen[0] * (i - 26), 1840) """小键盘
def drop_down_button(self, var): """正确选项后答对率 下拉按钮""" loc = self.get_element_location(var) size = self.get_element_size(var) x = loc[0] + size[0] // 2 y = loc[1] + size[1] - 10 ClickBounds().click_bounds(x, y)
def games_keyboard(key): """小键盘 q w e等字母""" screen = BasePage().get_window_size() keyboard = ['q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'capslock', 'z', 'x', 'c', 'v', 'b', 'n', 'm', "backspace", ',', '.', '-', 'blank', "'", 'enter'] if key.lower() in keyboard: i = keyboard.index(key.lower()) if i < 10: ClickBounds().click_bounds(0.08888 * screen[0] * (i+0.5) + 0.011 * screen[0]*(i+1), 1010) elif i in range(10, 19): ClickBounds().click_bounds((0.08888+0.011) * screen[0] * (i - 9), 1085) # i +1-10 elif i in range(19, 27): ClickBounds().click_bounds((0.08888+0.011) * screen[0] * (i - 18), 1158) # i+1-19 else: # 27--32 if i > 30: ClickBounds().click_bounds(0.08888 * screen[0] * (i-25+0.5) + 0.011 * screen[0]*(i - 23), 1240) # else: ClickBounds().click_bounds(0.08888 * screen[0] * (i - 28 + 0.5) + 0.011 * screen[0] * (i - 26), 1240) # if key.lower() in keyboard: # i = keyboard.index(key.lower()) # print(key.lower()) # if i < 10: # ClickBounds().click_bounds(90 * (i + 0.5) + 15 * (i + 1), 1385) # elif i in range(10, 19): # ClickBounds().click_bounds(105 * (i - 9), 1535) # i +1-10 # elif i in range(19, 28): # ClickBounds().click_bounds(105 * (i - 18), 1685) # i+1-19 # else: # 28--32 # if i > 30: # ClickBounds().click_bounds(90 * (i - 25 + 0.5) + 15 * (i - 23), 1835) # # else: # ClickBounds().click_bounds(90 * (i - 28 + 0.5) + 15 * (i - 26), 1835) """小键盘
def click_block(self): """点击页面空白区域""" ClickBounds().click_bounds(540, 300)
def __init__(self): self.bounds = ClickBounds() self.result = ResultPage() self.get = GetAttribute() self.key = Keyboard()
class ChoiceWordCloze(BasePage): """选词填空""" def __init__(self): self.bounds = ClickBounds() self.result = ResultPage() self.get = GetAttribute() self.key = Keyboard() @teststeps def wait_check_page(self): """以“title:选词填空”的xpath-index为依据""" locator = (By.XPATH, "//android.widget.TextView[contains(@text,'选词填空')]") try: WebDriverWait(self.driver, 20, 0.5).until(lambda x: x.find_element(*locator)) return True except: return False @teststeps def wait_check_play_page(self): """以“rate”的ID为依据""" locator = (By.XPATH, "//android.widget.TextView[contains(@resource-id," + self.id_type() + "rate)]") try: WebDriverWait(self.driver, 20, 0.5).until(lambda x: x.find_element(*locator)) return True except: return False @teststep def rate(self): """获取作业数量""" rate = self.driver\ .find_element_by_id(self.id_type() + "rate").text return rate @teststep def font_middle(self): """第一个Aa""" ele = self.driver \ .find_element_by_id(self.id_type() + "font_middle") return ele @teststep def font_large(self): """第二个Aa""" ele = self.driver \ .find_element_by_id(self.id_type() + "font_large") return ele @teststep def font_great(self): """第三个Aa""" ele = self.driver \ .find_element_by_id(self.id_type() + "font_great") return ele @teststep def prompt(self): """提示词""" self.driver\ .find_element_by_id(self.id_type() + "prompt").click() @teststep def bounds_prompt(self): """提示词按钮""" ele = self.driver\ .find_elements_by_xpath("//android.widget.TextView[contains(@index,0)]")[1] return ele @teststep def prompt_content(self): """提示词内容""" ele = self.driver \ .find_elements_by_xpath("//android.widget.TextView[contains(@index,0)]")[1].text return ele @teststep def click_blank(self): """点击页面 提示词弹框 以外空白处,弹框消失""" self.bounds.click_bounds(67.5, 1119.5) time.sleep(1) @teststep def time(self): """获取作业时间""" ele = self.driver \ .find_element_by_id(self.id_type() + "time").text return ele # 查看答案 页面 @teststeps def wait_check_detail_page(self): """以“answer”的ID为依据""" locator = (By.XPATH, "//android.widget.TextView[contains(@resource-id," + self.id_type() + "tv_answer)]") try: WebDriverWait(self.driver, 20, 0.5).until(lambda x: x.find_element(*locator)) return True except: return False @teststep def content_value(self): """获取整个 外框元素""" ele = self.driver\ .find_element_by_id(self.id_type() + "tb_content") return ele @teststeps def content_desc(self): """点击输入框,激活小键盘""" content = self.get.get_description(self.content_value()) item_x = re.match(".*\[(.*)\].*\[", content) # x值 item_y = re.match(".*\[(.*)\].*", content) # y值 x = item_x.group(1).split(',') # 所有输入框y值的列表 y = item_y.group(1).split(',') # 所有输入框x值的列表 return x, y @teststeps def get_result(self): """点击输入框,激活小键盘""" content = self.get.get_description(self.content_value()) value = re.match("\\[(.+?)\\]", content) # answer answer = value.group(1).split(',') # 所有输入框值的列表 print('正确答案:', answer) self.click_blank() return answer @teststeps def choice_word_filling(self): """《选词填空》 游戏过程""" if self.wait_check_page(): # 页面检查点 if self.wait_check_play_page(): timestr = [] self.prompt() # 右上角 提示词 time.sleep(1) content = self.prompt_content() # 取出提示内容 self.click_blank() # 点击空白处 弹框消失 word_list = content.split(' ') # 取出单词列表 print('待输入的单词:', word_list) self.font_operate() # Aa文字大小切换按钮 切换 及状态统计 rate = self.rate() for i in range(int(rate)): Homework().rate_judge(rate, i) # 测试当前rate值显示是否正确 Homework().next_button_operate('false') # 下一题 按钮 状态判断 加点击 if i == 0: # 获取第一个输入框的坐标,点击激活小键盘 item = self.content_desc() loc = self.get_element_location(self.content_value()) # 文章元素左上角 顶点坐标 x = float(item[0][i]) + loc[0]+55.0 # 55.0为点击输入框中心点的偏移量 y = float(item[1][i]) + loc[1] self.driver.tap([(x, y)]) # 点击激活输入框 else: self.key.games_keyboard('enter') # 点击回车键进入下一题 word = word_list[i] # 单词 print('study_word:', word) if len(word_list) >= int(rate): for index in range(len(word)): if index == 4: self.key.games_keyboard('capslock') # 点击键盘 切换到 大写字母 self.key.games_keyboard(word[index].upper()) # 点击键盘对应 大写字母 self.key.games_keyboard('capslock') # 点击键盘 切换到 小写字母 else: self.key.games_keyboard(word[index]) # 点击键盘对应字母 else: self.key.games_keyboard('a') # 点击键盘对应字母 timestr.append(self.time()) # 统计每小题的计时控件time信息 Homework().next_button_operate('true') # 下一题 按钮 状态判断 加点击 Homework().now_time(timestr) # 判断游戏界面 计时功能控件 是否在计时 print('==================================================') return rate @teststeps def check_detail_page(self, rate, homework_title, game_title): """查看答案页面面""" if self.result.wait_check_result_page(): # 结果页检查点 self.result.check_result_button() # 结果页 查看答案 按钮 if self.result.wait_check_detail_page(): # 页面检查点 print('查看答案页面:') item = self.get_result() print('excel-opeate:') for i in range(len(item)): print('----------------------') ExcelUtil().data_write(rate, homework_title, game_title, item[i]) self.result.back_up_button() @teststeps def font_operate(self): """Aa文字大小切换按钮 状态判断 及 切换操作""" x = [] y = [] middle = self.font_middle() # first large = self.font_large() # second great = self.font_great() # third i = 0 j = 0 while i < 3: bounds = self.content_desc() # 获取输入框坐标 print(self.get.get_checked(middle), self.get.get_checked(large), self.get.get_checked(great)) if self.get.get_checked(middle) == 'false': if self.get.get_checked(large) == 'false': x.insert(2, bounds[0][0]) y.insert(2, bounds[1][0]) print('当前选中的Aa按钮为第3个:', bounds[0][0], bounds[1][0]) j = 3 else: if self.get.get_checked(large) == 'true': x.insert(1, bounds[0][0]) y.insert(1, bounds[1][0]) print('当前选中的Aa按钮为第2个:', bounds[0][0], bounds[1][0]) j = 2 else: x.insert(0, bounds[0][0]) y.insert(0, bounds[1][0]) print('当前选中的Aa按钮为第1个:', bounds[0][0], bounds[1][0]) j = 1 if j == 1: large.click() elif j == 2: great.click() else: middle.click() i += 1 print('--------------------------------------------') time.sleep(2) if not float(y[2]) > float(y[1]) > float(y[0]): print('❌❌❌ Error - Aa文字大小切换按钮:', y) print('==============================================')
def click_block(self): ClickBounds().click_bounds(540, 200)
def choose_album_mul(self): """5.1 模拟器 选择相册370,720""" print('选择相册') ClickBounds().click_bounds(560, 270)
def choose_album(self): """选择相册370,720""" ClickBounds().click_bounds(320, 500)
def __init__(self): self.bounds = ClickBounds() self.result = ResultPage()
class ChoiceWordCloze(BasePage): """选词填空""" def __init__(self): self.bounds = ClickBounds() self.result = ResultPage() @teststeps def wait_check_page(self): """以“title:选词填空”的xpath-index为依据""" locator = (By.XPATH, "//android.widget.TextView[contains(@text,'选词填空')]") try: WebDriverWait(self.driver, 20, 0.5).until(lambda x: x.find_element(*locator)) return True except: return False @teststep def rate(self): """获取作业数量""" rate = self.driver\ .find_element_by_id("com.vanthink.student.debug:id/rate").text return rate @teststep def font_middle(self): """第一个Aa""" ele = self.driver \ .find_element_by_id("com.vanthink.student.debug:id/font_middle") return ele @teststep def font_large(self): """第二个Aa""" ele = self.driver \ .find_element_by_id("com.vanthink.student.debug:id/font_large") return ele @teststep def font_great(self): """第三个Aa""" ele = self.driver \ .find_element_by_id("com.vanthink.student.debug:id/font_great") return ele @teststep def prompt(self): """提示词""" self.driver\ .find_element_by_id("com.vanthink.student.debug:id/prompt").click() @teststep def bounds_prompt(self): """提示词按钮""" ele = self.driver\ .find_elements_by_xpath("//android.widget.TextView[contains(@index,0)]")[1] return ele @teststep def prompt_content(self): """提示词内容""" ele = self.driver \ .find_elements_by_xpath("//android.widget.TextView[contains(@index,0)]")[1].text return ele @teststep def click_blank(self): """点击页面 提示词弹框 以外空白处,弹框消失""" self.bounds.click_bounds(67.5, 1119.5) @teststep def time(self): """获取作业时间""" ele = self.driver \ .find_element_by_id("com.vanthink.student.debug:id/time").text return ele @teststep def back_up_button(self): """以“返回按钮”的class name为依据""" time.sleep(2) self.driver \ .find_element_by_class_name("android.widget.ImageButton") \ .click() @teststeps def content_desc(self): """点击输入框,激活小键盘""" content = self.driver \ .find_element_by_id("com.vanthink.student.debug:id/tb_content").get_attribute('contentDescription') item_x = re.match(".*\[(.*)\].*\[", content) # x值 item_y = re.match(".*\[(.*)\].*", content) # y值 x = item_x.group(1).split(',') # 所有输入框y值的列表 print(x) y = item_y.group(1).split(',') # 所有输入框x值的列表 print(y) return x, y @teststeps def get_result(self): """点击输入框,激活小键盘""" content = self.driver \ .find_element_by_id("com.vanthink.student.debug:id/tb_content").get_attribute('contentDescription') value = re.match("\\[(.+?)\\]", content) # answer print(value) answer = value.group(1).split(',') # 所有输入框值的列表 print('正确答案:', answer) return answer @teststep def click_enter_button(self): """点击回车键,激活下一题输入框""" self.bounds.click_bounds(660, 1240) @teststeps def choice_word_filling(self): """《选词填空》 游戏过程""" if self.wait_check_page(): # 页面检查点 timestr = [] self.prompt() # 右上角 提示词 content = self.prompt_content() # 取出提示内容 self.click_blank() # 点击空白处 弹框消失 word_list = content.split(' ') # 取出单词列表 print('待输入的单词:', word_list) self.font_operate() # Aa文字大小切换按钮 切换 及状态统计 rate = self.rate() for i in range(int(rate)): Homework().rate_judge(rate, i, self.rate()) # 测试当前rate值显示是否正确 Homework().next_button_operate('false') # 下一题 按钮 状态判断 加点击 if i == 0: item = self.content_desc() time.sleep(2) x = float(item[0][i]) + 88.0 y = float(item[1][i]) + 246.0 self.bounds.click_bounds(x, y) else: self.click_enter_button() word = word_list[i] print('word:', word) if len(word_list) >= int(rate): for index in range(len(word)): if index == 4: games_keyboard('capslock') # 点击键盘 切换到 大写字母 games_keyboard(word[index].upper()) # 点击键盘对应 大写字母 games_keyboard('capslock') # 点击键盘 切换到 小写字母 else: games_keyboard(word[index]) # 点击键盘对应字母 else: games_keyboard('abc') # 点击键盘对应字母 timestr.append(self.time()) # 统计每小题的计时控件time信息 Homework().next_button_operate('true') # 下一题 按钮 状态判断 加点击 Homework().now_time(timestr) # 判断游戏界面 计时功能控件 是否在计时 print('==================================================') return rate @teststeps def detail_page(self, rate, homework_title, game_title): """查看答案页面面""" self.result.check_result_button() # 结果页 查看答案 按钮 if self.result.wait_check_detail_page(): # 页面检查点 print('查看答案页面:') item = self.get_result() print('excel-opeate:') for i in range(len(item)): print('----------------------') ExcelUtil().data_write(rate, homework_title, game_title, item[i]) self.back_up_button() @teststeps def font_operate(self): """Aa文字大小切换按钮 状态判断 及 切换操作""" x = [] y = [] middle = self.font_middle() # first large = self.font_large() # second great = self.font_great() # third i = 0 j = 0 while i < 3: bounds = self.content_desc() # 获取输入框坐标 print(middle.get_attribute('checked'), large.get_attribute('checked'), great.get_attribute('checked')) if middle.get_attribute('checked') == 'false': if large.get_attribute('checked') == 'false': x.insert(2, bounds[0][0]) y.insert(2, bounds[1][0]) print('当前选中的Aa按钮为第3个:', bounds[0][0], bounds[1][0]) j = 3 else: if large.get_attribute('checked') == 'true': x.insert(1, bounds[0][0]) y.insert(1, bounds[1][0]) print('当前选中的Aa按钮为第2个:', bounds[0][0], bounds[1][0]) j = 2 else: x.insert(0, bounds[0][0]) y.insert(0, bounds[1][0]) print('当前选中的Aa按钮为第1个:', bounds[0][0], bounds[1][0]) j = 1 if j == 1: large.click() elif j == 2: great.click() else: middle.click() i += 1 print('--------------------------------------------') time.sleep(2) if not float(y[2]) > float(y[1]) > float(y[0]): print('★★★ Error - Aa文字大小切换按钮:', y) print('==============================================')
def click_hide(self): """点击 隐藏键盘 按钮""" ClickBounds().click_bounds(990, 1210)
def click_next(self): """点击键盘 下一个 按钮""" ClickBounds().click_bounds(994, 1845)
class StrengthenSentence(BasePage): """强化炼句""" def __init__(self): self.bounds = ClickBounds() self.result = ResultPage() # 以下为 共有元素 @teststeps def wait_check_page(self): """以“title:强化炼句”的ID为依据""" locator = (By.XPATH, "//android.widget.TextView[contains(@text,'强化炼句')]") try: WebDriverWait(self.driver, 20, 0.5).until(lambda x: x.find_element(*locator)) return True except: return False @teststep def rate(self): """获取作业数量""" rate = self.driver\ .find_element_by_id("com.vanthink.student.debug:id/rate").text return rate @teststep def time(self): """获取作业时间""" rate = self.driver\ .find_element_by_id("com.vanthink.student.debug:id/time").text return rate @teststeps def content_desc(self): """点击输入框,激活小键盘""" content = self.driver \ .find_element_by_id("com.vanthink.student.debug:id/input2").get_attribute('contentDescription') item_x = re.match(".*\[(.*)\].*\[", content) # x值 item_y = re.match(".*\[(.*)\].*", content) # y值 x = item_x.group(1).split(',') # 所有输入框y值的列表 y = item_y.group(1).split(',') # 所有输入框x值的列表 return x, y @teststeps def get_result(self): """点击输入框,激活小键盘""" content = self.driver \ .find_element_by_id("com.vanthink.student.debug:id/input2").get_attribute('contentDescription') value = re.match("\\[(.+?)\\]", content) # answer answer = value.group(1).split(',') # 所有输入框值的列表 return answer @teststep def click_voice(self): """页面内音量按钮""" self.driver \ .find_element_by_id("com.vanthink.student.debug:id/play_voice") \ .click() @teststeps def sentence(self): """展示的句子""" word = self.driver \ .find_element_by_id("com.vanthink.student.debug:id/input2").text return word @teststep def explain(self): """展示的翻译""" word = self.driver \ .find_element_by_id("com.vanthink.student.debug:id/explain").text return word # 每小题回答完,下一步按钮后展示答案的页面 @teststeps def correct_title(self): """展示的答案title:正确答案 的ID为依据""" locator = (By.ID, "com.vanthink.student.debug:id/correct_title") try: WebDriverWait(self.driver, 20, 0.5).until(lambda x: x.find_element(*locator)) return True except: return False @teststeps def correct(self): """展示的答案""" word = self.driver \ .find_element_by_id("com.vanthink.student.debug:id/correct").text ele = word[:-1] # 去掉最后的标点符号 return ele # 查看答案页面 @teststeps def result_question(self): """展示的题目""" ele = self.driver \ .find_elements_by_id("com.vanthink.student.debug:id/tv_hint") word = [] for i in range(len(ele)): word.append(ele[i].text) return word @teststeps def result_answer(self): """展示的 正确答案""" ele = self.driver \ .find_elements_by_id("com.vanthink.student.debug:id/tv_answer") word = [] for i in range(len(ele)): word.append(ele[i].text) return word @teststep def result_mine_state(self, index): """我的答案对错标识 selected属性""" word = self.driver \ .find_elements_by_id("com.vanthink.student.debug:id/iv_mine")[index].get_attribute('selected') return word @teststep def back_up_button(self): """以“返回按钮”的class name为依据""" self.driver \ .find_element_by_class_name("android.widget.ImageButton") \ .click() @teststeps def diff_type(self, tpe): """选择 不同模式小游戏的 游戏方法""" print(tpe) if tpe == '默写模式': answer = self.dictation_pattern() elif tpe == '自定义模式': answer = self.custom_pattern() elif tpe == '简单模式': answer = self.easy_pattern() else: # 复杂模式 answer = self.random_pattern() return answer @teststeps def random_pattern(self): """《强化炼句 复杂模式》 游戏过程""" if self.wait_check_page(): # 页面检查点 answer = [] timestr = [] # 获取每小题的时间 rate = self.rate() for i in range(int(rate)): Homework().rate_judge(rate, i, self.rate()) # 测试当前rate值显示是否正确 Homework().next_button_operate('false') # 下一题 按钮 判断加 点击操作 value = self.edit_text() # 激活输入框并进行输入 Homework().next_button_operate( 'true') # 下一题 按钮 状态判断加 点击操作 ,进入答案页面 self.correct_judge(value, i) # 判断答题是否正确 timestr.append(self.time()) # 统计每小题的计时控件time信息 Homework().next_button_operate('true') # 下一题 按钮 状态判断加 点击操作 print('-------------------------------') Homework().now_time(timestr) # 判断游戏界面 计时功能控件 是否在计时 print('======================================================') return rate, answer @teststeps def custom_pattern(self): """《强化炼句 自定义模式》 游戏过程""" if self.wait_check_page(): # 页面检查点 answer = [] timestr = [] # 获取每小题的时间 rate = self.rate() for i in range(int(rate)): Homework().rate_judge(rate, i, self.rate()) # 测试当前rate值显示是否正确 Homework().next_button_operate('false') # 下一题 按钮 状态判断 点击 value = self.edit_text() # 激活输入框并进行输入 Homework().next_button_operate('true') # 下一题 按钮 状态判断 点击 if self.correct_title(): result = self.correct_judge(value, i) # 判断答题是否正确 answer.append(result[0]) timestr.append(self.time()) # 统计每小题的计时控件time信息 Homework().next_button_operate('true') # 下一题 按钮 状态判断 点击 print('-------------------------------') Homework().now_time(timestr) # 判断游戏界面 计时功能控件 是否在计时 print('======================================================') return rate, answer @teststeps def easy_pattern(self): """《强化炼句 简单模式》 游戏过程""" if self.wait_check_page(): # 页面检查点 answer = [] timestr = [] # 获取每小题的时间 rate = self.rate() for i in range(int(rate)): Homework().rate_judge(rate, i, self.rate()) # 测试当前rate值显示是否正确 Homework().next_button_operate('false') # 下一题 按钮 状态判断 点击 value = self.edit_text() # 激活输入框并进行输入 Homework().next_button_operate('true') # 下一题 按钮 状态判断 点击,进入答案页面 result = self.correct_judge(value, i) # 判断答题是否正确 answer.append(result[0]) timestr.append(self.time()) # 统计每小题的计时控件time信息 Homework().next_button_operate('true') # 下一题 按钮 状态判断 点击 print('-------------------------------') Homework().now_time(timestr) # 判断游戏界面 计时功能控件 是否在计时 print('======================================================') return rate, answer @teststeps def dictation_pattern(self): """《强化炼句 默写模式》 游戏过程""" if self.wait_check_page(): # 页面检查点 answer = [] timestr = [] # 获取每小题的时间 rate = self.rate() for i in range(int(rate)): Homework().rate_judge(rate, i, self.rate()) # 测试当前rate值显示是否正确 Homework().next_button_operate('false') # 下一题 按钮 状态判断 点击 value = self.edit_text() # 激活输入框并进行输入 Homework().next_button_operate('true') # 下一题 按钮 状态判断 点击,进入答案页面 result = self.correct_judge(value, i) # 判断答题是否正确 answer.append(result[0]) timestr.append(self.time()) # 统计每小题的计时控件time信息 Homework().next_button_operate('true') # 下一题 按钮 状态判断 点击 print('-----------------------------') Homework().now_time(timestr) # 判断游戏界面 计时功能控件 是否在计时 print('==================================================') return rate, answer @teststeps def edit_text(self): """激活输入框 并 输入内容""" explain = self.explain() # 解释的内容 sentence = self.sentence().split(' ') # 句子 print('题目:', self.sentence()) value = strength_sentence_operate(explain) # 数据字典 words = value.split(' ') # 将句子分割成单词 word = [] for i in range(len(words)): if (self.is_alphabet(words[i])) and (words[i] not in sentence): word.append(words[i]) for j in range(len(word)): item = self.content_desc() # 获取输入框坐标 x = float(item[0][j]) + 80.0 y = float(item[1][j]) + 320.0 self.bounds.click_bounds(x, y) # 激活输入框 for z in range(len(word[j])): if j == len(word) - 1: if word[j][z] in ['.', '?', '!']: # 去掉最后的标点符号 break if z == 4 and z != len(word[j]) - 1: games_keyboard('capslock') # 点击键盘 切换到 大写字母 games_keyboard(word[j][z].upper()) # 点击键盘对应 大写字母 games_keyboard('capslock') # 点击键盘 切换到 小写字母 else: if j == 2 and word[j][z] == "'": games_keyboard(',') # 第二小题 点击键盘 逗号 else: games_keyboard(word[j][z]) # 点击键盘对应字母 return value @teststeps def correct_judge(self, value, i): """每小题回答完,下一步按钮后展示答案的页面""" if self.correct_title(): # 展示的答案title元素是否存在 result = self.get_result() # content-desc的值 answer = self.sentence() # 展示的本人的答案 for j in range(len(result)): for k in range(len(answer)): if answer[k] == '{': if len(answer) != 2: if k == 0: # 展示的本人的答案 result[j] answer = result[j].strip() + answer[k + 2:] elif k + 1 == len(answer) - 1: if ' ' not in result[j]: answer = answer[:k - 1] + ' ' + result[j] else: answer = answer[:k - 1] + result[j] else: if ' ' not in result[j]: answer = answer[:k - 1] + ' ' + result[ j] + answer[k + 2:] else: answer = answer[:k - 1] + result[j] + answer[k + 2:] break if answer[len(answer) - 1] == ' ': answer = answer[:-1] correct = self.correct() # 展示的正确答案 print('我的答案:', answer) if correct == value: # 测试展示的答案是否正确 if answer == correct: print('回答正确') else: print('回答错误') return answer, i def replace_string(self, answer, num, replace): string2 = '' for i in range(len(answer)): if i == num: string2 += replace else: string2 += answer[i] return string2 @teststeps def study_again(self, tpe): """《强化炼句》 再练一遍 操作过程""" print('再练一遍 操作过程:') if self.result.wait_check_result_page(): # 结果页检查点 self.result.again_button() # 结果页 再练一遍 按钮 result = self.diff_type(tpe) # 强化炼句 - 游戏过程 return '再练一遍按钮', result[0], result[1] @teststeps def check_detail_page(self, i, answer): """查看答案页面""" if self.result.wait_check_result_page(): # 结果页检查点 self.result.check_result_button() # 查看答案 按钮 if self.result.wait_check_detail_page(): print('结果页 - 查看答案 按钮:') if int(i) <= 16: self.result_operate(answer) else: item = self.result_question() if int(i) % len(item) == 0: page = int(int(i) / len(item)) else: page = int(int(i) / len(item)) + 1 print('页数:', page) for j in range(page): last_one = self.result_operate( answer) # 滑动前页面内最后一个小题- 做题结果 self.screen_swipe_up(0.5, 0.75, 0.35, 1000) item_2 = self.result_question() # 滑动后页面内的题目 的数量 if item_2[len(item_2) - 1].text == last_one: print('到底啦', last_one) self.back_up_button() break elif item_2[len(item_2) - 1].text == answer[len(answer) - 1]: # 滑动后到底,因为普通情况下最多只有两页,滑动一次即可到底 print('滑动后到底', last_one) k = [] for i in range(len(item_2) - 1, -1, -1): # 倒序 if item_2[i].text == last_one: k.append(i + 1) break self.result_operate(answer, k[0]) break else: continue self.screen_swipe_down(0.5, 0.75, 0.35, 1000) time.sleep(2) self.back_up_button() @teststeps def result_operate(self, var, index=0): """查看答案页面 -- 展示的解释内容验证""" explain = self.result_question() # 题目 answer = self.result_answer() # 正确答案 print(answer, var) for i in range(index, len(explain)): count = [] value = strength_sentence_operate(explain[i]).split(' ') if answer[i] == var[i]: # 测试结果页 我的答案展示是否正确 if answer[i] == value: # 测试 正确答案 for j in range(len(var)): # 我的答案 与 正确答案 比较 if var[j] != value[j]: # 答案不正确 count+1 count.append(j) if self.result_mine_state() != 'false': print('★★★ Error - 我的答案:%s 与 正确答案:%s 对错标识:%s' % (var[j], value[j], 'true')) else: if self.result_mine_state() != 'true': print('★★★ Error - 我的答案:%s 与 正确答案:%s 对错标识:%s' % (var[j], value[j], 'false')) break else: print('★★★ Error - 正确答案:', answer[i], value) print('------------------------------------') return var[1][len(var[1]) - 1]
def choose_image(self): """选择相册图片""" ClickBounds().click_bounds(float(VALID_IMAGE.location_x()), float(VALID_IMAGE.location_y()))
def click_block(self): """点击页面空白区域""" time.sleep(1) ClickBounds().click_bounds(540, 300)
def click_blank(self): """点击空白处""" ClickBounds().click_bounds(430, 800) print('点击空白处,切换双页面:') time.sleep(1)
def choose_image(self): """选择相册图片""" time.sleep(2) print(float(VALID_IMAGE.location_x()), float(VALID_IMAGE.location_y())) ClickBounds().click_bounds(float(VALID_IMAGE.location_x()), float(VALID_IMAGE.location_y()))