android / android/testing-samples
Not able to pick an image from gallery using espresso tool
- Vorherrschende Sprache
- Java
- Sterne
- 9.3k
- Forks
- 3.6k
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
I tried all the methods which are present on the internet but nothing works. Can someone help me with it?
Here is a code:
@Rule
public IntentsTestRule mActivityRule = new IntentsTestRule<>(
HomeScreenActivity.class);
@Before
public void setUp() {
Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
Resources resources = InstrumentationRegistry.getTargetContext().getResources();
Uri fileUri = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + resources
.getResourcePackageName(R.mipmap.ic_launcher) + '/' + resources.getResourceTypeName(
R.mipmap.ic_launcher) + '/' + resources.getResourceEntryName(R.mipmap.ic_launcher));
Intent resultData = new Intent();
resultData.setData(fileUri);
Instrumentation.ActivityResult result = new Instrumentation.ActivityResult(Activity.RESULT_OK, resultData);
}
@Test
public void _test_e_testComposeWithAttachments()
{
ComposePageObject.clickComposeButton();
Matcher expectedIntent = allOf(hasAction(Intent.ACTION_PICK),
hasData(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI));
//Intents.init();
intending(expectedIntent).respondWith(mActivityResult);
onView(withId(R.id.attachment_button)).perform(click());
intended(allOf(expectedIntent));
Intents.release();
Getting this error every time:
junit.framework.AssertionFailedError: Wanted to match 1 intents. Actually matched 0 intents.
IntentMatcher: ((has action: is "android.intent.action.PICK" and has data: is ))
Matched intents:[]
Recorded intents:
-Intent { cmp=com.essential.mail/.ComposeActivity (has extras) } handling packages:[[com.essential.mail]], extras:[Bundle[{compose.account_id=2, compose.action_type=compose}]])
-Intent { act=android.intent.action.GET_CONTENT cat=[android.intent.category.OPENABLE] typ=*/* } handling packages:[[com.android.documentsui, com.android.music, com.android.gallery3d]])
at junit.framework.Assert.fail(Assert.java:50)
Beitragsleitfaden
Rechercherichtung
Beginne mit _test_e_testComposeWithAttachments und der attachment_button-Interaktion. Vergleiche anschließend den erwarteten ACTION_PICK-Matcher mit den aufgezeichneten Intents, die ACTION_GET_CONTENT zeigen. Verfolge den Activity-Ablauf von ComposePageObject.clickComposeButton() aus und bestimme, welches Intent der Test beobachten und auf das er reagieren sollte; fertig ist die Aufgabe, wenn die beabsichtigte Interaktion aufgezeichnet wird und die Assertion erfolgreich ist.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- android, java
- Bereich
- mobile-dev, testing
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 30/100