Skip to content

Instantly share code, notes, and snippets.

View venkata-kari's full-sized avatar

Venkata Kari venkata-kari

View GitHub Profile
@adavis
adavis / BeforeLoginActivityTest.java
Last active April 7, 2022 13:58
Using Screen Robots with Android Espresso Tests
package <your_package>;
import android.support.test.espresso.intent.rule.IntentsTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;
import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
package com.facebook;
import java.util.ArrayList;
import java.util.Collection;
public class AccessTokenCreator {
public static AccessToken createToken(Collection<String> grantedPermissions) {
return new AccessToken("token", "appId", "userId", grantedPermissions,
new ArrayList<String>(), AccessTokenSource.WEB_VIEW, null, null);
class EspressoTextInputLayoutUtils{
/*
* Use this method to find the EditText within the TextInputLayout. Useful for typing into the TextInputLayout
*/
public static ViewInteraction onEditTextWithinTilWithId(@IdRes int textInputLayoutId) {
//Note, if you have specified an ID for the EditText that you place inside
//the TextInputLayout, use that instead - i.e, onView(withId(R.id.my_edit_text));
return onView(allOf(isDescendantOfA(withId(textInputLayoutId)), isAssignableFrom(EditText.class)));
}
task bvtTest(dependsOn: 'connectedAvodDebugAndroidTest') {
group = 'Verification'
description = 'Runs the tests for debug on connected devices'
android.defaultConfig.testInstrumentationRunnerArguments.package = 'com.package.bvt'
}
// Requried for Continous Integration
// The gradle process will always pass even with test failures
// inspect test results app/build/outputs/androidTest-results/connected/
project.gradle.taskGraph.whenReady {
@danielgomezrico
danielgomezrico / AndroidManifest.xml
Last active March 26, 2023 11:57 — forked from xrigau/AndroidManifest.xml
Android - AndroidJUnitRunner that disable animations, disable screen lock and wake processor all the time to avoid Tests to fail because of test device setup. Note that my test buildType is mock to have a manifest just for tests (dont want to ship an app with SET_ANIMATION_SCALE permissions...).
<?xml version="1.0" encoding="utf-8"?>
<!-- This file should be outside of release manifest (in this case app/src/mock/Manifest.xml -->
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.tests">
<!-- For espresso testing purposes, this is removed in live builds, but not in dev builds -->
<uses-permission android:name="android.permission.SET_ANIMATION_SCALE" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
@vgonda
vgonda / MainActivityTest.java
Created June 11, 2015 13:51
Example of how to use espresso-intents in Android tests
package com.collectiveidea.example;
import android.content.Intent;
import android.support.test.espresso.intent.Intents;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import com.collectiveidea.example.ui.LoginActivity;
import com.collectiveidea.example.ui.MainActivity;
import com.collectiveidea.example.util.AccountUtility;
@patrickhammond
patrickhammond / EspressoTestRule.java
Last active September 2, 2018 12:14
Hacking through Espresso issues...
import android.app.Activity;
import android.app.Instrumentation;
import android.app.KeyguardManager;
import android.app.KeyguardManager.KeyguardLock;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.IBinder;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.support.test.InstrumentationRegistry;
@nbarraille
nbarraille / OrientationChangeAction.java
Last active January 30, 2023 00:04
An Espresso ViewAction that changes the orientation of the screen
/*
* The MIT License (MIT)
*
* Copyright (c) 2015 - Nathan Barraille
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
public void showToastOver(View view, String text) {
Toast toast = Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT);
int xOffset = view.getLeft() - (view.getWidth() / 2);
int yOffset = view.getHeight();
toast.setGravity(Gravity.LEFT | Gravity.BOTTOM, xOffset, yOffset);
Log.d("toast", String.format("Left %d Top %d Bottom %d", view.getLeft(), view.getTop(), view.getBottom()));
toast.show();
}