Appium中文输入问题的一些探索

发表于:2015-4-23 11:02

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:厚脸皮说测试    来源:51Testing软件测试网博客

  在Appium Android Uiautomator中,输入方法就是这一段代码。从这一段代码中会发现Appium基本没有做什么事情,最终调用了Uiautomator本身的setText方法。所以,接下来需要确认原生的Uiautomator是否可以支持中文输入。 经过简单的测试发现,Uiautomator不支持中文输入,然后继续Google解决方案。发现了一个uiautomator-unicode-input-helper开源项目。直接拿来尝试了中文,也发现不对。按照作者的说法是可以支持日语,但是貌似想支持中文的话,还要进行一定量的开发。
  继续看看Uiautomator为什么不支持中文。然后继续找Android的源码,发现Uiautomator的所有的功能都是通过UiAutomatorBridge来完成的。在UiAutomatorBridge类中有一个成员变量类型是InteractionController。输入是通过InteractionController来实现的。具体的setText方法代码如下:
  Java
public boolean More ...sendText(String text) {
if (DEBUG) {
Log.d(LOG_TAG, "sendText (" + text + ")");
}
mUiAutomatorBridge.setOperationTime();
KeyEvent[] events = mKeyCharacterMap.getEvents(text.toCharArray());
if (events != null) {
for (KeyEvent event2 : events) {
// We have to change the time of an event before injecting it because
// all KeyEvents returned by KeyCharacterMap.getEvents() have the same
// time stamp and the system rejects too old events. Hence, it is
// possible for an event to become stale before it is injected if it
// takes too long to inject the preceding ones.
KeyEvent event = KeyEvent.changeTimeRepeat(event2,
SystemClock.uptimeMillis(), 0);
if (!injectEventSync(event)) {
return false;
}
}
}
return true;
}
  通过这段代码,基本上就明白了,Android的Uiautomator完全没有兼容英文以外的输入法的意思。并且也没有提供直接设置属性的方法。
  Appium Android Uiautomator 要支持输入中文还有很长的一段路需要走。伤心了。
22/2<12
《2023软件测试行业现状调查报告》独家发布~

精彩评论

  • 暗暗123
    2015-4-24 00:24:48

    这个方法会出现一个没有实现的  办企 业 资 质 证【Q2817230008。========+qq2817230008

      好吧,看源码。

      在使用Appium 的sendkeys方法是,Client会发送一个http请求到Appium的server。在AppiumServer端的源码中 有一个 rounting 的文件,输入方法会发送这样的路由

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号