android / android/testing-samples

Not able to pick an image from gallery using espresso tool

オープン
#285 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Java
スター
9.3k
フォーク
3.6k
PR マージ指標
30日以内にマージされた PR はありません

説明

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)

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

_test_e_testComposeWithAttachments と attachment_button のインタラクションから始め、期待される ACTION_PICK matcher と ACTION_GET_CONTENT を示す記録済みの intents を比較します。ComposePageObject.clickComposeButton() からアクティビティのフローを追跡し、テストがどの intent を観測して応答すべきかを判断します。意図したインタラクションが記録され、assertion が成功すれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
android, java
領域
mobile-dev, testing
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
30/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。