日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

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

發布時間:2024/9/19 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android程序等待1,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

總結

以上是生活随笔為你收集整理的Android程序等待1,android – Espresso如何等待一段时间(1小时)?的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。