Robotium体验----录屏(失败)& 放弃

Robotium除了架构简单的特点之外,录屏是其提供的又一利器,能将操作自动转化为代码,事半功倍。

但在尝试过程中,各种碰壁,最终导致放弃使用Robotium框架的念头产生。

网上各种教程,要么是基于 eclipse,要么是AS低版本,且年头久远,以致可参考的资料不多。

无解之际,直接email其开发人员Renas Reda(renasreda@gmail.com,https://blog.jayway.com/2014/01/20/introducing-robotium-recorder/,也不知是否跳槽了~),并在github提问(https://github.com/RobotiumTech/robotium/issues/873),皆未得到回复。

查看Robotium版本信息,发现已是2016年底的事情。至今是否还在维护,存在变数。

此外,心中还有一疑问。是否是免费版本的缘故?如果只是体验,每年小200刀,真心不想花~

但不能因为简单的个人体验,而否定一个框架,因此本文将记录,使用Robotium Recorder插件过程中所遇到的问题(Android Studio3.0.1)。若有解题者,更是一种延续。

Robotium Recorder安装

在Android Studio中,安装Robotium Recorder十分的简单。官方提供了相应插件。

Alt+Ctrol+S进入Settings,之后按图操作,即可完成安装。

Robotium体验----录屏(失败)& 放弃_第1张图片

Robotium体验----录屏(失败)& 放弃_第2张图片

安装完毕后,重新启动Android Studio。如果Tool菜单下,出现Rototium Recorder,则安装成功。如下图。

Robotium体验----录屏(失败)& 放弃_第3张图片

当前版本,我2016年的2.5版,免费。

接下来,看一下如何使用。

若在录制过程中,出现任何异常,插件都会将log保存至:C:\Users\XXXX\Robotium_log.txt中(XXXX为当前用户)。

在录制前,需要注意,

需要提前设置ANDROID_HOME,否则录制报错。提示未找到ANDROID_HOME

What went wrong: A problem occurred evaluating root project 'executorproject'. > SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.  * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

录屏(失败)

本节录屏分3个步骤,其中问题出在步骤(3)。

个人分析后,认为是Android Studio与Robotium Record兼容性问题,导致录屏失败。至今,并未找到解决方案。

如有不同观点,望拍砖指点~

(1)点击Robotium Recorder便可开始录屏。

Robotium体验----录屏(失败)& 放弃_第4张图片

用户可以在当前界面中选择,所要测试的APK。确定目标后,插件会列出APK中的模块(app)。默认不选择任何模块,即对APK整体进行测试。

用户还需要给出test module名称,即所生成的测试脚本所保存的模块名称,插件将自动生成该模块。

选定APK后,插件将在该APK同路径下,生成debug版本(重签名),如下图。

Robotium体验----录屏(失败)& 放弃_第5张图片

插件还自动记录上次测试的apk。若长时间未选择APK,插件将载入上次测试所用apk。

点击“Next”,进入下一界面。

Robotium体验----录屏(失败)& 放弃_第6张图片

(2)录屏Settings.

Robotium体验----录屏(失败)& 放弃_第7张图片

Runtime options中有4个选项

Use sleeps - 是否会使用sleeps方法,来保证回放测试用例的速度和录制的时候相同,该配置对那些带宽密集型或者混合App特别有用。简单讲,就是在生成的测试用例中调用sleep()方法来模拟用户录制时的操作间隔,如果不设置的话,该recorder只会捕捉到用户和Activity的动作,但是回放的时候会顺序瞬间执行。

Keep app data - 如果开启一个新的脚本录制的时候,是否保留App的数据。

Identify class over string - 默认的视图标识符通常为Resource ID,如果Resource ID丢失,可以选择一个视图类标识符来代替字符串标识符。

Click and drag coordinates - 选择在点击和拖拽的时候是否录制坐标。

再看一下Saved paths,用于设置Android SDK和JDK路径。

Robotium体验----录屏(失败)& 放弃_第8张图片

License key界面则是用于导入license key。

Robotium体验----录屏(失败)& 放弃_第9张图片

(3)开始录屏

点击“New Robotium Test”,开始录屏。若无真机,插件将自动创建虚拟设备。

插件将自动安装debug版本的APK至测试端,安装完毕后开始正式录屏。

错误也出现在此处。插件提示

Robotium体验----录屏(失败)& 放弃_第10张图片

查看log,提示Gradle版本太高(4.1),应降至2.2

Input: 

C:\D\proj\robotiumDiary\gradlew.bat -Dorg.gradle.daemon=true assembleDebugTest -u -b C:\D\proj\robotiumDiary\executorproject\build.gradle 


Output: 

 Starting a Gradle Daemon, 1 incompatible Daemon could not be reused, use --status for details  
FAILURE: Build failed with an exception.  
* Where: Build file 'C:\D\proj\robotiumDiary\executorproject\build.gradle' line: 13  
* What went wrong: A problem occurred evaluating root project 'executorproject'. 
> Failed to apply plugin [id 'com.android.application']    
> Gradle version 2.2 is required. Current version is 4.1. 
If using the gradle wrapper, try editing the distributionUrl in C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Android Studio\gradle\wrapper\gradle-wrapper.properties to gradle-2.2-all.zip  
* Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.  * Get more help at https://help.gradle.org  BUILD FAILED in 20s

由于Gradle版本跟Android Stuido中的Gradle插件存在对应关系,可参见

https://developer.android.com/studio/releases/gradle-plugin.html#updating-gradle。

因此,修改Gradle版本的同时,也需要修改Gradle插件版本号。

由于版本降低,导致Repositories中的google()方法不能使用。因此,也要对google()方法进行注释。

在Project Setting中进行相应修改。

Robotium体验----录屏(失败)& 放弃_第11张图片

之后,再次编译,却出错。提示

Error:Unsupported method: BaseConfig.getApplicationIdSuffix().
The version of Gradle you connect to does not support that method.
To resolve the problem you can change/upgrade the target version of Gradle you connect to.
Alternatively, you can ignore this exception and read other information from the model.

网上对于该问题的解决方式,多是提升gradle plugin版本,而这与我们要做的(降低gradle版本,匹配Robotium Recorder需求)相冲突。

因此,个人推断,由于gradle plugin(1.0.0)版本太低,与Android Studio3.0.1不兼容。

转换思路,降低Android Studio版本,再次尝试。

使用Android Studio1.0,Gradle version2.2,Gradle plugin versioin1.0再次尝试。录屏时,再次报错。

Incremental java compilation is an incubating feature.  
FAILURE: Build failed with an exception.  
* What went wrong: A problem occurred configuring root project 'executorproject'. > 
Could not resolve all dependencies for configuration ':_debugAndroidTestCompile'.    > 
Could not find :ExecutorLibrary:.      
Searched in the following locations:          
https://repo1.maven.org/maven2//ExecutorLibrary//ExecutorLibrary-.pom          
https://repo1.maven.org/maven2//ExecutorLibrary//ExecutorLibrary-.aar          
file:/C:/D/proj/testRR/executorproject/libs/ExecutorLibrary-.aar          
file:/C:/D/proj/testRR/executorproject/libs/ExecutorLibrary.aar          
file:/C:/Users/user/AppData/Local/Android/sdk/extras/android/m2repository//ExecutorLibrary//ExecutorLibrary-.pom          
file:/C:/Users/user/AppData/Local/Android/sdk/extras/android/m2repository//ExecutorLibrary//ExecutorLibrary-.aar          
file:/C:/Users/user/AppData/Local/Android/sdk/extras/google/m2repository//ExecutorLibrary//ExecutorLibrary-.pom          
file:/C:/Users/user/AppData/Local/Android/sdk/extras/google/m2repository//ExecutorLibrary//ExecutorLibrary-.aar          
file:/C:/Users/user/AppData/Local/Android/sdk/extras/m2repository//ExecutorLibrary//ExecutorLibrary-.pom          
file:/C:/Users/user/AppData/Local/Android/sdk/extras/m2repository//ExecutorLibrary//ExecutorLibrary-.aar      
Required by:          
:executorproject:unspecified  
* Try: Run with --stacktrace option to get the stack trace. 
Run with --info or --debug option to get more log output.  
BUILD FAILED  Total time: 15.501 secs

查看本地目录,确实不存在ExecutorLibrary相关文件。再次查找maven相关路径,也未找到。

网上搜索ExecutorLibrary关键字,无解答。

于是github提问,并email联系相关开发者,未得到回复。

之后,也怀疑Robotium Recorder插件与Android Studio版本匹配问题。几经尝试,仍是Block在ExecutorLibrary处。

至此,对于Robotium录屏心灰意冷~


小结

本文仅在Android Stuido环境下,对Robotium Recorder进行了尝试,最终并未成功。Eclipse下并未做尝试,因此,并不敢保证Robotium Recorder不能被使用。且使用版本为免费版,尝试过程中也可能存在偏差,所以,不管妄下断论。

之后对于Robotium的体验,也多是集中在API的使用,纯代码而已,按照其document不会有太大偏差。

之所以在此停止体验,原因归结如下:

(1)Robotium架构相比其它框架,需要额外重签名,受制于DEBUG版本。

(2)Robotium不能跨进程,且解决跨进程的方案开销大。

(3)Robotium录屏功能,在Android Studio下存在兼容性问题。

(4)Robotium版本维护存疑。

你可能感兴趣的:(android测试,Android自动化测试)