android UiAutomator如何根据颜色判断控件的状态
来源:互联网 发布:穿越火线刮刮乐软件 编辑:程序博客网 时间:2024/05/16 12:20
本人在用UiAutomator做测试的时候,经常会遇到一些控件因为不同的条件显示不同的颜色,在学习了UiAutomator图像处理之后,自己尝试写了一个方法来处理不同颜色控件的区分。分享代码供大家参考。
//根据颜色判断状态public boolean isBlue(UiObject uiObject) throws UiObjectNotFoundException {screenShot("test");//截图String path = "/mnt/sdcard/123/test.png";Bitmap bitmap = BitmapFactory.decodeFile(path);//新建并实例化bitmap对象Rect rect = uiObject.getVisibleBounds();int x = rect.left;int xx = rect.right;int y = rect.top;int yy = rect.bottom;List<Integer> blueColor = new ArrayList<Integer>();for (int i = x; i < xx; i++) {for (int k = y;k < yy;k++) {int color = bitmap.getPixel(i, k);//获取坐标点像素颜色int red = Color.blue(color);blueColor.add(red);}}int sum = 0;for (int i = 0;i<blueColor.size();i++) {sum += blueColor.get(i);}//output(sum/blueColor.size());return sum/blueColor.size() > 200?true:false;}
下面是在选择判定值的过程中快速获取某点颜色值的方法:
public int getRedPixel(int x, int y) {screenShot("test");//截图String path = "/mnt/sdcard/123/test.png";Bitmap bitmap = BitmapFactory.decodeFile(path);//新建并实例化bitmap对象int color = bitmap.getPixel(x, y);//获取坐标点像素颜色//output(color);//输出颜色值int red = Color.red(color);return red;}public int getGreenPixel(int x, int y) {screenShot("test");//截图String path = "/mnt/sdcard/123/test.png";Bitmap bitmap = BitmapFactory.decodeFile(path);//新建并实例化bitmap对象int color = bitmap.getPixel(x, y);//获取坐标点像素颜色//output(color);//输出颜色值int green = Color.green(color);return green;}public int getBluePixel(int x, int y) {screenShot("test");//截图String path = "/mnt/sdcard/123/test.png";Bitmap bitmap = BitmapFactory.decodeFile(path);//新建并实例化bitmap对象int color = bitmap.getPixel(x, y);//获取坐标点像素颜色//output(color);//输出颜色值int blue = Color.blue(color);return blue;}
public int[] getRGBcolorPixel(int x, int y) {screenShot("testDemo");String path = "/mnt/sdcard/123/testDemo.png";Bitmap bitmap = BitmapFactory.decodeFile(path);int color = bitmap.getPixel(x, y);int red = Color.red(color);int green = Color.green(color);int blue = Color.blue(color);int[] rgb = {red, green, blue};return rgb;}
阅读全文
0 0
- android UiAutomator如何根据颜色判断控件的状态
- 精确获取屏幕尺寸 判断是否是平板 文字根据状态更改颜色 android:textColor 背景色根据状态更改颜色 android:backgroup 启动APK的默认Activit
- 文字根据状态改变颜色 android:textColor
- Android 如何判断网络的连接状态
- Android 根据触摸状态切换背景,颜色,字体等状态
- android 控件点击状态颜色变化
- 判断控件状态的函数
- 如何调试 android UIAutomator ?
- 根据交换机的端口状态判断网络故障
- extjs的grid控件如何根据值来设置某行的背景颜色
- 背景色根据状态更改颜色 android:backgroup
- android UiAutomator自定义一个判断当前版本的方法
- UIAutomator定位Android控件的方法实践和建议
- UiAutomator中android.widget.ListView控件的子元素遍历
- UIAutomator定位Android控件的方法(渐进篇)
- 如何设置Android中控件的颜色透明度
- 如何设置Android中控件的颜色透明度
- 如何改变控件的颜色
- kafka管理器kafka-manager部署安装
- Java8源码-Map总结
- 把数组排成最小的数
- ubuntu 修改默认root密码
- ionic2 遇到的一些小问题
- android UiAutomator如何根据颜色判断控件的状态
- html学习7—目录
- 小程序文档整理之 -- API(调试接口)
- Git详解汇总
- MyISAM和InnoDB的区别
- [cvpr2017]Adversarial Discriminative Domain Adaptation
- &&与&
- 编程技巧干货笔记 【数组范围界定】
- 利用浏览器,js代码,json和字符串互相转化