本文整理汇总了Java中android.support.test.rule.ActivityTestRule类的典型用法代码示例。如果您正苦于以下问题:Java ActivityTestRule类的具体用法?Java ActivityTestRule怎么用?Java ActivityTestRule使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ActivityTestRule类属于android.support.test.rule包,在下文中一共展示了ActivityTestRule类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createRule
import android.support.test.rule.ActivityTestRule; //导入依赖的package包/类
ActivityTestRule<FruitActivity> createRule(){
return new ActivityTestRule<FruitActivity>(FruitActivity.class) {
@Override
protected void beforeActivityLaunched() {
new SystemLogger().i("FruitViewRotationTestStateBuilder", "beforeActivityLaunched()");
CustomApp customApp = (CustomApp) InstrumentationRegistry.getTargetContext().getApplicationContext();
customApp.injectSynchronousObjectGraph();
//inject our test model
customApp.injectMockObject(FruitFetcher.class, fruitViewRotationTest.fruitFetcher);
customApp.registerActivityLifecycleCallbacks(new ProgressBarIdler());
}
@Override
protected void afterActivityFinished() {
super.afterActivityFinished();
this.getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
};
}
示例2: testReposActivityFragments
import android.support.test.rule.ActivityTestRule; //导入依赖的package包/类
@Test
public void testReposActivityFragments() {
ActivityTestRule rule = new ActivityTestRule<>(ReposActivity.class, true, false);
shelfTestUtils.setupBook("book-one", "Preface\n\n* Note");
shelfTestUtils.setupRepo("file:/");
shelfTestUtils.setupRepo("dropbox:/orgzly");
rule.launchActivity(null);
// List of repos
fragmentTest(rule, false, withId(R.id.fragment_repos_flipper));
// Directory repo
onListItem(1).perform(click());
fragmentTest(rule, false, withId(R.id.fragment_repo_directory_container));
pressBack();
// Dropbox repo
onListItem(0).perform(click());
fragmentTest(rule, false, withId(R.id.fragment_repo_dropbox_container));
}
示例3: fragmentTest
import android.support.test.rule.ActivityTestRule; //导入依赖的package包/类
private void fragmentTest(ActivityTestRule rule, boolean hasSearchMenuItem, Matcher<View> matcher) {
onView(matcher).check(matches(isDisplayed()));
toPortrait(rule);
onView(matcher).check(matches(isDisplayed()));
toLandscape(rule);
onView(matcher).check(matches(isDisplayed()));
toPortrait(rule);
onView(matcher).check(matches(isDisplayed()));
toLandscape(rule);
onView(matcher).check(matches(isDisplayed()));
toPortrait(rule);
if (hasSearchMenuItem) {
onView(withId(R.id.activity_action_search)).check(matches(isDisplayed()));
} else {
onView(withId(R.id.activity_action_search)).check(doesNotExist());
}
}
示例4: createRule
import android.support.test.rule.ActivityTestRule; //导入依赖的package包/类
ActivityTestRule<CounterActivity> createRule(){
return new ActivityTestRule<CounterActivity>(CounterActivity.class) {
@Override
protected void beforeActivityLaunched() {
//get hold of the application
CustomApp customApp = (CustomApp) InstrumentationRegistry.getTargetContext().getApplicationContext();
customApp.injectSynchronousObjectGraph();
//inject our mocks so our UI layer will pick them up
customApp.injectMockObject(CounterWithLambdas.class, mockCounterWithLambdas);
customApp.injectMockObject(CounterWithProgress.class, mockCounterWithProgress);
}
};
}
示例5: createRule
import android.support.test.rule.ActivityTestRule; //导入依赖的package包/类
ActivityTestRule<FruitActivity> createRule(){
return new ActivityTestRule<FruitActivity>(FruitActivity.class) {
@Override
protected void beforeActivityLaunched() {
//get hold of the application
CustomApp customApp = (CustomApp) InstrumentationRegistry.getTargetContext().getApplicationContext();
customApp.injectSynchronousObjectGraph();
//inject our mocks so our UI layer will pick them up
customApp.injectMockObject(FruitFetcher.class, mockFruitFetcher);
customApp.registerActivityLifecycleCallbacks(new ProgressBarIdler());
}
};
}
示例6: createRule
import android.support.test.rule.ActivityTestRule; //导入依赖的package包/类
ActivityTestRule<WalletsActivity> createRule(){
return new ActivityTestRule<WalletsActivity>(WalletsActivity.class) {
@Override
protected void beforeActivityLaunched() {
//get hold of the application
CustomApp customApp = (CustomApp) InstrumentationRegistry.getTargetContext().getApplicationContext();
customApp.injectSynchronousObjectGraph();
//inject our mocks so our UI layer will pick them up
customApp.injectMockObject(Wallet.class, mockWallet);
}
};
}
示例7: createRule
import android.support.test.rule.ActivityTestRule; //导入依赖的package包/类
ActivityTestRule<PlaylistsActivity> createRule(){
return new ActivityTestRule<PlaylistsActivity>(PlaylistsActivity.class) {
@Override
protected void beforeActivityLaunched() {
//get hold of the application
CustomApp customApp = (CustomApp) InstrumentationRegistry.getTargetContext().getApplicationContext();
customApp.injectSynchronousObjectGraph();
//inject our mocks so our UI layer will pick them up
customApp.injectMockObject(PlaylistAdvancedModel.class, mockPlaylistAdvancedModel);
customApp.injectMockObject(PlaylistSimpleModel.class, mockPlaylistSimpleModel);
}
};
}
示例8: testRegisterUserPasswordInvalid
import android.support.test.rule.ActivityTestRule; //导入依赖的package包/类
@Test
public void testRegisterUserPasswordInvalid(){
new ActivityTestRule<>(RegisterScreenActivity.class);
onView(withId(R.id.nicknameEditText))
.perform(typeText("testuser"));
onView(withId(R.id.passwordEditText))
.perform(typeText("!*"));
onView(withId(R.id.passwordConfirmEditText))
.perform(typeText("senha1234"))
.perform(closeSoftKeyboard());
onView(withId(R.id.emailEditText))
.perform(typeText("[email protected]"))
.perform(closeSoftKeyboard());
onView(withId(R.id.registerButton))
.perform(click());
onView(withId(R.id.passwordEditText)).check(matches(hasErrorText(activity.getString(R.string.passwordValidation))));
}
示例9: testRegisterUserConfirmPasswordInvalid
import android.support.test.rule.ActivityTestRule; //导入依赖的package包/类
@Test
public void testRegisterUserConfirmPasswordInvalid(){
new ActivityTestRule<>(RegisterScreenActivity.class);
onView(withId(R.id.nicknameEditText))
.perform(typeText("testuser"));
onView(withId(R.id.passwordEditText))
.perform(typeText("senha1234"));
onView(withId(R.id.passwordConfirmEditText))
.perform(typeText("!*"))
.perform(closeSoftKeyboard());
onView(withId(R.id.emailEditText))
.perform(typeText("[email protected]"))
.perform(closeSoftKeyboard());
onView(withId(R.id.registerButton))
.perform(click());
onView(withId(R.id.passwordConfirmEditText)).check(matches(hasErrorText(activity.getString(R.string.passwordConfirmValidation))));
}
示例10: testRegisterUserEmailInvalid
import android.support.test.rule.ActivityTestRule; //导入依赖的package包/类
@Test
public void testRegisterUserEmailInvalid(){
new ActivityTestRule<>(RegisterScreenActivity.class);
onView(withId(R.id.nicknameEditText))
.perform(typeText("testuser"));
onView(withId(R.id.passwordEditText))
.perform(typeText("senha1234"));
onView(withId(R.id.passwordConfirmEditText))
.perform(typeText("senha1234"))
.perform(closeSoftKeyboard());
onView(withId(R.id.emailEditText))
.perform(typeText("[email protected]"))
.perform(closeSoftKeyboard());
onView(withId(R.id.registerButton))
.perform(click());
onView(withId(R.id.emailEditText)).check(matches(hasErrorText(activity.getString(R.string.invalidEmail))));
}
示例11: recreateActivity
import android.support.test.rule.ActivityTestRule; //导入依赖的package包/类
/**
* Restarts the RecreatedAppCompatActivity and waits for the new activity to be resumed.
*
* @return The newly-restarted RecreatedAppCompatActivity
*/
@SuppressWarnings("unchecked") // The type of the recreated activity is guaranteed to be T
public static <T extends RecreatableAppCompatActivity> T recreateActivity(
ActivityTestRule<? extends RecreatableAppCompatActivity> rule, final T activity)
throws InterruptedException {
// Now switch the orientation
RecreatableAppCompatActivity.resumedLatch = new CountDownLatch(1);
RecreatableAppCompatActivity.destroyedLatch = new CountDownLatch(1);
runOnUiThreadRethrow(
rule,
new Runnable() {
@Override
public void run() {
activity.recreate();
}
});
assertTrue(RecreatableAppCompatActivity.resumedLatch.await(1, TimeUnit.SECONDS));
assertTrue(RecreatableAppCompatActivity.destroyedLatch.await(1, TimeUnit.SECONDS));
T newActivity = (T) RecreatableAppCompatActivity.activity;
waitForExecution(rule);
RecreatableAppCompatActivity.clearState();
return newActivity;
}
示例12: getCurrentActivity
import android.support.test.rule.ActivityTestRule; //导入依赖的package包/类
/**
* Gets an instance of the currently active (displayed) activity.
* @param activityTestRule test rule
* @param <T> activity class
* @return activity instance
*/
public static <T extends Activity> T getCurrentActivity(@NonNull ActivityTestRule activityTestRule) {
getInstrumentation().waitForIdleSync();
final Activity[] activity = new Activity[1];
try {
activityTestRule.runOnUiThread(new Runnable() {
@Override
public void run() {
java.util.Collection<Activity> activites = ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(Stage.RESUMED);
activity[0] = Iterables.getOnlyElement(activites);
}});
} catch (Throwable throwable) {
throwable.printStackTrace();
}
//noinspection unchecked
return (T) activity[0];
}
示例13: Disconnect
import android.support.test.rule.ActivityTestRule; //导入依赖的package包/类
public static void Disconnect(ActivityTestRule<SnippetListActivity> snippetListActivityTestRule) {
SnippetListActivity snippetListActivity = snippetListActivityTestRule.launchActivity(null);
openActionBarOverflowOrOptionsMenu(InstrumentationRegistry.getTargetContext());
// Espresso can't find menu items by id. We'll use the text property.
onView(withText(R.string.disconnect_menu_item))
.perform(click());
intended(allOf(
hasComponent(hasShortClassName(".SignInActivity")),
toPackage("com.microsoft.graph.snippets")
));
snippetListActivity.finish();
}
示例14: getSnippetsIndexes
import android.support.test.rule.ActivityTestRule; //导入依赖的package包/类
public static List<Integer> getSnippetsIndexes(ActivityTestRule<SnippetListActivity> snippetListActivityRule) {
SnippetListActivity snippetListActivity = snippetListActivityRule.launchActivity(null);
ListAdapter listAdapter = getListAdapter(snippetListActivity);
int numItems = listAdapter.getCount();
List<Integer> snippetIndexes = new ArrayList<>();
// Get the index of items in the adapter that
// are actual snippets and not categories, which don't have a Url
for (int i = 0; i < numItems; i++) {
if(((AbstractSnippet)listAdapter.getItem(i)).getUrl() != null) {
snippetIndexes.add(i);
}
}
snippetListActivity.finish();
return snippetIndexes;
}
示例15: rotateOrientation
import android.support.test.rule.ActivityTestRule; //导入依赖的package包/类
public static void rotateOrientation(ActivityTestRule<? extends Activity> testRule) {
switch (testRule.getActivity().getResources().getConfiguration().orientation) {
case Configuration.ORIENTATION_LANDSCAPE:
testRule.getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
break;
default:
testRule.getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
}