bootstrap之UpdateStrings
UpdateStrings
package io.appium.android.bootstrap.handler; import io.appium.android.bootstrap.AndroidCommand;
import io.appium.android.bootstrap.AndroidCommandResult;
import io.appium.android.bootstrap.CommandHandler;
import io.appium.android.bootstrap.Logger; import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream; import org.json.JSONObject; /**
* This handler is used to update the apk strings.
*
*/
public class UpdateStrings extends CommandHandler { /**
* strings.json文件保存的是apk的strings.xml里的内容,在Bootstrap启动前由appium服务器解析并push到设备端的
*
* @return
*/
public static boolean loadStringsJson() {
Logger.debug("Loading json...");
try {
final String filePath = "/data/local/tmp/strings.json";
final File jsonFile = new File(filePath);
// json will not exist for apks that are only on device
// 你的case必须写明apk的路径,假设启动设备上已有的应用而case中没有app路径,此时json文件是不存在的
// because the node server can't extract the json from the apk.
if (!jsonFile.exists()) {
return false;
}
final DataInputStream dataInput = new DataInputStream(
new FileInputStream(jsonFile));
final byte[] jsonBytes = new byte[(int) jsonFile.length()];
dataInput.readFully(jsonBytes);
// this closes FileInputStream
dataInput.close();
final String jsonString = new String(jsonBytes, "UTF-8");
// 将读取出来的信息赋给Find类中的属性,以做后用
Find.apkStrings = new JSONObject(jsonString);
Logger.debug("json loading complete.");
} catch (final Exception e) {
Logger.error("Error loading json: " + e.getMessage());
return false;
}
return true;
} /*
* @param command The {@link AndroidCommand} used for this handler.
*
* @return {@link AndroidCommandResult}
*
* @see io.appium.android.bootstrap.CommandHandler#execute(io.appium.android.
* bootstrap.AndroidCommand)
*/
@Override
public AndroidCommandResult execute(final AndroidCommand command) {
if (!loadStringsJson()) {
return getErrorResult("Unable to load json file and update strings.");
}
return getSuccessResult(true);
}
}
在appium初始化的时候,假设你代码中加入了app应用,而不是启动手机设备中已经有的应用。这时候appium会将该app解析。并提取出设备当前语言环境的strings.xml文件中的信息保存在strings.json里,并将其push到手机的/data/local/tmp文件夹下,当你想要获取应用中用到的字符串时,手机会去该文件夹下读取strings.json文件并返回给client。
所以上面的代码也就是我上面说的过程。
bootstrap之UpdateStrings的更多相关文章
- bootstrap之Click大事
上一篇文章中谈到了bootstrap流程,本文开始把目光bootstrap它可以接受指令(从源代码视图的透视.因为appium该项目现在还处于不断更新,因此,一些指令已经实现.也许未来会实现一些.从视 ...
- Appium Android Bootstrap源码分析之命令解析执行
通过上一篇文章<Appium Android Bootstrap源码分析之控件AndroidElement>我们知道了Appium从pc端发送过来的命令如果是控件相关的话,最终目标控件在b ...
- Appuim源码剖析(Bootstrap)
Appuim源码剖析(Bootstrap) SkySeraph Jan. 26th 2017 Email:skyseraph00@163.com 更多精彩请直接访问SkySeraph个人站点:www. ...
- 手机自动化测试:appium源码分析之bootstrap三
手机自动化测试:appium源码分析之bootstrap三 研究bootstrap源码,我们可以通过代码的结构,可以看出来appium的扩展思路和实现方式,从中可以添加我们自己要的功能,针对app ...
- 手机自动化测试:appium源码分析之bootstrap二
手机自动化测试:appium源码分析之bootstrap二 在bootstrap项目中的io.appium.android.bootstrap.handler包中的类都是对应的指令类, priva ...
- 手机自动化测试:appium源码分析之bootstrap一
手机自动化测试:appium源码分析之bootstrap一 前言: poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.popte ...
- 手机自动化测试:appium源码分析之bootstrap十六
手机自动化测试:appium源码分析之bootstrap十六 poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.如果对课程感兴趣 ...
- appium框架之bootstrap
(闲来无事,做做测试..)最近弄了弄appium,感觉挺有意思,就深入研究了下. 看小弟这篇文章之前,先了解一下appium的架构,对你理解有好处,推荐下面这篇文章:testerhome appium ...
- 旺财速啃H5框架之Bootstrap(五)
在上一篇<<旺财速啃H5框架之Bootstrap(四)>>做了基本的框架,<<旺财速啃H5框架之Bootstrap(二)>>篇里也大体认识了bootst ...
随机推荐
- extjs表单验证
extjs表单验证 //放在onReady的function(){}中 Ext.QuickTips.init(); //为组件提供提示信息功能,form的主要提示信息就是客户端验证的错误信息. Ext ...
- Android之NDK开发环境r9
需要的软件: android-ndk-r9-windows-x86_64.zip(我的系统是64位的,所以下载的是64的)下载地址:http://developer.android.com/tools ...
- 卡方检验(Chi-square test/Chi-Square Goodness-of-Fit Test)
什么是卡方检验 卡方检验是一种用途很广的计数资料的假设检验方法.它属于非参数检验的范畴,主要是比较两个及两个以上样本率( 构成比)以及两个分类变量的关联性分析.其根本思想就是在于比较理论频数和实际频数 ...
- java.lang.ClassNotFoundException: Didn't find class "stu.love.neihan.MainActivity" on path: DexPathL
java.lang.ClassNotFoundException: Didn't find class "stu.love.neihan.MainActivity" on path ...
- 使用DBCA工具创建自己的数据库
ylbtech-Oracle:使用DBCA工具创建自己的数据库 DBCA创建数据库 默认安装的Oracle数据库一般不能满足实际应用的需求,例如数据库名称.数据库块的大小等都需要修改,那么我们应该自 ...
- Android中Intent的显示和隐式使用
Android应用程序中组件之间的通信都少不了Intent的使用,Intent负责对应用中一次操作的动作.动作涉及数据.附加数据进行描述,Android则根据此Intent的描述,负责找到对应的组件, ...
- 伪元素 :Before 和 :After的学习
层叠样式表(CSS)的主要目的是给HTML元素添加样式,然而,在一些案例中给文档添加额外的元素是多余的或是不可能的.事实上CSS中有一个特性允许我们添加额外元素而不扰乱文档本身,这就是“伪元素”. 你 ...
- Java8新特性之重复注解(repeating annotations)浅析
Java8新特性之重复注解(repeating annotations)浅析 学习了:https://www.jb51.net/article/50827.htm
- Oracle服务启动顺序导致ORA-12514
在window 上装了oracle11g,按照常规步骤安装完成后一切OK,如下图所示 C:\Users\Administrator>sqlplus /nolog SQL*Plus: Releas ...
- loadicon后一定要调用destroyicon吗
Remarks It is only necessary to call DestroyIcon for icons and cursors created with the following fu ...