android espresso跨程序,android – Espresso如何等待一段时间(1小时)?

在我的测试用例中,我必须记录1小时,在机器人solo.sleep(600000)完成了我的工作,但在espresso我感到困惑IdlingResource的概念.我必须开始录音并等待一段时间(取决于测试的类型)15分钟,60分钟等

机器人中的等效代码

solo.clickOnView(solo.getView("start_record"));

solo.sleep(duration * 60 * 1000);

solo.clickOnView(solo.getView("stop_record"));

我尝试在espresso中使用它

@RunWith(AndroidJUnit4.class)

@SmallTest

public class AaEspressoTest {

private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME = "com.absd.rec.RecorderActivity";

private static Class> launcherActivityClass;

private Solo solo;

private static CoreRecordingTest skyroTestRunner;

private static Class extends Activity> activityClass;

static {

try {

activityClass = (Class extends Activity>) Class.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);

} catch (ClassNotFoundException e) {

throw new RuntimeException(e);

}

}

@Rule

public final ActivityTestRule> activityRule

= new ActivityTestRule<>(activityClass);

private IntentServiceIdlingResource idlingResource;

@Before

public void registerIntentServiceIdlingResource() {

Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();

idlingResource = new IntentServiceIdlingResource(instrumentation.getTargetContext());

Espresso.registerIdlingResources(idlingResource);

}

@After

public void unregisterIntentServiceIdlingResource() {

Espresso.unregisterIdlingResources(idlingResource);

}

@Test

public void testHello() throws Exception {

onView(withId(AaEspressoTest.getId("recorderpage_record"))).perform(click());

registerIntentServiceIdlingResource();

onView(withId(AaEspressoTest.getId("recorderpage_stop"))).perform(click());

}

}

空闲资源

public class IntentServiceIdlingResource implements IdlingResource {

private final Context context;

private ResourceCallback resourceCallback;

public static boolean status = false;

public IntentServiceIdlingResource(Context context) {

this.context = context;

}

@Override

public String getName() {

return IntentServiceIdlingResource.class.getName();

}

@Override

public boolean isIdleNow() {

return getTimer();

}

@Override

public void registerIdleTransitionCallback(ResourceCallback resourceCallback) {

this.resourceCallback = resourceCallback;

}

private static boolean getTimer() {

new CountDownTimer(5000, 1000) {

@Override

public void onTick(long millisUntilFinished) {

// Do Nothing

status = false;

}

@Override

public void onFinish() {

status = true;

}

};

return status;

}

}

例外:

android.support.test.espresso.IdlingResourceTimeoutException: Wait for [com.adbs.recorder.IntentServiceIdlingResource] to become idle timed out

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值