package test.utils;

 import android.support.test.espresso.PerformException;
import android.support.test.espresso.ViewAction;
import android.support.test.espresso.action.CoordinatesProvider;
import android.support.test.espresso.action.GeneralSwipeAction;
import android.support.test.espresso.action.Press;
import android.support.test.espresso.action.Swipe;
import android.support.test.espresso.util.HumanReadables;
import android.view.View;
import android.widget.SeekBar; import static android.support.test.espresso.action.ViewActions.actionWithAssertions; /**
* Created by qiantao on 17-10-19.
*/ public class SeekBarActions {
public static ViewAction scrubSeekBarAction(int progress) {
return actionWithAssertions(new GeneralSwipeAction(
Swipe.SLOW,
new SeekBarThumbCoordinatesProvider(-1),
new SeekBarThumbCoordinatesProvider(progress),
Press.PINPOINT));
} /**
* -1 表示起始位置
*/
private static class SeekBarThumbCoordinatesProvider implements CoordinatesProvider {
int mProgress; public SeekBarThumbCoordinatesProvider(int progress) {
mProgress = progress;
} private static float[] getVisibleLeftTop(View view) {
final int[] xy = new int[2];
view.getLocationOnScreen(xy);
return new float[]{(float) xy[0], (float) xy[1]};
} @Override
public float[] calculateCoordinates(View view) {
if (!(view instanceof SeekBar)) {
throw new PerformException.Builder()
.withViewDescription(HumanReadables.describe(view))
.withCause(new RuntimeException(String.format("SeekBar expected"))).build();
}
SeekBar seekBar = (SeekBar) view;
int width = seekBar.getWidth() - seekBar.getPaddingLeft() - seekBar.getPaddingRight();
LogUtils.i("seekBar.getProgress():" + seekBar.getProgress());
double progress = mProgress == -1 ? seekBar.getProgress() : (mProgress * seekBar.getMax() / 100);
int xPosition = (int) (seekBar.getPaddingLeft() + (width * progress / seekBar.getMax()));
float[] xy = getVisibleLeftTop(seekBar);
return new float[]{xy[0] + xPosition, xy[1]};
}
}
}

检查Mtacher

    public static Matcher<View> withSeekBarProgress(final int expectedProgress) {
return new BoundedMatcher<View, SeekBar>(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)));
}

espresso Seekbar的更多相关文章

  1. 安卓SeekBar

    public class Speak extends Fragment implements OnSeekBarChangeListener { private SeekBar bar1; priva ...

  2. SeekBar进度条简单案例

    SeekBar是进度条.我们使用进度条时,可以使用系统默认的进度条:也可以自定义进度条的图片和滑块图片等 向右拉进度条让图片显示出来 向右拉五角星加载有色进度条 baseSeekBar package ...

  3. 【Android测试】【第十九节】Espresso——API详解

    ◆版权声明:本文出自胖喵~的博客,转载必须注明出处. 转载请注明出处:http://www.cnblogs.com/by-dream/p/5997557.html 前言 Espresso的提供了不少A ...

  4. 安卓自动化测试:Android studio 自带的 Record Espresso Test || [ Appium & (Android studio || Python|| Eclipse ) ]

    1.Android studio 自带的 Record Espresso Test  https://developer.android.com/studio/test/espresso-test-r ...

  5. 通过seekBar改变图片的透明度

    作者:堕落的天使 对应的图片 activity_main.xml(代码) <RelativeLayout xmlns:android="http://schemas.android.c ...

  6. SeekBar 圆角问题

    用图片做背景色,最后处理成.9.png的.用普通png图片做背景,则两边会有圆角出现,原因是图片不适合SeekBar尺寸,因而被拉伸或压缩,从而产生圆角. <?xml version=" ...

  7. Android之SeekBar定制

    1.SeekBar样式定制 xml文件中:  <SeekBar             android:id="@+id/seekbar_voice"             ...

  8. 自定义SeekBar的使用

    一.seekbar是进度条,可以使用系统的,也可以自己定义,下面我们将自己定义一个seekbar. 1.自定义滑条,包括对背景,第一进度,第二进度的设置,通过一个xml来实现,在drawable下创建 ...

  9. listview+seekbar问题的解决

    最近做了个项目,其中有录音播放功能.每次录音结束都会在listView中显示,在listView中能播放每次的录音,也可以每条录音之间的切换播放.随之就引发了许多的问题,比如当我播放第一条录音的时所有 ...

随机推荐

  1. 【转】Itween 贝塞尔曲线(一)

    原地址:点击打开链接 1.回调函数 回调函数,即当动画完成时那瞬间需要执行一次的一个函数,it中默认有一个onComplete函数,当动画完成时会自动执行,且你可以提供需要传递的一些参数.见如下代码: ...

  2. [转]mysql联合索引

    mysql联合索引   命名规则:表名_字段名1.需要加索引的字段,要在where条件中2.数据量少的字段不需要加索引3.如果where条件中是OR关系,加索引不起作用4.符合最左原则 https:/ ...

  3. vi - vim的一些遗忘点

    1. vi 供分为三种模式:一般模式.编辑模式和命令行模式.i / Esc + :wq :q :q! 使vi在一般模式与编辑模式中来回转换. /word 向下寻找一个名称为word的字符串: ?wor ...

  4. FreeBSD NTP 简单使用

    FreeBSD NTP 简单使用 来源 https://blog.csdn.net/stevexk/article/details/1349506 1.ntptrace xxx.xxx.xxx.xxx ...

  5. phantomjs和selenium模拟登陆qq空间

    # -*- coding: utf-8 -*- from selenium import webdriver import time driver =webdriver.PhantomJS() dri ...

  6. InnoDB的多版本并发控制(MMVC)

    InnoDB的MVCC之(乐观锁),是通过在每行记录保存两个隐藏列来实现的.这两个列,一个是存创建时间,一个是删除时间,这里的时间指的是,系统版本号,并不是真正的时间值. 每开始一个新的事务,系统版本 ...

  7. ie下,jquery为动态添加的节点添加事件,用live

    jQuery向动态生成的内容添加事件响应 jQuery live() 方法详解 [收藏] 发布时间:2013-07-24 点击次数:176 来源:www.daimajiayuan.com jQuery ...

  8. mysql 游标的嵌套使用示例

    BEGIN DECLARE trainee_no_value BIGINT (20); -- 学员编号 DECLARE pay_no_value BIGINT (20); -- 交费序号 DECLAR ...

  9. RelativeSource

    当一个Binding有明确的数据来源时可以通过为Source或ElementName赋值的办法让Binding与之关联,有的时候由于不能确定Source的对象叫什么名字,但知道它与作为Binding目 ...

  10. linux0.11内核源码剖析:第一篇 内存管理、memory.c【转】

    转自:http://www.cnblogs.com/v-July-v/archive/2011/01/06/1983695.html linux0.11内核源码剖析第一篇:memory.c July  ...