android / android/testing-samples
Not able to pick an image from gallery using espresso tool
还没有人认领这个 Issue。
- 主要语言
- 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<Intent> 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 content://media/external/images/media))
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)
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 _test_e_testComposeWithAttachments 和 attachment_button 交互开始,然后将预期的 ACTION_PICK matcher 与显示 ACTION_GET_CONTENT 的已记录 intents 进行比较。跟踪从 ComposePageObject.clickComposeButton() 开始的 activity 流程,并确定测试应观察并响应哪个 intent;当预期的交互被记录且 assertion 通过时即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- android, java
- 领域
- mobile-dev, testing
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 需要澄清
- 新手友好度
- 30/100