微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

常用adb命令学习:查看和修改设备的输入法

自动化测试过程中,有时可能会需要设置Android设备的输入法的场景时

如:运行了appium后,会自动切换到appium的输入法(io.appium.settings/.UnicodeIME),在之后的手动使用时,每次均需要去手机设置内调整输入法,较为麻烦,即可借助adb命令来实现自动修改

如:使用airtest输入时,需切换到airtest输入法(com.netease.nie.yosemite/.ime.ImeService)

  • 获取设备当前使用的输入法

     # 会输出当前设备正在使用的输入法
    adb shell settings get secure default_input_method
    
  • 获取当前设备已安装的输入法

    # 会输出当前设备的全部输入法的详细信息
    adb shell ime list
    # 仅输出当前设备的全部输入法名称
    adb shell ime list -s
    
  • 修改当前设备的输入法

    方法一:
    	adb shell ime set xxxxxx
    
        如:
            adb shell ime set io.appium.settings/.UnicodeIME	# 切换至appium UnicodeIME输入法
            adb shell ime set com.netease.nie.yosemite/.ime.ImeService	# 切换至airtest yosemite输入法
    	
    方法二:
    	adb shell settings put secure default_input_method	xxxxxx
        如:
            adb shell settings put secure default_input_method io.appium.settings/.UnicodeIME	# 切换至appium UnicodeIME输入法
            adb shell settings put secure default_input_method com.netease.nie.yosemite/.ime.ImeService	# 切换至airtest yosemite输入法
    
  • Python + airtest 的使用示例

    def setting_writing_type(self, var):
        """
        设置设备的输入法
        :param var: sou_gou, appium, air_test
        """
        writing = {
        'sou_gou': 'com.sohu.inputmethod.sogou.xiaomi/.sogouIME',
        'appium': 'io.appium.settings/.UnicodeIME',
        'air_test': 'com.netease.nie.yosemite/.ime.ImeService'
        }
    
        shell(f'settings put secure default_input_method {writing[var]}')
        
    
    # 使用示例
    
    # 设置输入法为yosemite
    self.setting_writing_type('air_test')
    """
    完成输入行为,完成测试
    """
    # 修改认搜狗输入法
    self.setting_writing_type('sou_gou')
    

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐