博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
espresso Seekbar
阅读量:5108 次
发布时间:2019-06-13

本文共 3356 字,大约阅读时间需要 11 分钟。

1 package test.utils; 2  3 import android.support.test.espresso.PerformException; 4 import android.support.test.espresso.ViewAction; 5 import android.support.test.espresso.action.CoordinatesProvider; 6 import android.support.test.espresso.action.GeneralSwipeAction; 7 import android.support.test.espresso.action.Press; 8 import android.support.test.espresso.action.Swipe; 9 import android.support.test.espresso.util.HumanReadables;10 import android.view.View;11 import android.widget.SeekBar;12 13 import static android.support.test.espresso.action.ViewActions.actionWithAssertions;14 15 /**16  * Created by qiantao on 17-10-19.17  */18 19 public class SeekBarActions {20     public static ViewAction scrubSeekBarAction(int progress) {21         return actionWithAssertions(new GeneralSwipeAction(22                 Swipe.SLOW,23                 new SeekBarThumbCoordinatesProvider(-1),24                 new SeekBarThumbCoordinatesProvider(progress),25                 Press.PINPOINT));26     }27 28     /**29      * -1 表示起始位置30      */31     private static class SeekBarThumbCoordinatesProvider implements CoordinatesProvider {32         int mProgress;33 34         public SeekBarThumbCoordinatesProvider(int progress) {35             mProgress = progress;36         }37 38         private static float[] getVisibleLeftTop(View view) {39             final int[] xy = new int[2];40             view.getLocationOnScreen(xy);41             return new float[]{(float) xy[0], (float) xy[1]};42         }43 44         @Override45         public float[] calculateCoordinates(View view) {46             if (!(view instanceof SeekBar)) {47                 throw new PerformException.Builder()48                         .withViewDescription(HumanReadables.describe(view))49                         .withCause(new RuntimeException(String.format("SeekBar expected"))).build();50             }51             SeekBar seekBar = (SeekBar) view;52             int width = seekBar.getWidth() - seekBar.getPaddingLeft() - seekBar.getPaddingRight();53             LogUtils.i("seekBar.getProgress():" + seekBar.getProgress());54             double progress = mProgress == -1 ? seekBar.getProgress() : (mProgress * seekBar.getMax() / 100);55             int xPosition = (int) (seekBar.getPaddingLeft() + (width * progress / seekBar.getMax()));56             float[] xy = getVisibleLeftTop(seekBar);57             return new float[]{xy[0] + xPosition, xy[1]};58         }59     }60 }

 

检查Mtacher

 

public static Matcher
withSeekBarProgress(final int expectedProgress) { return new BoundedMatcher
(SeekBar.class) { @Override public void describeTo(Description description) { description.appendText("expected: "); description.appendText("" + expectedProgress); } @Override public boolean matchesSafely(SeekBar seekBar) { LogUtils.i("seekBar.getProgress():" + seekBar.getProgress()); return seekBar.getProgress()*100/seekBar.getMax() == expectedProgress; } }; }

用法

for (int i = 0; i <= 100; i += 50) {      onView(seekBarViewMatcher).perform(SeekBarActions.scrubSeekBarAction(i));      onView(seekBarViewMatcher).check(matches(withSeekBarProgress(i)));}

 

转载于:https://www.cnblogs.com/guhan121/p/7691634.html

你可能感兴趣的文章
TestNG入门
查看>>
【ul开发攻略】HTML5/CSS3菜单代码 阴影+发光+圆角
查看>>
IO—》Properties类&序列化流与反序列化流
查看>>
Codeforces 719B Anatoly and Cockroaches
查看>>
ActiveMQ与spring整合
查看>>
关于TFS2010使用常见问题
查看>>
poj2752 Seek the Name, Seek the Fame
查看>>
理解oracle中连接和会话
查看>>
[13年迁移]Firefox下margin-top问题
查看>>
Zookeeper常用命令 (转)
查看>>
程序员的数学
查看>>
聚合与组合
查看>>
洛谷 P2089 烤鸡【DFS递归/10重枚举】
查看>>
我眼中的技术地图
查看>>
lc 145. Binary Tree Postorder Traversal
查看>>
android dialog使用自定义布局 设置窗体大小位置
查看>>
ionic2+ 基础
查看>>
[leetcode]Minimum Path Sum
查看>>
Aizu - 1378 Secret of Chocolate Poles (DP)
查看>>
IO流写出到本地 D盘demoIO.txt 文本中
查看>>