class Messenger(unittest.TestCase): def __init__(self, methodName='runTest', device=DEVICE_CONFIG): unittest.TestCase.__init__(self, methodName) self.device = device self.APPIUM_CONFIG = appium_config.get_appium_set()[self.device] def setUp(self): print('Test start') desired_caps = {} desired_caps[ 'automationName'] = "appium" # Appium,UiAutomator2,XCUITest,YouiEngine desired_caps['platformName'] = 'Android' desired_caps['deviceName'] = self.device desired_caps['udid'] = self.device # desired_caps['appPackage'] = 'com.tencent.mm' # desired_caps['appActivity'] = 'com.tencent.mm.ui.LauncherUI' desired_caps['appPackage'] = 'com.facebook.orca' desired_caps['appActivity'] = '.auth.StartScreenActivity' # desired_caps['appPackage'] = 'com.emoji.ikeyboard' # desired_caps['appActivity'] = 'com.qisi.ikeyboarduirestruct.NavigationActivity' # 隐藏键盘 # desired_caps['resetKeyboard'] = 'True' # 使用appium键盘 # desired_caps['unicodeKeyboard'] = 'True' self.d = webdriver.Remote( 'http://%s:%s/wd/hub' % (self.APPIUM_CONFIG[0], self.APPIUM_CONFIG[1]), desired_caps) # self.d = webdriver.Remote('http://%s:%s/wd/hub' % ('127.0.0.1', '4711'), desired_caps) self.extend = Appium_Extend(self.d) self.BF = BaseFunction(self, self.d) self.Ik = Ikey_Function(self, self.d) self.M = Messager_Function(self, self.d, DEVICE_CONFIG) self.BF.keyboard_select( 'com.emoji.ikeyboard/com.android.inputmethod.latin.LatinIME') time.sleep(5) def tearDown(self): print('Test end') self.d.quit() def precast_condition(self): # self.d.start_activity('com.emoji.ikeyboard', 'com.android.inputmethod.latin.setup.SetupWizard2Activity') # time.sleep(3) self.Ik.precast_condition( 'com.emoji.ikeyboard', '/Users/xm/Downloads/app-ikeyboard-135601-release-ikey_engine_refactor.apk', 'com.emoji.ikeyboard/com.android.inputmethod.latin.LatinIME') def en_input(self): top_y = self.M.select_user( 'com.emoji.ikeyboard/com.android.inputmethod.latin.LatinIME') keyboard = Keyboard_Operation(self.d, top_y) keyboard.send_input('copy') keyboard.send_input(' ') copy = self.BF.attribute_name('id', 'com.facebook.orca:id/text_input_bar', 'Copy ') self.BF.check_assertTrue(copy, '上屏内容错误') self.BF.check_find_element( 'id', 'com.facebook.orca:id/text_input_bar').clear() keyboard.sliding_input('about') # 这个滑动输入的检查点需要重新明确 # about = self.BF.attribute_name('id', 'com.facebook.orca:id/text_input_bar', 'About') # self.BF.check_assertTrue(about, '上屏内容错误') self.BF.check_find_element( 'id', 'com.facebook.orca:id/text_input_bar').clear() keyboard.send_input('emoji') Messenger_emoji = self.BF.element_picture( 'id', 'com.facebook.orca:id/text_input_bar', 'Messenger_emoji') keyboard.send_input('emoji', 'emoji') keyboard.select_emoji('emoji', 1, 3) sendout = self.BF.attribute_name( 'id', 'com.facebook.orca:id/text_input_bar', '😂') self.BF.check_assertTrue(sendout, '表情选择错误') emoji = self.BF.cintrast_element_picture( 'id', 'com.facebook.orca:id/text_input_bar', Messenger_emoji) self.BF.check_assertFalse(emoji, '选择的emoji未上屏') # 检查点表格'Messenger_emoji' self.BF.checkpoint('Messenger_emoji', 'id', 'com.facebook.orca:id/text_input_bar', 'Messenger_emoji') self.BF.check_find_element( 'id', 'com.facebook.orca:id/text_input_bar').clear() keyboard.send_input('emoji') keyboard.send_input('sticker', 'emoji') keyboard.select_emoji('sticker', 1, 2) time.sleep(5) # self.BF.click('name', '确定') self.BF.checkpoint('Messenger_sticker', 'id', 'com.facebook.orca:id/message_container', 'Messenger_sticker') keyboard.send_input('gif', 'emoji') time.sleep(10) keyboard.select_emoji('gif', 1, 2) time.sleep(5) # self.BF.click('name', '确定') self.BF.checkpoint('Messenger_gif', 'id', 'com.facebook.orca:id/message_container', 'Messenger_gif') keyboard.send_input('emoticon', 'emoji') keyboard.select_emoji('gif', 1, 2) emoticon = self.BF.attribute_name( 'id', 'com.facebook.orca:id/text_input_bar', '(^~^)') self.BF.check_assertTrue(emoticon, 'emoticon选择错误') self.BF.checkpoint('Messenger_emoticon', 'id', 'com.facebook.orca:id/text_input_bar', 'Messenger_emoticon') def es_input(self): top_y = self.M.select_user( 'com.emoji.ikeyboard/com.android.inputmethod.latin.LatinIME') keyboard = Keyboard_Operation(self.d, top_y) # 切换输入法至西班牙语 while True: location = keyboard.keyboard_reader(' ') orc = keyboard.orc_location_text(location['x'], location['y'], location['width'], location['height']) print(orc) if 'Es' in orc: break else: keyboard.swip_location(location['x'], location['y'], location['width'], location['height']) keyboard.send_input('espa') orc_select = keyboard.orc_location_text(0, top_y, keyboard.phone_width, 40 * keyboard.density()['density'], set_lang='epo') # print(orc_select) if 'Espaĥol' in orc_select: orc_result = True else: orc_result = False self.BF.check_assertTrue(orc_result, '没有纠正') def por_input(self): top_y = self.M.select_user( 'com.emoji.ikeyboard/com.android.inputmethod.latin.LatinIME') keyboard = Keyboard_Operation(self.d, top_y) # 切换输入法至葡萄牙语 while True: location = keyboard.keyboard_reader(' ') orc = keyboard.orc_location(location['x'], location['y'], location['width'], location['height']) print(orc) if 'Po' in orc: break else: keyboard.swip_location(location['x'], location['y'], location['width'], location['height']) keyboard.send_input('portug') orc_select = keyboard.orc_location(0, top_y, keyboard.phone_width, 40 * keyboard.density()['density'], set_lang='por') print(orc_select) if 'Português' in orc_select: orc_result = True else: orc_result = False self.BF.check_assertTrue(orc_result, '没有纠正')
class InputApp(unittest.TestCase): def __init__(self, methodName='runTest', device=DEVICE_CONFIG): unittest.TestCase.__init__(self, methodName) self.device = device self.APPIUM_CONFIG = appium_config.get_appium_set()[self.device] def setUp(self): print('Test start') desired_caps = {} desired_caps[ 'automationName'] = "appium" # Appium,UiAutomator2,XCUITest,YouiEngine desired_caps['platformName'] = 'Android' desired_caps['deviceName'] = self.device desired_caps['udid'] = self.device # 超时时间设置 desired_caps['newCommandTimeout'] = 360 # desired_caps['appPackage'] = 'com.tencent.mm' # desired_caps['appActivity'] = 'com.tencent.mm.ui.LauncherUI' desired_caps['appPackage'] = 'yuside.cn.numbersonly' desired_caps['appActivity'] = 'yuside.cn.numbersonly.MainActivity' # desired_caps['appPackage'] = 'com.emoji.ikeyboard' # desired_caps['appActivity'] = 'com.qisi.ikeyboarduirestruct.NavigationActivity' # 隐藏键盘 # desired_caps['resetKeyboard'] = 'True' # 使用appium键盘 # desired_caps['unicodeKeyboard'] = 'True' self.d = webdriver.Remote( 'http://%s:%s/wd/hub' % (self.APPIUM_CONFIG[0], self.APPIUM_CONFIG[1]), desired_caps) # self.d = webdriver.Remote('http://%s:%s/wd/hub' % ('127.0.0.1', '4711'), desired_caps) self.extend = Appium_Extend(self.d) self.BF = BaseFunction(self, self.d) self.Ik = Ikey_Function(self, self.d, self.device) time.sleep(5) self.BF.keyboard_select( 'com.emoji.ikeyboard/com.android.inputmethod.latin.LatinIME', self.device) def tearDown(self): print('Test end') self.d.quit() def precast_condition(self): self.Ik.precast_condition( 'com.emoji.ikeyboard', '/Users/xm/Downloads/app-ikeyboard-136401-release-ikey_engine_refactor.apk', 'com.emoji.ikeyboard/com.android.inputmethod.latin.LatinIME') def theme(self): top_y = self.BF.keyboard_get_ready( 'com.emoji.ikeyboard/com.android.inputmethod.latin.LatinIME', 'class', 'android.widget.ScrollView') keyboard = Keyboard_Operation(self.d, top_y) k = keyboard.get_keyboard_picture(0, top_y, keyboard.phone_width, (keyboard.density()['app'] - top_y), 'keyboard') keyboard.send_input('system') keyboard.main_menu_click('theme') keyboard.select_theme(2, 1) pic_text = keyboard.get_keyboard_picture( 0, top_y, keyboard.phone_width, (keyboard.density()['app'] - top_y), 'keyboard_back') keyboard.send_input('q') click = self.BF.attribute_name('classes', 'android.widget.EditText[0]') # pic_text = keyboard.pic_text(pic_text) # if 'q' in pic_text: if click == 'q' or 'Q': pass else: assert 1 + 1 > 2, '没有回到键盘' k_s = keyboard.keyboard_same(0, top_y, keyboard.phone_width, (keyboard.density()['app'] - top_y), k) self.BF.check_assertFalse(k_s, '主题更换失败') # 回选到默认主题 keyboard.send_input('system') keyboard.main_menu_click('theme') keyboard.select_theme(1, 2) pic_text = keyboard.get_keyboard_picture( 0, top_y, keyboard.phone_width, (keyboard.density()['app'] - top_y), 'keyboard_back') pic_text = keyboard.pic_text(pic_text) if 'q' or 'Q' in pic_text: pass else: assert 1 + 1 > 2, '没有回到键盘' k_s = keyboard.keyboard_same(0, top_y, keyboard.phone_width, (keyboard.density()['app'] - top_y), k) self.BF.check_assertTrue(k_s, '主题更换失败') def old_new_app1(self): self.Ik.old_new_app_custom_keyboard( 'com.emoji.ikeyboard', 'com.emoji.ikeyboard/com.android.inputmethod.latin.LatinIME', '/Users/xm/Downloads/app-ikeyboard-135401-release-ikey_release.apk', '/Users/xm/Downloads/app-ikeyboard-135601-release-ikey_engine_refactor.apk' ) def old_new_app2(self): run_result = [] false_result = [] for i in range(3, 12): # for i in range(5, 7): result = self.Ik.old_new_app_theme( i, 'com.emoji.ikeyboard', 'com.emoji.ikeyboard/com.android.inputmethod.latin.LatinIME', '/Users/xm/Downloads/app-ikeyboard-135401-release-ikey_release.apk', '/Users/xm/Downloads/app-ikeyboard-135601-release-ikey_engine_refactor.apk' ) run_result.append(result) print(run_result) for g in range(0, len(run_result)): for f in run_result[g]: key = f if run_result[g][f] == False: false_result.append(key) if len(false_result) > 0: assert 1 + 1 > 2, '以下主题前后不一致%s' % str(false_result) def old_new_app3(self): run_result = [] false_result = [] for i in range(0, 5): result = self.Ik.old_new_app_font( i, 'com.emoji.ikeyboard', 'com.emoji.ikeyboard/com.android.inputmethod.latin.LatinIME', '/Users/xm/Downloads/app-ikeyboard-135401-release-ikey_release.apk', '/Users/xm/Downloads/app-ikeyboard-135601-release-ikey_engine_refactor.apk' ) run_result.append(result) print(run_result) for g in range(0, len(run_result)): for f in run_result[g]: key = f if run_result[g][f] == False: false_result.append(key) if len(false_result) > 0: assert 1 + 1 > 2, '以下字体前后不一致%s' % str(false_result) # 自定义键盘 def change(self): self.Ik.change_custom_keyboard() def settings(self): self.Ik.app_settings() # 修改为第几个主题 def theme_change(self): self.Ik.change_theme(3) self.d.start_activity('yuside.cn.numbersonly', 'yuside.cn.numbersonly.MainActivity') # 键盘输入检查 top_y = self.BF.keyboard_get_ready( 'com.emoji.ikeyboard/com.android.inputmethod.latin.LatinIME', 'class', 'android.widget.ScrollView') keyboard = Keyboard_Operation(self.d, top_y) keyboard.send_input('qwertyuiopasdfghjklzxcvbnm') keyboard.send_input('shift') keyboard.send_input('g') s_input = self.BF.attribute_name('classes', 'android.widget.EditText[0]', 'qwertyuiopasdfghjklzxcvbnmG') self.BF.check_assertTrue(s_input, '键盘输入内容错误') # 随机下载主题并清除下载的主题 def download_theme(self): self.Ik.random_download_theme() self.d.start_activity('yuside.cn.numbersonly', 'yuside.cn.numbersonly.MainActivity') # 键盘输入检查 top_y = self.BF.keyboard_get_ready( 'com.emoji.ikeyboard/com.android.inputmethod.latin.LatinIME', 'class', 'android.widget.ScrollView') keyboard = Keyboard_Operation(self.d, top_y) keyboard.send_input('qwertyuiopasdfghjklzxcvbnm') keyboard.send_input('shift') keyboard.send_input('g') s_input = self.BF.attribute_name('classes', 'android.widget.EditText[0]', 'qwertyuiopasdfghjklzxcvbnmG') self.BF.check_assertTrue(s_input, '键盘输入内容错误') self.Ik.clear_download_theme() # 跟换emoji的风格 def emoji_style_change(self): top_y = self.BF.keyboard_get_ready( 'com.emoji.ikeyboard/com.android.inputmethod.latin.LatinIME', 'class', 'android.widget.ScrollView') keyboard = Keyboard_Operation(self.d, top_y) keyboard.send_input('emoji') old_emoji = keyboard.get_keyboard_picture( 0, top_y + 40 * keyboard.density()['density'], keyboard.phone_width, keyboard.density()['app'] - top_y - 80 * keyboard.density()['density'], 'old_emoji') self.Ik.change_emoji_style(0) self.d.start_activity('yuside.cn.numbersonly', 'yuside.cn.numbersonly.MainActivity') # 键盘输入检查 top_y = self.BF.keyboard_get_ready( 'com.emoji.ikeyboard/com.android.inputmethod.latin.LatinIME', 'class', 'android.widget.ScrollView') keyboard = Keyboard_Operation(self.d, top_y) keyboard.send_input('emoji') now_emoji = keyboard.keyboard_same( 0, top_y + 40 * keyboard.density()['density'], keyboard.phone_width, keyboard.density()['app'] - top_y - 80 * keyboard.density()['density'], old_emoji) self.BF.check_assertFalse(now_emoji, 'emoji风格更换失败') # 下载并更换emoji主题后清理 def emoji_style_download(self): top_y = self.BF.keyboard_get_ready( 'com.emoji.ikeyboard/com.android.inputmethod.latin.LatinIME', 'class', 'android.widget.ScrollView') keyboard = Keyboard_Operation(self.d, top_y) keyboard.send_input('emoji') old_emoji = keyboard.get_keyboard_picture( 0, top_y + 40 * keyboard.density()['density'], keyboard.phone_width, keyboard.density()['app'] - top_y - 80 * keyboard.density()['density'], 'old_emoji') self.Ik.random_download_emoji_style() self.d.start_activity('yuside.cn.numbersonly', 'yuside.cn.numbersonly.MainActivity') # 键盘输入检查 top_y = self.BF.keyboard_get_ready( 'com.emoji.ikeyboard/com.android.inputmethod.latin.LatinIME', 'class', 'android.widget.ScrollView') keyboard = Keyboard_Operation(self.d, top_y) keyboard.send_input('emoji') now_emoji = keyboard.keyboard_same( 0, top_y + 40 * keyboard.density()['density'], keyboard.phone_width, keyboard.density()['app'] - top_y - 80 * keyboard.density()['density'], old_emoji) self.BF.check_assertFalse(now_emoji, 'emoji风格更换失败') self.Ik.clear_download_emoji_style() # 下载font对比后并清理 def download_font(self): top_y = self.BF.keyboard_get_ready( 'com.emoji.ikeyboard/com.android.inputmethod.latin.LatinIME', 'class', 'android.widget.ScrollView') keyboard = Keyboard_Operation(self.d, top_y) old_keyboard = keyboard.get_keyboard_picture( 0, top_y + 40 * keyboard.density()['density'], keyboard.phone_width, (keyboard.density()['app'] - top_y - 40 * keyboard.density()['density']) * 3 / 4, 'keyboard_old') self.Ik.random_download_font() self.d.start_activity('yuside.cn.numbersonly', 'yuside.cn.numbersonly.MainActivity') time.sleep(5) top_y = self.BF.keyboard_get_ready( 'com.emoji.ikeyboard/com.android.inputmethod.latin.LatinIME', 'class', 'android.widget.ScrollView') keyboard = Keyboard_Operation(self.d, top_y) k = keyboard.keyboard_same( 0, top_y + 40 * keyboard.density()['density'], keyboard.phone_width, (keyboard.density()['app'] - top_y - 40 * keyboard.density()['density']) * 3 / 4, old_keyboard) self.BF.check_assertFalse(k, '字体修改失败') self.Ik.clear_font() # pop_key检查 def pop_key(self): top_y = self.BF.keyboard_get_ready( 'com.emoji.ikeyboard/com.android.inputmethod.latin.LatinIME', 'class', 'android.widget.ScrollView') keyboard = Keyboard_Operation(self.d, top_y) keyboard.pop_select('a', 'á') a = self.BF.attribute_name('xpath', '//android.widget.EditText[@index="0"]', 'á') self.BF.check_assertTrue(a, 'popkey有问题') self.BF.check_find_element( 'xpath', '//android.widget.EditText[@index="0"]').clear() keyboard.send_input('number') keyboard.pop_select('.', '…', keyboard_type='normal_number') number = self.BF.attribute_name( 'xpath', '//android.widget.EditText[@index="0"]', '…') self.BF.check_assertTrue(number, 'popkey有问题') self.BF.check_find_element( 'xpath', '//android.widget.EditText[@index="0"]').clear() keyboard.send_input('symbol', keyboard_type='normal_number') keyboard.pop_select('=', '∞', keyboard_type='normal_symbol') symbol = self.BF.attribute_name( 'xpath', '//android.widget.EditText[@index="0"]', '∞') self.BF.check_assertTrue(symbol, 'popkey有问题') # 开启Number和Select后的layout检查 def keyboard_layout(self): default_top_y = self.BF.keyboard_get_ready( 'com.emoji.ikeyboard/com.android.inputmethod.latin.LatinIME', 'class', 'android.widget.ScrollView') # 开启数字和select self.Ik.app_settings() self.BF.click('name', 'Keyboard Settings') self.BF.click_change( 'xpath', '//*[@text="Number Row"]/../../android.widget.LinearLayout') self.BF.click_change( 'xpath', '//*[@text="Selector Row"]/../../android.widget.LinearLayout') # 打开input self.d.start_activity('yuside.cn.numbersonly', 'yuside.cn.numbersonly.MainActivity') top_y = self.BF.keyboard_get_ready( 'com.emoji.ikeyboard/com.android.inputmethod.latin.LatinIME', 'class', 'android.widget.ScrollView') keyboard = Keyboard_Operation(self.d, top_y) keyboard.send_input('1234567890', number=True, select=True) number = self.BF.attribute_name( 'xpath', '//android.widget.EditText[@index="0"]', '1234567890') self.BF.check_assertTrue(number, '输入错误,数字键有问题') self.BF.check_find_element( 'xpath', '//android.widget.EditText[@index="0"]').clear() self.BF.click('xpath', '//android.widget.EditText[@index="0"]') keyboard.send_input('asdfghj', inputtype='long_pass', number=True, select=True) symbol = self.BF.attribute_name( 'xpath', '//android.widget.EditText[@index="0"]', '@#$%&-+') self.BF.check_assertTrue(symbol, '输入错误,pop_key有问题') # 关闭Number和Select self.Ik.app_settings() self.BF.click('name', 'Keyboard Settings') self.BF.click_change( 'xpath', '//*[@text="Number Row"]/../../android.widget.LinearLayout') self.BF.click_change( 'xpath', '//*[@text="Selector Row"]/../../android.widget.LinearLayout') # 检查键盘是否高度变化 self.d.start_activity('yuside.cn.numbersonly', 'yuside.cn.numbersonly.MainActivity') new_top_y = self.BF.keyboard_get_ready( 'com.emoji.ikeyboard/com.android.inputmethod.latin.LatinIME', 'class', 'android.widget.ScrollView') if default_top_y == new_top_y: cancel_result = True else: cancel_result = False self.BF.check_assertTrue(cancel_result, '取消Number和Select后键盘高度变化了') # 新老版本语言 def new_language(self): self.Ik.app_settings() self.BF.click('name', 'Language') self.Ik.reach_language_add('Español (US)') self.Ik.reach_language_add('Português (Brasil)') self.d.back() self.BF.click('name', 'Language') l1 = self.BF.existence('name', 'English (US)') l2 = self.BF.existence('name', 'Español (US)') l3 = self.BF.existence('name', 'Português (Brasil)') if l1 and l2 and l3 is True: new_result = True else: new_result = False self.BF.check_assertTrue(new_result, '键盘添加语言正确') # 键盘检查 self.BF.open_app_atcivity( 'com.emoji.ikeyboard/com.qisi.ikeyboarduirestruct.NavigationActivity', self.device) self.Ik.app_settings() self.BF.click('name', 'Language') self.BF.click('name', 'Español (US)') self.BF.click('id', 'com.emoji.ikeyboard:id/iv_bg') es = self.BF.existence('name', 'Español (US)', fail_pic=False) self.BF.check_assertFalse(es, 'Es删除失败') self.BF.click('name', 'Português (Brasil)') self.BF.click('id', 'com.emoji.ikeyboard:id/iv_bg') es = self.BF.existence('name', 'Português (Brasil)', fail_pic=False) self.BF.check_assertFalse(es, 'Pt删除失败') def test(self): top_y = self.BF.keyboard_get_ready( 'com.emoji.ikeyboard/com.android.inputmethod.latin.LatinIME', 'class', 'android.widget.ScrollView', self.device) keyboard = Keyboard_Operation(self.d, top_y, self.device) keyboard.send_input('system') location = keyboard.main_menu_select('settings') # location = keyboard.main_menu_select('theme') keyboard.get_keyboard_picture(location['x'], location['y'], location['width'], location['height'], 'theme')
class Keyboard_Test(unittest.TestCase): def __init__(self, methodName='runTest', device=DEVICE_CONFIG): unittest.TestCase.__init__(self, methodName) self.device = device self.APPIUM_CONFIG = appium_config.get_appium_set()[self.device] def setUp(self): print('Test start') desired_caps = {} desired_caps[ 'automationName'] = "appium" # Appium,UiAutomator2,XCUITest,YouiEngine desired_caps['platformName'] = 'Android' desired_caps['deviceName'] = self.device desired_caps['udid'] = self.device # desired_caps['appPackage'] = 'com.tencent.mm' # desired_caps['appActivity'] = 'com.tencent.mm.ui.LauncherUI' desired_caps['appPackage'] = 'yuside.cn.numbersonly' desired_caps['appActivity'] = 'yuside.cn.numbersonly.MainActivity' # 隐藏键盘 # desired_caps['resetKeyboard'] = 'True' # 使用appium键盘 # desired_caps['unicodeKeyboard'] = 'True' self.d = webdriver.Remote( 'http://%s:%s/wd/hub' % (self.APPIUM_CONFIG[0], self.APPIUM_CONFIG[1]), desired_caps) # self.d = webdriver.Remote('http://%s:%s/wd/hub' % ('127.0.0.1', '4711'), desired_caps) self.extend = Appium_Extend(self.d) self.BF = BaseFunction(self, self.d) time.sleep(5) def tearDown(self): print('Test end') self.d.quit() def eninput(self): top_y = self.BF.keyboard_get_ready( 'com.emoji.ikeyboard/com.android.inputmethod.latin.LatinIME', 'class', 'android.widget.ScrollView') keyboard = Keyboard_Operation(self.d, top_y) # 用例内容 self.BF.click('xpath', '//*[@index="3"]') # self.BF.click('name', '01-textAutoComplete') time.sleep(2) keyboard.send_input('cppy') keyboard.send_input(' ') text = self.BF.attribute_name('xpath', '//*[@index="3"]', 'copy ') self.BF.check_assertTrue(text, 'fail') # text = keyboard.select_word_check('copy') # self.BF.check_assertTrue(text, '需要的词没有在选词栏中') # select = \ # keyboard.ocr_location(0, top_y, int(self.d.get_window_size()['width']), # int(keyboard.density()['density']) * 40)[0] # print(select) # keyboard.location_click(select['x'], select['y']) # click = self.BF.attribute_name('id', 'yuside.cn.numbersonly:id/search_btn', 'copy') # self.BF.check_assertTrue(click, '选词上屏fail') # self.BF.result_picture('eninput1') # self.BF.check_find_element('id', 'yuside.cn.numbersonly:id/search_btn').clear() # keyboard.sliding_input('about') # sliding = self.BF.attribute_name('id', 'yuside.cn.numbersonly:id/search_btn', 'about') # self.BF.check_assertTrue(sliding, '滑动上屏fail') # self.BF.result_picture('eninput2') def emoji(self): top_y = self.BF.keyboard_get_ready( 'com.emoji.ikeyboard/com.android.inputmethod.latin.LatinIME', 'class', 'android.widget.ScrollView') keyboard = Keyboard_Operation(self.d, top_y) self.BF.click('name', '02-search') search = self.BF.element_picture( 'id', 'yuside.cn.numbersonly:id/search_btn', 'search') keyboard.send_input('emoji') time.sleep(2) keyboard.send_input('emoji', keyboard_type='emoji') keyboard.select_emoji_class('emoji', 3) keyboard.select_emoji('emoji', 3, 5) emoji = self.BF.cintrast_element_picture( 'id', 'yuside.cn.numbersonly:id/search_btn', search) self.BF.check_assertFalse(emoji, 'emoji未上屏') self.BF.result_picture('emoji') def emoji_style(self): top_y = self.BF.keyboard_get_ready( 'com.emoji.ikeyboard/com.android.inputmethod.latin.LatinIME', 'class', 'android.widget.ScrollView') keyboard = Keyboard_Operation(self.d, top_y) keyboard.send_input('emoji') keyboard.send_input('emoji', keyboard_type='emoji') height = (keyboard.phone_height - top_y) width = keyboard.phone_width load = keyboard.get_keyboard_picture( 0, top_y, width, height - 40 * int(keyboard.density()['density']), 'emojy') keyboard.send_input('normal_key', keyboard_type='emoji') keyboard.send_input('system') keyboard.main_menu_click('style') keyboard.select_theme(1, 2) time.sleep(5) keyboard.send_input('emoji') same = keyboard.keyboard_same( 0, top_y, width, height - 40 * int(keyboard.density()['density']), load) self.BF.check_assertFalse(same, '表情风格更换失败') self.BF.result_picture('emoji_style') def nubmer_decimal(self): top_y = self.BF.keyboard_get_ready( 'com.emoji.ikeyboard/com.android.inputmethod.latin.LatinIME', 'class', 'android.widget.ScrollView') keyboard = Keyboard_Operation(self.d, top_y) self.BF.reach_element_click(200, 'name', '24-numberDecimal') keyboard.send_input('1234567890', keyboard_type='number_decimal') input = self.BF.attribute_name('xpath', '//*[@index="23"]', '1234567890') self.BF.check_assertTrue(input, '输入内容正确显示正确') # location = keyboard.keyboard_reader('1', keyboard_type='number_decimal') # keyboard.get_keyboard_picture(location['x'], location['y'], location['width'], location['height'], '1') # location = keyboard.keyboard_reader('2', keyboard_type='number_decimal') # keyboard.get_keyboard_picture(location['x'], location['y'], location['width'], location['height'], '2') # location = keyboard.keyboard_reader('3', keyboard_type='number_decimal') # keyboard.get_keyboard_picture(location['x'], location['y'], location['width'], location['height'], '3') # location = keyboard.keyboard_reader('-', keyboard_type='number_decimal') # keyboard.get_keyboard_picture(location['x'], location['y'], location['width'], location['height'], '-') # location = keyboard.keyboard_reader(' ', keyboard_type='number_decimal') # keyboard.get_keyboard_picture(location['x'], location['y'], location['width'], location['height'], 'space') self.BF.result_picture('nubmer_decimal') def number_password(self): top_y = self.BF.keyboard_get_ready( 'com.emoji.ikeyboard/com.android.inputmethod.latin.LatinIME', 'class', 'android.widget.ScrollView') keyboard = Keyboard_Operation(self.d, top_y) self.BF.reach_element_click(200, 'xpath', '//*[@index="24"]') keyboard.send_input('1234567890', keyboard_type='number_password') # location = keyboard.keyboard_reader('1', keyboard_type='number_password') # keyboard.get_keyboard_picture(location['x'], location['y'], location['width'], location['height'], '1') # location = keyboard.keyboard_reader('2', keyboard_type='number_password') # keyboard.get_keyboard_picture(location['x'], location['y'], location['width'], location['height'], '2') # location = keyboard.keyboard_reader('3', keyboard_type='number_password') # keyboard.get_keyboard_picture(location['x'], location['y'], location['width'], location['height'], '3') self.BF.result_picture('number_passworf') def chang_theme(self): top_y = self.BF.keyboard_get_ready( 'com.emoji.ikeyboard/com.android.inputmethod.latin.LatinIME', 'class', 'android.widget.ScrollView') keyboard = Keyboard_Operation(self.d, top_y) height = (keyboard.phone_height - top_y) width = keyboard.phone_width load = keyboard.get_keyboard_picture( 0, top_y, width, height - 40 * int(keyboard.density()['density']), 'keyboard') keyboard.send_input('system') keyboard.main_menu_click('theme') keyboard.select_theme(1, 2) # 判断是否回到了键盘主页 text = keyboard.word_in_pic( 0, top_y + int(keyboard.density()['density']) * 40, keyboard.phone_width, (int(keyboard.density()['app']) - top_y - int(keyboard.density()['density']) * 40) / 4, 'q') self.BF.check_assertTrue(text, '返回qwerty键盘失败,可能没有选择主题') time.sleep(5) same = keyboard.keyboard_same( 0, top_y, width, height - 40 * int(keyboard.density()['density']), load) self.BF.check_assertFalse(same, '主题风格更换失败') self.BF.result_picture('emoji_style') def normal_number(self): top_y = self.BF.keyboard_get_ready( 'com.emoji.ikeyboard/com.android.inputmethod.latin.LatinIME', 'class', 'android.widget.ScrollView') keyboard = Keyboard_Operation(self.d, top_y) self.BF.click('name', '02-search') # self.BF.click('name', '01-textAutoComplete') time.sleep(2) keyboard.send_input('number') keyboard.send_input('1234567890', keyboard_type='normal_number') # keyboard.send_input('qwertyuiopasdfghjklzxcvbnm') self.BF.result_picture('normal_number') def normal_symbol(self): top_y = self.BF.keyboard_get_ready( 'com.emoji.ikeyboard/com.android.inputmethod.latin.LatinIME', 'class', 'android.widget.ScrollView') keyboard = Keyboard_Operation(self.d, top_y) self.BF.click('name', '02-search') # self.BF.click('name', '01-textAutoComplete') time.sleep(2) keyboard.send_input('number') keyboard.send_input('symbol', keyboard_type='normal_number') keyboard.send_input('•√Π÷׶∆£¢€¥^°©®™℅', keyboard_type='normal_symbol') keyboard.send_input('number', keyboard_type='normal_symbol') # keyboard.send_input('qwertyuiopasdfghjklzxcvbnm') self.BF.result_picture('normal_symbol')
class Kika_Function: def __init__(self, tester, driver, device_config='none'): self.driver = driver self.BF = BaseFunction(tester, self.driver) self.AppiumExtend = Appium_Extend(self.driver) self.device_config = device_config # 这个主要作为一个例子其中会涉及到使用到的安卓系统导致没有适配的能力所以暂时只写个例子 def precast_condition(self, del_package, install_package_path, Typewriting): # 删除应用 if self.device_config == 'none': try: unin_result = os.popen('adb uninstall %s' % del_package) except Exception as e: print(e) print('没有对应应用') else: try: unin_result = os.popen('adb -s %s uninstall %s' % (self.device_config, del_package)) except Exception as e: print(e) print('没有对应应用') # 安装应用 self.BF.adb_install(install_package_path, self.device_config) self.BF.keyboard_select(Typewriting, self.device_config) self.BF.open_app_atcivity('com.qisiemoji.inputmethod/com.qisi.ikeyboarduirestruct.NavigationActivity') theme = self.BF.existence('name', 'Settings') if theme == False: count = 0 while True: try: self.BF.click('name', 'Allow') count += 1 except: time.sleep(3) if count == 3: break if count == 6: break self.BF.keyboard_select('com.qisiemoji.inputmethod/com.android.inputmethod.latin.LatinIME') # 点击设定 self.BF.click('id', 'com.qisiemoji.inputmethod:id/item_settigns') # 点击语言 self.BF.click('name', 'Language') # time.sleep(10) # 选择语言的时候最好根据自上而下的顺序这样就很快的都能加上 # self.reach_language_add('Español (US)') # self.reach_language_add('Português (Brasil)') # self.driver.back() # self.BF.click('name', 'Language') # if self.BF.existence('name', 'Español (US)') and self.BF.existence('name', # 'English (US)') and self.BF.existence('name', # 'Português (Brasil)'): # pass # else: # assert 1 + 1 > 2, '语言添加失败' self.driver.start_activity('yuside.cn.numbersonly', 'yuside.cn.numbersonly.MainActivity') # 获取的高度不是默认的高度 top_y = self.BF.keyboard_get_ready(Typewriting, 'class', 'android.widget.ScrollView') keyboard = Keyboard_Operation(self.driver, top_y) self.driver.back() self.BF.click('xpath', '//android.widget.EditText[@index="0"]') # 重新获取键盘高度 top_y = self.BF.keyboard_get_ready(Typewriting, 'class', 'android.widget.ScrollView') keyboard = Keyboard_Operation(self.driver, top_y) keyboard.send_input('emoji') self.driver.back() self.BF.click('xpath', '//android.widget.EditText[@index="0"]') keyboard.send_input('emoji') keyboard.send_input('emoji', 'emoji') keyboard.select_emoji('emoji', 1, 3) emoji = self.BF.attribute_name('xpath', '//android.widget.EditText[@index="0"]', '😂') self.BF.check_assertTrue(emoji, 'emoji默认设置取消失败') # 寻找语言添加到键盘中(language根据应用中来选取) def reach_language_add(self, language): # 'Español' # 滑动高度v_y是根据语言名称外面的layout控件的高度来的有需要自己设定 v_y = self.BF.element_size('id', 'com.qisiemoji.inputmethod:id/root', "height") self.BF.reach_element_click(v_y * 5, 'name', language) language_no = self.BF.elements('id', 'com.qisiemoji.inputmethod:id/tv_name') for i in range(len(language_no)): find_l = self.BF.attribute_name('ides', 'com.qisiemoji.inputmethod:id/tv_name[%s]' % i) if find_l == language: print(find_l) self.BF.click('ides', 'com.qisiemoji.inputmethod:id/tv_add[%s]' % i) def app_theme(self): self.BF.open_app_atcivity('com.qisiemoji.inputmethod/com.qisi.ikeyboarduirestruct.NavigationActivity') self.BF.keyboard_select('com.qisiemoji.inputmethod/com.android.inputmethod.latin.LatinIME') theme = self.BF.existence('name', 'Settings') if theme == False: count = 0 while True: try: self.BF.click('name', 'Allow') count += 1 except: time.sleep(3) if count == 3: break theme = self.BF.existence('name', 'Settings') self.BF.click('name', 'Theme') self.BF.check_assertTrue(theme, '进入Theme页面失败') def app_settings(self): self.BF.open_app_atcivity('com.qisiemoji.inputmethod/com.qisi.ikeyboarduirestruct.NavigationActivity') settings = self.BF.click_change('id', 'com.qisiemoji.inputmethod:id/item_settigns') self.BF.check_assertTrue(settings, '点击Setting失败') def old_new_app_theme(self, i, package, Typewriting, old, new): if self.device_config == 'none': try: unin_result = os.popen('adb uninstall %s' % package) except Exception as e: print(e) print('没有对应应用') else: try: unin_result = os.popen('adb -s %s uninstall %s' % (self.device_config, package)) except Exception as e: print(e) print('没有对应应用') # 安装老应用 # self.driver.install_app(old) o = os.popen('adb install -r %s' % old) print(o.read()) self.BF.keyboard_select(Typewriting) self.change_theme(i) self.driver.start_activity('yuside.cn.numbersonly', 'yuside.cn.numbersonly.MainActivity') # 截图 top_y = self.BF.keyboard_get_ready(Typewriting, 'class', 'android.widget.ScrollView') keyboard = Keyboard_Operation(self.driver, top_y) old_keyboard = keyboard.get_keyboard_picture(0, top_y + 40 * keyboard.density()['density'], keyboard.phone_width, (keyboard.density()['app'] - top_y - 40 * keyboard.density()[ 'density']) * 3 / 4, 'keyboard_old') self.driver.back() self.driver.back() # 强制安装 self.BF.adb_install(new, self.device_config) # 对比 # 以防键盘不弹起来 self.BF.keyboard_select(Typewriting) self.driver.start_activity('yuside.cn.numbersonly', 'yuside.cn.numbersonly.MainActivity') time.sleep(5) top_y = self.BF.keyboard_get_ready(Typewriting, 'class', 'android.widget.ScrollView') keyboard = Keyboard_Operation(self.driver, top_y) k = keyboard.keyboard_same(0, top_y + 40 * keyboard.density()['density'], keyboard.phone_width, (keyboard.density()['app'] - top_y - 40 * keyboard.density()[ 'density']) * 3 / 4, old_keyboard) # self.BF.check_assertTrue(k, '第%s个默认主题出现问题' % (no + 1)) return {'%s' % (i + 1): k} def old_new_app_font(self, i, package, Typewriting, old, new): if self.device_config == 'none': try: unin_result = os.popen('adb uninstall %s' % package) except Exception as e: print(e) print('没有对应应用') else: try: unin_result = os.popen('adb -s %s uninstall %s' % (self.device_config, package)) except Exception as e: print(e) print('没有对应应用') # 安装老应用 # self.driver.install_app(old) o = os.popen('adb install -r %s' % old) print(o.read()) self.BF.keyboard_select(Typewriting) self.cheage_font(i) self.driver.start_activity('yuside.cn.numbersonly', 'yuside.cn.numbersonly.MainActivity') # 截图 top_y = self.BF.keyboard_get_ready(Typewriting, 'class', 'android.widget.ScrollView') keyboard = Keyboard_Operation(self.driver, top_y) old_font = keyboard.get_keyboard_picture(0, top_y + 40 * keyboard.density()['density'], keyboard.phone_width, (keyboard.density()['app'] - top_y - 40 * keyboard.density()[ 'density']) * 3 / 4, 'font_old') self.driver.back() self.driver.back() # 强制安装 self.BF.adb_install(new, self.device_config) # 对比 self.BF.keyboard_select(Typewriting) self.driver.start_activity('yuside.cn.numbersonly', 'yuside.cn.numbersonly.MainActivity') time.sleep(5) top_y = self.BF.keyboard_get_ready(Typewriting, 'class', 'android.widget.ScrollView') keyboard = Keyboard_Operation(self.driver, top_y) k = keyboard.keyboard_same(0, top_y + 40 * keyboard.density()['density'], keyboard.phone_width, (keyboard.density()['app'] - top_y - 40 * keyboard.density()['density']) * 3 / 4, old_font) # self.BF.check_assertTrue(k, '第%s个默认字体出现问题' % (no + 1)) return {'%s' % (i + 1): k} def seekbar(self, how, element, x): seekbar_button = self.BF.check_find_element(how, element) seekbar_button_x = seekbar_button.location['x'] seekbar_button_y = seekbar_button.location['y'] seekbar_button_width = seekbar_button.size['width'] seekbar_button_height = seekbar_button.size['height'] # 调节 # begin_button_x = seekbar_button_x + seekbar_button_width begin_button_y = seekbar_button_y + seekbar_button_height / 2 # end_button_x = seekbar_button_x + seekbar_button_width / 2 # self.driver.swipe(start_x=begin_button_x * s_x, start_y=begin_button_y, end_x=end_button_x * e_x, # end_y=begin_button_y) self.driver.tap([(seekbar_button_x + seekbar_button_width * x, begin_button_y)]) def custom_keyboard(self): self.app_theme() self.BF.click('id', 'com.qisiemoji.inputmethod:id/fab') self.BF.click('id', 'com.qisiemoji.inputmethod:id/fab') # 选择背景 self.BF.random_click('xpath', '//android.support.v4.view.ViewPager/android.widget.FrameLayout/android.widget.ScrollView/android.widget.LinearLayout/android.widget.LinearLayout[3]/android.widget.ImageButton') # Effect设定 Effect = self.BF.click_change('name', 'Effect') self.BF.check_assertTrue(Effect, 'Effect点击无反应') theme_preview = self.BF.element_picture('id', 'com.qisiemoji.inputmethod:id/theme_preview') # 获取seekbar控件属性 self.seekbar('id', 'com.qisiemoji.inputmethod:id/seek_bar_color_brightness', 1 / 2) theme_preview_change = self.BF.cintrast_element_picture('id', 'com.qisiemoji.inputmethod:id/seek_bar_color_brightness', theme_preview) self.BF.check_assertFalse(theme_preview_change, 'Effect没有变化') # Button self.BF.click('name', 'Button') theme_preview_button = self.BF.element_picture('id', 'com.qisiemoji.inputmethod:id/theme_preview') self.BF.click_change('id', 'com.qisiemoji.inputmethod:id/button_2') theme_preview_button_change = self.BF.cintrast_element_picture('id', 'com.qisiemoji.inputmethod:id/theme_preview', theme_preview_button) self.BF.check_assertFalse(theme_preview_button_change, 'button2修改无变化') self.BF.click_change('id', 'com.qisiemoji.inputmethod:id/button_1') theme_preview_button1_change = self.BF.cintrast_element_picture('id', 'com.qisiemoji.inputmethod:id/theme_preview', theme_preview_button) self.BF.check_assertTrue(theme_preview_button1_change, 'button1点击无效果') theme_preview_button_seekbar = self.BF.element_picture('id', 'com.qisiemoji.inputmethod:id/theme_preview') self.seekbar('id', 'com.qisiemoji.inputmethod:id/seek_bar', 3 / 4) theme_preview_button_seekbar_change = self.BF.cintrast_element_picture('id', 'com.qisiemoji.inputmethod:id/theme_preview', theme_preview_button_seekbar) self.BF.check_assertFalse(theme_preview_button_seekbar_change, 'button seek没有变化') # Font self.BF.click('name', 'Font') theme_preview_fount = self.BF.element_picture('id', 'com.qisiemoji.inputmethod:id/theme_preview') self.seekbar('id', 'com.qisiemoji.inputmethod:id/seek_bar', 1 / 3) theme_preview_fount_change = self.BF.cintrast_element_picture('id', 'com.qisiemoji.inputmethod:id/theme_preview', theme_preview_fount) self.BF.check_assertFalse(theme_preview_fount_change, '字体大小没有变化') theme_preview_fount1 = self.BF.element_picture('id', 'com.qisiemoji.inputmethod:id/theme_preview') self.BF.random_click('id', 'com.qisiemoji.inputmethod:id/button') theme_preview_fount1_change = self.BF.cintrast_element_picture('id', 'com.qisiemoji.inputmethod:id/theme_preview', theme_preview_fount1) self.BF.check_assertFalse(theme_preview_fount1_change, '字体样式没有变化') # color 无法做 self.BF.click('id', 'com.qisiemoji.inputmethod:id/save') while True: try: self.BF.click('name', 'Theme saved successfully!') break except: pass self.BF.click('id', 'com.qisiemoji.inputmethod:id/md_buttonDefaultPositive') self.BF.result_picture('自定义键盘') def old_new_app_custom_keyboard(self, package, Typewriting, old, new): if self.device_config == 'none': try: unin_result = os.popen('adb uninstall %s' % package) except Exception as e: print(e) print('没有对应应用') else: try: unin_result = os.popen('adb -s %s uninstall %s' % (self.device_config, package)) except Exception as e: print(e) print('没有对应应用') # 安装老应用 o = os.popen('adb install -r %s' % old) print(o.read()) self.BF.keyboard_select(Typewriting) self.custom_keyboard() self.driver.tap([(200, 200)]) self.driver.back() self.driver.start_activity('yuside.cn.numbersonly', 'yuside.cn.numbersonly.MainActivity') # 截图 top_y = self.BF.keyboard_get_ready(Typewriting, 'class', 'android.widget.ScrollView') keyboard = Keyboard_Operation(self.driver, top_y) old_keyboard = keyboard.get_keyboard_picture(0, top_y + 40 * keyboard.density()['density'], keyboard.phone_width, (keyboard.density()['app'] - top_y - 40 * keyboard.density()[ 'density']) * 3 / 4, 'keyboard_old') self.driver.back() self.driver.back() # 强制安装 self.BF.adb_install(new, self.device_config) # 对比 self.BF.keyboard_select(Typewriting) self.driver.start_activity('yuside.cn.numbersonly', 'yuside.cn.numbersonly.MainActivity') time.sleep(5) top_y = self.BF.keyboard_get_ready(Typewriting, 'class', 'android.widget.ScrollView') keyboard = Keyboard_Operation(self.driver, top_y) k = keyboard.keyboard_same(0, top_y + 40 * keyboard.density()['density'], keyboard.phone_width, (keyboard.density()['app'] - top_y - 40 * keyboard.density()['density']) * 3 / 4, old_keyboard) self.BF.check_assertTrue(k, '自定义主题消失了') # 自定义主题 def change_custom_keyboard(self): self.app_theme() self.BF.click('id', 'com.qisiemoji.inputmethod:id/fab') before_change = self.BF.element_picture('ides', 'com.qisiemoji.inputmethod:id/item[0]') self.BF.click('id', 'com.qisiemoji.inputmethod:id/edit') self.BF.click('id', 'com.qisiemoji.inputmethod:id/edit_button_action') # 选择背景 background = self.BF.element_picture('id', 'com.qisiemoji.inputmethod:id/theme_preview') bg_count = 0 while True: self.BF.random_click('xpath', '//android.support.v4.view.ViewPager/android.widget.FrameLayout/android.widget.ScrollView/android.widget.LinearLayout/android.widget.LinearLayout[3]/android.widget.ImageButton') change_background = self.BF.cintrast_element_picture('id', 'com.qisiemoji.inputmethod:id/theme_preview', background) if change_background == False: c_b_g_r = True break else: bg_count += 1 if bg_count >= 10: c_b_g_r = False break self.BF.check_assertTrue(c_b_g_r, '超时或者背景修改失败') # Effect设定 Effect = self.BF.click_change('name', 'Effect') self.BF.check_assertTrue(Effect, 'Effect点击无反应') theme_preview = self.BF.element_picture('id', 'com.qisiemoji.inputmethod:id/theme_preview') # 获取seekbar控件属性 self.seekbar('id', 'com.qisiemoji.inputmethod:id/seek_bar_color_brightness', 1 / 3) theme_preview_change = self.BF.cintrast_element_picture('id', 'com.qisiemoji.inputmethod:id/seek_bar_color_brightness', theme_preview) self.BF.check_assertFalse(theme_preview_change, 'Effect没有变化') # Button self.BF.click('name', 'Button') theme_preview_button = self.BF.element_picture('id', 'com.qisiemoji.inputmethod:id/theme_preview') self.BF.click_change('id', 'com.qisiemoji.inputmethod:id/button_2') theme_preview_button_change = self.BF.cintrast_element_picture('id', 'com.qisiemoji.inputmethod:id/theme_preview', theme_preview_button) self.BF.check_assertFalse(theme_preview_button_change, 'button2修改无变化') theme_preview_button_seekbar = self.BF.element_picture('id', 'com.qisiemoji.inputmethod:id/theme_preview') self.seekbar('id', 'com.qisiemoji.inputmethod:id/seek_bar', 1 / 4) theme_preview_button_seekbar_change = self.BF.cintrast_element_picture('id', 'com.qisiemoji.inputmethod:id/theme_preview', theme_preview_button_seekbar) self.BF.check_assertFalse(theme_preview_button_seekbar_change, 'button seek没有变化') # Font self.BF.click('name', 'Font') theme_preview_fount = self.BF.element_picture('id', 'com.qisiemoji.inputmethod:id/theme_preview') self.seekbar('id', 'com.qisiemoji.inputmethod:id/seek_bar', 2 / 3) theme_preview_fount_change = self.BF.cintrast_element_picture('id', 'com.qisiemoji.inputmethod:id/theme_preview', theme_preview_fount) self.BF.check_assertFalse(theme_preview_fount_change, '字体大小没有变化') theme_preview_fount1 = self.BF.element_picture('id', 'com.qisiemoji.inputmethod:id/theme_preview') f_count = 0 while True: self.BF.random_click('id', 'com.qisiemoji.inputmethod:id/button') theme_preview_fount1_change = self.BF.cintrast_element_picture('id', 'com.qisiemoji.inputmethod:id/theme_preview', theme_preview_fount1) if theme_preview_fount1_change == False: c_f_r = True break else: f_count += 1 if bg_count >= 10: c_f_r = False break self.BF.check_assertTrue(c_f_r, '超时或者字体修改失败') # color 无法做 self.BF.click('id', 'com.qisiemoji.inputmethod:id/save') while True: try: self.BF.click('name', 'Theme saved successfully!') break except: pass self.BF.click('id', 'com.qisiemoji.inputmethod:id/md_buttonDefaultPositive') self.BF.result_picture('自定义键盘修改结果') self.driver.back() self.BF.click('id', 'com.qisiemoji.inputmethod:id/edit') after_change = self.BF.cintrast_element_picture('ides', 'com.qisiemoji.inputmethod:id/item[0]', before_change) self.BF.check_assertFalse(after_change, '自定义键盘修改失败') # 选择第i个默认主题 def change_theme(self, i): self.app_theme() self.BF.click('name', 'Theme') self.BF.click('id', 'com.qisiemoji.inputmethod:id/fab') time.sleep(2) no = i if i > 7: self.driver.swipe(start_x=self.driver.get_window_size()['width'] / 2, start_y=self.driver.get_window_size()['height'] * 3 / 4, end_x=self.driver.get_window_size()['width'] / 2, end_y=self.driver.get_window_size()['height'] / 4) if i == 8: i = 4 elif i == 9: i = 5 elif i == 10: i = 6 elif i == 11: i = 7 self.BF.click('ides', 'com.qisiemoji.inputmethod:id/item[%s]' % i) self.driver.tap([(200, 200)]) self.driver.back() def random_download_theme(self): self.app_theme() self.BF.click('name', 'More') self.BF.random_click('id', 'com.qisiemoji.inputmethod:id/item') self.BF.click('id', 'com.qisiemoji.inputmethod:id/button_download') count_install = 0 while True: ex = self.BF.existence('id', 'com.android.vending:id/buy_button') if ex == True: self.BF.click('id', 'com.android.vending:id/buy_button') while_result1 = True break else: count_install += 1 time.sleep(3) if count_install > 10: while_result1 = False break self.BF.check_assertTrue(while_result1, '未跳转到主题下载页') count_open = 0 while True: ex = self.BF.existence('id', 'com.android.vending:id/launch_button') if ex == True: self.BF.click('id', 'com.android.vending:id/launch_button') while_result2 = True break else: count_open += 1 time.sleep(3) if count_open > 20: while_result2 = False break self.BF.check_assertTrue(while_result2, '打开主题失败') time.sleep(10) self.BF.click('name', 'ACTIVATE THEME') def clear_download_theme(self): self.app_theme() self.BF.click('id', 'com.qisiemoji.inputmethod:id/fab') self.BF.click('id', 'com.qisiemoji.inputmethod:id/edit') while True: self.BF.click('id', 'com.qisiemoji.inputmethod:id/delete_button_action') self.BF.click('name', 'OK') time.sleep(8) if self.BF.existence('name', 'Downloaded') is False: break print('下载主题清理完毕') def change_emoji_style(self, i): self.app_theme() self.BF.click('name', 'Emoji') self.BF.click('id', 'com.qisiemoji.inputmethod:id/fab') self.BF.click('ides', 'com.qisiemoji.inputmethod:id/card_view[%s]' % i) def random_download_emoji_style(self): self.app_theme() self.BF.click('name', 'Emoji') self.BF.random_click('id', 'com.qisiemoji.inputmethod:id/card_view') self.BF.click('id', 'com.qisiemoji.inputmethod:id/button_download') count_install = 0 while True: ex = self.BF.existence('id', 'com.android.vending:id/buy_button') if ex == True: self.BF.click('id', 'com.android.vending:id/buy_button') while_result1 = True break else: count_install += 1 time.sleep(3) if count_install > 10: while_result1 = False break self.BF.check_assertTrue(while_result1, '未跳转到emoji_style下载页') count_open = 0 while True: ex = self.BF.existence('id', 'com.android.vending:id/launch_button') if ex == True: self.BF.click('id', 'com.android.vending:id/launch_button') while_result2 = True break else: count_open += 1 time.sleep(3) if count_open > 20: while_result2 = False break self.BF.check_assertTrue(while_result2, '打开emoji_style失败') time.sleep(10) self.driver.back() self.BF.click('name', 'ACTIVATE EMOJI') def clear_download_emoji_style(self): self.app_theme() self.BF.click('name', 'Emoji') self.BF.click('id', 'com.qisiemoji.inputmethod:id/fab') self.BF.click('id', 'com.qisiemoji.inputmethod:id/edit') while True: self.BF.click('id', 'com.qisiemoji.inputmethod:id/button_action') self.BF.click('name', 'OK') time.sleep(8) if self.BF.existence('id', 'com.qisiemoji.inputmethod:id/button_action') is False: break print('下载emoji_style清理完毕') def cheage_font(self, i): self.app_theme() y = self.BF.check_find_element('id', 'com.qisiemoji.inputmethod:id/tab_layout').location["y"] phone = self.driver.get_window_size() self.driver.swipe(start_x=phone['width'] / 2, start_y=y + 10, end_x=0, end_y=y + 10) self.BF.click('name', 'Font') self.BF.click('id', 'com.qisiemoji.inputmethod:id/fab') no = i print(len(self.BF.elements('id', 'com.qisiemoji.inputmethod:id/text_font_preview'))) self.BF.click('ides', 'com.qisiemoji.inputmethod:id/text_font_preview[%s]' % i) self.driver.tap([(200, 200)]) self.driver.back() def random_download_font(self): self.app_theme() self.BF.click('name', 'Sound') self.BF.click('name', 'Font') self.BF.random_click('id', 'com.qisiemoji.inputmethod:id/text_font_preview') self.BF.click('id', 'com.qisiemoji.inputmethod:id/button_download') count_install = 0 while True: ex = self.BF.existence('name', 'Apply') if ex == True: self.BF.click('name', 'Apply') while_result1 = True break else: count_install += 1 time.sleep(3) if count_install > 10: while_result1 = False break self.BF.check_assertTrue(while_result1, '获取字体失败') self.driver.back() def clear_font(self): self.app_theme() self.BF.click('name', 'Sound') self.BF.click('name', 'Font') self.BF.click('id', 'com.qisiemoji.inputmethod:id/fab') self.BF.click('id', 'com.qisiemoji.inputmethod:id/edit') while True: self.BF.click('id', 'com.qisiemoji.inputmethod:id/action_delete') time.sleep(8) if self.BF.existence('id', 'com.qisiemoji.inputmethod:id/action_delete') is False: break print('下载font清理完毕')