-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NullPointerException at PopupWindow.getDecorViewLayoutParams #5345
Comments
Got the very same stacktrace today after I updated Google's Material Components library from
|
Problem seems to be a re-entrant call to
Now because the said flag is already switched, the code in |
Tracked this down, the issue appeared with Material Components 1.2.0-alpha03, because this is the first version where my test fails. It is green with Material Components 1.2.0-alpha02. Will futher investigate. |
My issue seems to be rooted in MDC, opened a bug there material-components/material-components-android#1027 |
Ok, my workaround is to not touch / click the fun showDropDown(): ViewAction =
object : ViewAction {
override fun getDescription(): String = "Shows the dropdown menu of an AutoCompleteTextView"
override fun getConstraints(): Matcher<View> = allOf(
isEnabled(), isAssignableFrom(AutoCompleteTextView::class.java)
)
override fun perform(uiController: UiController, view: View) {
val autoCompleteTextView = view as AutoCompleteTextView
autoCompleteTextView.showDropDown()
uiController.loopMainThreadUntilIdle()
}
} |
Hi, I'm having a very similar issue, I'm unable to use typeText() or click() on EditText throght espresso. here is my code: @Test
public void on_date_click_the_date_picker_should_be_displayed() {
FragmentScenario<ReportProblemFragment> scenario = FragmentScenario.launchInContainer(
ReportProblemFragment.class, null, fragmentFactory);
Espresso
.onView(withId( R.id.et_problem ))
.perform(typeText("Hi"));
} This produces:
My Dependencies
|
Thank you @realdadfish for your solution. Finally got passed my espresso testing of my |
+1, Full code: https://gist.github.com/joshallenit/04be926a7a31957817426d8d98d4af28 @Test
fun editText_whenClickedOnWithText_shouldNotCrash() {
val scenario = launchFragmentInContainer<TestFragment>()
scenario.onFragment {
val underTest = it.view!!
onView(withClassName(Matchers.equalTo(underTest::class.qualifiedName)))
.perform(typeText("Hello "))
.perform(typeText("c")) // CRASH
}
}
class TestFragment : Fragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return EditText(requireContext())
}
} Somehow the outer
|
Here is a Shadow that works around it: @Implements(className="android.widget.Editor\$InsertionHandleView")
class ShadowInsertionHandleView: ShadowView() { {
@RealObject
private lateinit var realInsertionHandleView: Object
@Suppress("unused", "ProtectedInFinal") // Used by Robolectric and protected recommended to limit api surface.
@Implementation
protected fun getCurrentCursorOffset(): Int {
return try {
Shadow.directlyOn(
realInsertionHandleView,
"android.widget.Editor\$InsertionHandleView",
"getCurrentCursorOffset"
)
} catch (ex: Exception) {
0
}
}
} |
Description
Running
EditText
setError()
together withrequestFocus()
inonClick()
handler causes NPE ingetDecorViewLayoutParams()
. It seems thatdecorView
is null.Interesting that running with
@LooperMode(PAUSED)
fixes the issue.Steps to Reproduce
Robolectric & Android Version
Robolectric 4.3
Android SDK 29
The text was updated successfully, but these errors were encountered: