espresso Seekbar
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的更多相关文章
- 安卓SeekBar
public class Speak extends Fragment implements OnSeekBarChangeListener { private SeekBar bar1; priva ...
- SeekBar进度条简单案例
SeekBar是进度条.我们使用进度条时,可以使用系统默认的进度条:也可以自定义进度条的图片和滑块图片等 向右拉进度条让图片显示出来 向右拉五角星加载有色进度条 baseSeekBar package ...
- 【Android测试】【第十九节】Espresso——API详解
◆版权声明:本文出自胖喵~的博客,转载必须注明出处. 转载请注明出处:http://www.cnblogs.com/by-dream/p/5997557.html 前言 Espresso的提供了不少A ...
- 安卓自动化测试: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 ...
- 通过seekBar改变图片的透明度
作者:堕落的天使 对应的图片 activity_main.xml(代码) <RelativeLayout xmlns:android="http://schemas.android.c ...
- SeekBar 圆角问题
用图片做背景色,最后处理成.9.png的.用普通png图片做背景,则两边会有圆角出现,原因是图片不适合SeekBar尺寸,因而被拉伸或压缩,从而产生圆角. <?xml version=" ...
- Android之SeekBar定制
1.SeekBar样式定制 xml文件中: <SeekBar android:id="@+id/seekbar_voice" ...
- 自定义SeekBar的使用
一.seekbar是进度条,可以使用系统的,也可以自己定义,下面我们将自己定义一个seekbar. 1.自定义滑条,包括对背景,第一进度,第二进度的设置,通过一个xml来实现,在drawable下创建 ...
- listview+seekbar问题的解决
最近做了个项目,其中有录音播放功能.每次录音结束都会在listView中显示,在listView中能播放每次的录音,也可以每条录音之间的切换播放.随之就引发了许多的问题,比如当我播放第一条录音的时所有 ...
随机推荐
- Struts2+DAO层实现实例03——添加监听器跟踪用户行为
实例说明 根据上两次的成品进行二次加工. 加入Listener,监听用户的登陆注销情况. 所用知识说明 采用SessionBindingListener对Session进行监听. 同时,Action中 ...
- android自定义SlideMenu源码详解之最简单侧滑实现
实现原理:在一个Activity的布局中需要有两部分,一个是菜单(menu)的布局,一个是内容(content)的布局.两个布局横向排列,菜单布局在左,内容布局在右.初始化的时候将菜单布局向左偏移,以 ...
- 微信公众号开发java框架:wx4j(入门篇)
导航 入门 http://www.cnblogs.com/2333/p/6617819.html WxServlet介绍 MaterialUtils 素材工具类使用说明 http://www.cnbl ...
- Sth about 函数式编程(Functional Programming)
今天开会提到了函数式编程,针对不同类型的百年城方式,查阅了一部分资料,展示如下: 编程语言一直到近代,从汇编到C到Java,都是站在计算机的角度,考虑CPU的运行模式和运行效率,以求通过设计一个高效的 ...
- [BZOJ3196] 二逼平衡树 [权值线段树套位置平衡树]
题面 洛咕题面 思路 没错我就是要不走寻常路! 看看那些外层位置数据结构,必须二分的,$O(n\log^3 n)$的做法吧! 看看那些cdq分治/树状数组套线段树的,空间$O(n\log^2 n)$挤 ...
- [LeetCode169]Majority Element
Majority Element Total Accepted: 58500 Total Submissions: 163658My Submissions Question Solution Gi ...
- Hibernate中用注解配置一对多双向关联和多对一单向关联
Hibernate中用注解配置一对多双向关联和多对一单向关联 Hibernate提供了Hibernate Annotations扩展包,使用注解完成映射.在Hibernate3.3之前,需单独下载注解 ...
- 培训补坑(day3:网络流&最小割)
继续补坑.. 第三天主要是网络流 首先我们先了解一下网络流的最基本的算法:dinic 这个算法的主要做法就是这样的: 在建好的网络流的图上从源点开始向汇点跑一遍BFS,然后如果一条边的流量不为0,那么 ...
- CString::GetLength()获得字节数
按照MSDN的说吗,在选用MBCS多字节字符串编码时,该方法会得到正确的字节数.此时没有问题. For multibyte character sets (MBCS), GetLength count ...
- 基于UDT connect连接通信以及文件传输--客户端
上面一篇文章中提出了服务端的,其实这里没有严格意义的服务端和客户端之分,因为我在代码中是基于UDP的,不存在服务端与客户端,两个都是对等的,只是我这里进行一下简单的区分而已.在这里,客户端所进行的主要 ...