Skip to content

Instantly share code, notes, and snippets.

View Egorand's full-sized avatar
🔲
sup sup

Egor Andreevich Egorand

🔲
sup sup
View GitHub Profile
@Egorand
Egorand / MainActivity.java
Created July 17, 2016 11:53
android-testing-runtime-permissions-checking-permissions
@Override
protected void onResume() {
super.onResume();
int permissionStatus = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_CONTACTS);
if (permissionStatus == PackageManager.PERMISSION_GRANTED) {
loadContacts();
} else if (!isPermissionAlreadyDenied) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_CONTACTS},
REQ_CODE_PERMISSIONS_READ_CONTACTS);
@Egorand
Egorand / ContactsSyncTest.java
Created July 17, 2016 11:52
android-testing-runtime-permissions-fix-method-order
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@Egorand
Egorand / ContactsSyncTest.java
Created July 17, 2016 11:51
android-testing-runtime-permissions-should-display-permission-dialog
@Test
public void a_shouldDisplayPermissionRequestDialogAtStartup() throws Exception {
assertViewWithTextIsVisible(device, "ALLOW");
assertViewWithTextIsVisible(device, "DENY");
// cleanup for the next test
denyCurrentPermission(device);
}
@Egorand
Egorand / UiAutomatorUtils.java
Created July 17, 2016 11:49
android-testing-runtime-permissions-deny-current-permission
public static void denyCurrentPermission(UiDevice device) throws UiObjectNotFoundException {
UiObject denyButton = device.findObject(new UiSelector().text(TEXT_DENY));
denyButton.click();
}
@Egorand
Egorand / UiAutomatorUtils.java
Created July 17, 2016 11:48
android-testing-runtime-permissions-assert-text-visible
public static void assertViewWithTextIsVisible(UiDevice device, String text) {
UiObject allowButton = device.findObject(new UiSelector().text(text));
if (!allowButton.exists()) {
throw new AssertionError("View with text <" + text + "> not found!");
}
}
@Egorand
Egorand / AndroidManifest.xml
Created July 17, 2016 11:46
android-testing-runtime-permissions-manifest-override
<?xml version="1.0" encoding="utf-8"?>
<manifest
package="me.egorand.contactssync"
xmlns:tools="http://schemas.android.com/tools">
<uses-sdk tools:overrideLibrary="android.support.test.uiautomator.v18"/>
</manifest>
@Egorand
Egorand / gist:fa8be60dc92d6d31fec86a83f2786584
Created July 17, 2016 11:45
android-testing-runtime-permissions-build-failure
Error:Execution failed for task ':app:processDebugAndroidTestManifest'.
> java.lang.RuntimeException: Manifest merger failed :
uses-sdk:minSdkVersion 16 cannot be smaller than version 18 declared in library
[com.android.support.test.uiautomator:uiautomator-v18:2.1.2]
/<app-path>/app/build/intermediates/exploded-aar/com.android.support.test.uiautomator/uiautomator-v18/2.1.2/AndroidManifest.xml
Suggestion: use tools:overrideLibrary="android.support.test.uiautomator.v18" to force usage
@Egorand
Egorand / build.gradle
Created July 17, 2016 11:43
android-testing-runtime-permissions-uiautomator-setup
dependencies {
// other dependencies
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'
}
@Egorand
Egorand / ContactsSyncTest.java
Created July 17, 2016 11:41
android-testing-runtime-permissions-failing-test
onView(withText("ALLOW")).perform(click());
@Egorand
Egorand / Terminal
Created July 2, 2016 09:51
android-espresso-sorted-list-run-command
./gradlew connectedAndroidTest