Fixed
Status Update
Comments
il...@google.com <il...@google.com>
jd...@gmail.com <jd...@gmail.com> #2
Hi,
Are there any workarounds to address this need? Thank you!
Are there any workarounds to address this need? Thank you!
hu...@google.com <hu...@google.com> #3
Hi Jorge,
Thanks for reporting the issue. Yes, the problem is EmptyActivity (which is used by FragmentScenario internally) extends FragmentActivity and FragmentActivity doesn't have ActionBar.
I'm going to update EmptyActivity to extend AppCompatActivity instead. As for the workaround solution, could you create EmptyActivity extending AppCompatActivity in your APK and use ActivityScenario, then run your Fragment in it?
Thanks for reporting the issue. Yes, the problem is EmptyActivity (which is used by FragmentScenario internally) extends FragmentActivity and FragmentActivity doesn't have ActionBar.
I'm going to update EmptyActivity to extend AppCompatActivity instead. As for the workaround solution, could you create EmptyActivity extending AppCompatActivity in your APK and use ActivityScenario, then run your Fragment in it?
ap...@google.com <ap...@google.com> #5
Project: platform/frameworks/support
Branch: androidx-master-dev
commit 97820f9e3b80de2ba10ad3dd520d8f146f0e394c
Author: Yuki Hamada <hummer@google.com>
Date: Thu Jan 24 13:33:55 2019
Use android:Theme.WithActionBar for EmptyFragmentActivity.
Before this CL, FragmentScenarioEmptyFragmentActivityTheme inherits android:Theme which doesn't have ActionBar so options menu which testing Fragment adds cannot be tested. This CL changes the parent theme to android:Theme.WithActionBar to support options menu.
Change-Id: I35e80d3b302ea600e5e76f6f0640934b806259e5
Test: :fragment-testing:connectedAndroidTest
Fixes: 121126668
M fragment/testing/build.gradle
M fragment/testing/src/androidTest/java/androidx/fragment/app/testing/FragmentScenarioTest.kt
A fragment/testing/src/androidTest/java/androidx/fragment/app/testing/OptionsMenuFragment.kt
A fragment/testing/src/androidTest/res/menu/example_menu.xml
M fragment/testing/src/main/res/values/styles.xml
https://android-review.googlesource.com/885195
https://goto.google.com/android-sha1/97820f9e3b80de2ba10ad3dd520d8f146f0e394c
Branch: androidx-master-dev
commit 97820f9e3b80de2ba10ad3dd520d8f146f0e394c
Author: Yuki Hamada <hummer@google.com>
Date: Thu Jan 24 13:33:55 2019
Use android:Theme.WithActionBar for EmptyFragmentActivity.
Before this CL, FragmentScenarioEmptyFragmentActivityTheme inherits android:Theme which doesn't have ActionBar so options menu which testing Fragment adds cannot be tested. This CL changes the parent theme to android:Theme.WithActionBar to support options menu.
Change-Id: I35e80d3b302ea600e5e76f6f0640934b806259e5
Test: :fragment-testing:connectedAndroidTest
Fixes: 121126668
M fragment/testing/build.gradle
M fragment/testing/src/androidTest/java/androidx/fragment/app/testing/FragmentScenarioTest.kt
A fragment/testing/src/androidTest/java/androidx/fragment/app/testing/OptionsMenuFragment.kt
A fragment/testing/src/androidTest/res/menu/example_menu.xml
M fragment/testing/src/main/res/values/styles.xml
jd...@gmail.com <jd...@gmail.com> #6
Hi all,
Sorry for my very late reply, but I was traveling and very busy.
I have just run the test again, and it still doesn't work.
As far as I understand, with the change that was introduced, I only had to update the dependencies and rerun the test as it was. Please correct me if I am wrong. These are my (relevant) dependencies:
- androidx.fragment and fragment-testing: 1.1.0-alpha05
- androidx.test.runner: 1.1.1
- androidx.test.core: 1.1.0
- androidx.test.ext.junit: 1.1.0
- org.robolectric: 4.2.1
Am I missing anything here? Thank you!
Best regards,
Jorge
Sorry for my very late reply, but I was traveling and very busy.
I have just run the test again, and it still doesn't work.
As far as I understand, with the change that was introduced, I only had to update the dependencies and rerun the test as it was. Please correct me if I am wrong. These are my (relevant) dependencies:
- androidx.fragment and fragment-testing: 1.1.0-alpha05
- androidx.test.runner: 1.1.1
- androidx.test.core: 1.1.0
- androidx.test.ext.junit: 1.1.0
- org.robolectric: 4.2.1
Am I missing anything here? Thank you!
Best regards,
Jorge
jd...@gmail.com <jd...@gmail.com> #7
Hi again,
The generated error is: "androidx.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with id: com.canonicalexamples.realprogrammers:id/menu_item_save".
Running the application displays that button. However, the (partial) hierarchy shown in the log is:
"+---->ActionMenuView{id=-1, visibility=VISIBLE, width=56, height=48, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, layout-params=android.view.ViewGroup$LayoutParams@340d8ce3, tag=null, root-is-layout-requested=false, has-input-connection=false, x=264.0, y=0.0, child-count=1}
|
+----->OverflowMenuButton{id=-1, desc=More options, visibility=VISIBLE, width=56, height=48, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, layout-params=android.widget.ActionMenuView$LayoutParams@1c10a9c8, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0}
|
+--->ActionBarContextView{id=16908677, res-name=action_context_bar, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, layout-params=android.widget.FrameLayout$LayoutParams@c883991, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=0}
|
+-->ActionBarContainer{id=16909335, res-name=split_action_bar, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, layout-params=com.android.internal.widget.ActionBarOverlayLayout$LayoutParams@820620, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=0} "
Best regards,
Jorge
The generated error is: "androidx.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with id: com.canonicalexamples.realprogrammers:id/menu_item_save".
Running the application displays that button. However, the (partial) hierarchy shown in the log is:
"+---->ActionMenuView{id=-1, visibility=VISIBLE, width=56, height=48, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, layout-params=android.view.ViewGroup$LayoutParams@340d8ce3, tag=null, root-is-layout-requested=false, has-input-connection=false, x=264.0, y=0.0, child-count=1}
|
+----->OverflowMenuButton{id=-1, desc=More options, visibility=VISIBLE, width=56, height=48, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, layout-params=android.widget.ActionMenuView$LayoutParams@1c10a9c8, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0}
|
+--->ActionBarContextView{id=16908677, res-name=action_context_bar, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, layout-params=android.widget.FrameLayout$LayoutParams@c883991, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=0}
|
+-->ActionBarContainer{id=16909335, res-name=split_action_bar, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, layout-params=com.android.internal.widget.ActionBarOverlayLayout$LayoutParams@820620, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=0} "
Best regards,
Jorge
Description
Version used: 1.1.0-alpha02
Devices/Android versions reproduced on: emulator
I am trying to test that a menu option is enabled or disabled when needed using Robolectric 4.0.2. The test will be something like:
@Test
fun enableSaveButton() {
sut.onFragment {
// TODO: trigger onCreateOptionsMenu(menu: Menu, inflater: MenuInflater)
openActionBarOverflowOrOptionsMenu(ApplicationProvider.getApplicationContext())
it.enableSaveButton(false)
}
onView(withId(R.id.menu_item_save)).check(matches(not(isEnabled())))
}
The fragment is launched and reaches the resumed state, but in the lamda that "onFragment" executes, onCreateMenuOptions() has NOT been executed yet becaues that is how the fragment lifecycle works (
I have also tried using Espresso's "openActionBarOverflowOrOptionsMenu(ApplicationProvider.getApplicationContext())" unsuccessfully.