Robotium 之Android 功能自动化测试关于关键盘弹出的处理

在利用Robotium做功能自动化测试的时候,常常由于一些EditText等的虚拟键盘弹出问题,导致额外的工作量来处理虚拟键盘的问题。

现在指定一种处理虚拟键盘的方法:

InputMethodManager:

Central system API to the overall input method framework (IMF) architecture, which arbitrates interaction between applications and the current input method. You can retrieve an instance of this interface with .

InputMethodManager是用来控制输入法的: 
Java代码 InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);  
用: 
Java代码 if (imm.isActive())  
来检查虚拟键盘是不是在开启的状态 
然后可以用toggle方法来关闭它 
Java代码 imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_NOT_ALWAYS);  
当然如果当前虚拟键盘是关闭的, toggle就会开启键盘. 
InputMethodManager也有独立开启和关闭的方法: 
Java代码 imm.showSoftInput(view, flags); 

 imm.showSoftInputFromInputMethod(token, flags);  

imm.hideSoftInputFromInputMethod(token, flags);  


在robotium种如此处理:

InputMethodManager imm = (InputMethodManager) solo.getCurrentActivity().getSystemService(Context.INPUT_METHOD_SERVICE);

assertTrue(imm.isActive());

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值