def theme(self): top_y = self.BF.keyboard_get_ready('com.qisiemoji.inputmethod/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') pic_text = keyboard.pic_text(pic_text) if '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_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' 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 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 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()
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()
def old_new_app_custom_keyboard(self, package, typewriting, old, new): if self.device == '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, 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.BF.open_app_atcivity( 'com.emoji.ikeyboard/com.qisi.ikeyboarduirestruct.NavigationActivity', self.device) # 截图 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) # 对比 self.BF.keyboard_select(typewriting) self.BF.open_app_atcivity( 'com.emoji.ikeyboard/com.qisi.ikeyboarduirestruct.NavigationActivity', self.device) 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 old_new_app_theme(self, i, package, typewriting, old, new): if self.device == '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, 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.BF.open_app_atcivity( 'com.emoji.ikeyboard/com.qisi.ikeyboarduirestruct.NavigationActivity', self.device) 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) # 对比 # 以防键盘不弹起来 self.BF.keyboard_select(typewriting) self.BF.open_app_atcivity( 'com.emoji.ikeyboard/com.qisi.ikeyboarduirestruct.NavigationActivity', self.device) 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 input(self): top_y = self.BF.keyboard_get_ready( 'com.qisiemoji.inputmethod/com.android.inputmethod.latin.LatinIME', 'class', 'android.widget.ScrollView') keyboard = Keyboard_Operation(self.d, top_y) default = keyboard.get_keyboard_picture( 0, top_y, keyboard.phone_width, 40 * keyboard.density()['density'], 'indian_default') self.BF.click('xpath', '//android.widget.EditText[@index="1"]') wrong = [] with open('./vocab_hinglish', 'r') as word_list: for line in word_list: print(line) print(line.split('\n')[0]) keyboard.send_input(line.split('\n')[0].lower(), number=True) keyboard.send_input(' ', number=True) same = keyboard.keyboard_same(0, top_y, keyboard.phone_width, 40 * keyboard.density()['density'], default, diff=2) print(same) key = self.BF.attribute_name( 'xpath', '//android.widget.EditText[@index="1"]') if line.split('\n')[0] in key: key = True else: key = False print(key) # self.BF.check_find_element('xpath', '//android.widget.EditText[@index="1"]').clear() count = 0 while True: keyboard.send_input('delete') count += 1 if count > 8: break if key is True and same is False: pass else: wrong.append(line.split('\n')[0]) print(wrong) print(wrong)
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 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 test_add_language(self): print('Test add language, swipe and screenshot keyboard: ') new = '/Users/yanqing.xu/Downloads/app-kika-215101-release-ef36305.apk' old = '/Users/yanqing.xu/Downloads/app-kika-214801-release-60bf8dd.apk' package = 'com.qisiemoji.inputmethod' Typewriting = package + '/com.android.inputmethod.latin.LatinIME' activity = package + '/com.qisi.ikeyboarduirestruct.NavigationActivity' # 添加和截取键盘个数 num = 50 # 滑动添加时滑动次数 rd = 20 for i in range(0, 11): if self.kika.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('没有对应应用') os.system('adb install -r %s' % old) # 安装测试包并设置默认输入法 # del_package = 'com.qisiemoji.inputmethod' self.BF.keyboard_select(Typewriting) time.sleep(2) self.BF.open_app_atcivity(activity) time.sleep(3) self.BF.click('name', 'Settings') time.sleep(1) self.BF.click('name', 'Language') # 获取手机分辨率,计算右下角add大概坐标 # adb shell dumpsys window displays |head -n 3计算x y dis = os.popen('adb shell dumpsys window displays |head -3').read() x = re.findall(r'init\=(.*?)x', dis)[0] y = re.findall(r'x(.*?)\s', dis)[0] swipex = int(x) * 1 / 2 swipey1 = int(y) * 3 / 4 swipey2 = int(y) * 1 / 4 addx = int(x) - 30 addy = int(y) - 100 swipe = 'adb shell input swipe ' add = 'adb shell input tap ' # 向上滑 for i in range(rd): print("swipe time:", i) ret = os.popen(swipe + str(int(swipex)) + ' ' + str(int(swipey1)) + ' ' + str(int(swipex)) + ' ' + str(int(swipey2))) ret.close() # 点击add添加所有language for j in range(num): print('Add language time:', j) try: self.BF.check_find_element('name', 'Yes') time.sleep(0.5) self.BF.click('name', 'Yes') except: pass os.system(add + str(addx) + ' ' + str(addy)) os.system('adb shell am start -n yuside.cn.numbersonly/.MainActivity') time.sleep(1) top_y = self.BF.keyboard_get_ready(Typewriting, 'class', 'android.widget.ScrollView') keyboard = Keyboard_Operation(self.d, top_y) width = keyboard.phone_width # 获取空格键位置 sp = keyboard.keyboard_reader(' ') height = (keyboard.phone_height - top_y) time.sleep(1) picinfo = dict() for k in range(num): keyboard.swip_location(sp['x'], sp['y'], sp['width'], sp['height']) time.sleep(1) picinfo[k] = keyboard.get_keyboard_picture(0, top_y, width, height, 'lang') # ******************分割线********* # 等待几秒,安装新版包,做截图对比 time.sleep(2) os.system('adb uninstall %s' % package) os.system('adb install -r %s' % new) self.BF.keyboard_select(Typewriting) self.BF.open_app_atcivity(activity) time.sleep(3) self.BF.click('name', 'Settings') time.sleep(1) self.BF.click('name', 'Language') for i in range(rd): print("swipe time:", i) ret = os.popen(swipe + str(int(swipex)) + ' ' + str(int(swipey1)) + ' ' + str(int(swipex)) + ' ' + str(int(swipey2))) ret.close() # 点击add添加所有language for j in range(num): print('Add language time:', j) try: self.BF.check_find_element('name', 'Yes') time.sleep(0.5) self.BF.click('name', 'Yes') except: pass os.system(add + str(addx) + ' ' + str(addy)) os.system('adb shell am start -n yuside.cn.numbersonly/.MainActivity') self.BF.keyboard_get_ready(Typewriting, 'class', 'android.widget.ScrollView') for k in range(num): keyboard.swip_location(sp['x'], sp['y'], sp['width'], sp['height']) time.sleep(1) keyboard.keyboard_same(0, top_y, width, height, picinfo[k]) time.sleep(1)