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中能播放每次的录音,也可以每条录音之间的切换播放.随之就引发了许多的问题,比如当我播放第一条录音的时所有 ...
随机推荐
- 安卓context(一)
最近看了一下深入安卓内核,毫无安卓基础的我一头深入不可自拔,看的是云里雾里,第一遍看到一半左右似乎开始失去了效率. 现在开始第二遍,并对看过的重要知识点以个人的理解进行梳理(不免有错的地方,好心人请告 ...
- HTTPS和HTTP的区别:
https协议需要到ca申请证书,一般免费证书很少,需要交费.http是超文本传输协议,信息是明文传输,https 则是具有安全性的ssl加密传输协议http和https使用的是完全不同的连接方式用的 ...
- qemu中是怎么模拟的新的设备
kvm_cpu_exec 和demo中演示的一样
- 【bzoj3781】小B的询问 莫队算法
原文地址:http://www.cnblogs.com/GXZlegend/p/6803821.html 题目描述 小B有一个序列,包含N个1~K之间的整数.他一共有M个询问,每个询问给定一个区间[L ...
- poj 2406 Power Strings (后缀数组 || KMP)
Power Strings Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 28859 Accepted: 12045 D ...
- JavaScript—获取本地时间以12小时制显示
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 自动设置 rem es模块写法
export default function () { let html = document.documentElement; function onWindowResize() { if (ht ...
- 论文笔记《Deep Hand: How to Train a CNN on 1 Million Hand Images When Your Data Is Continuous and Weakly Labelled》
一.概述 这个是最近的核心工作了,基本上都是靠着这篇paper的model过日子了啊.. 论文主要讲的是hand gesture recognition,实际上是用googlenet做的一个class ...
- spring in action 学习笔记五:@Autowired这个注解如何理解
@Autowired这个注解的意思就是自动装配.他把一个bean对象自动装配到另一个对象中.下面的案例证明了spring的自动装配. 定义一个Sixi类.代码如下: package com.qls.a ...
- es6+最佳入门实践(1)
1.let和const 1.1.let和块级作用域 在es5中,js的作用域分为全局作用域和局部作用域,通常是用函数来区分的,函数内部属于局部作用域,在es6中新增了块级作用域的概念,使用{}括起来的 ...