I have this simple Espresso interaction:
onView(atIndex(withId(R.id.editTextTextWidget), 0)).inRoot(authViewRootMatcher)
.check(matches(allOf(isDisplayed(), isEnabled())))
.perform(typeText("1"));
The check(matches(allOf(isDisplayed(), isEnabled()))) passes as expected, but the following perform(typeText("1")) does not. I cannot figure out why, for the life of me.
So, I can't believe I'm asking this, but how in the name of Android do I use Espresso to type text into my EditText whose ID is R.id.editTextTextWidget?
I fixed the problem by splitting the check(...) call and perform(...) call:
onView(atIndex(withId(R.id.editTextTextWidget), 0)).inRoot(authViewRootMatcher)
.check(matches(allOf(isDisplayed(), isEnabled())));
onView(atIndex(withId(R.id.editTextTextWidget), 0)).inRoot(authViewRootMatcher)
.perform(typeText("1"));
For some reason this works, and the original doesn't. #GooglePlz
Related
I'm repairing my friend's code and got confused.
My friend wants to fetch entered text (in EditText). Seems easy, right? Well, it is but instead of user input, he gets this warning/error:
To be honest I'm not sure how to fix it. He is coding in Kotlin (Android 10).
Activity that contains EditText:
And XML:
This is how it looks when debugging:
The app started working just fine after running "File -> invalidate Cashes/Restart" option, I just don't understand where this warning came from and how to fix it because the error remained unchanged (even though the app works). Do you have an idea how to solve it?
All the best!
fyi lambda expression like setOnClickListener from kotlin is not debuggable, see here.
if you want to debug variables inside setOnClickListener you should use the normal one e.g. setOnClickListener(object: View.OnClickListener {..})
sometimes there will be problem in auto generated binding files, if so it will be solved after invalidate cache and restart ide. sometimes the warning/error show but the project and complied without errors. so no need to worry about that. for next time post the code as code not screen shots.
I understand that the question is regarding evaluating expression, but there is a way you can read variables from your debugger console, even if you're inside an anonymous callback. I found it helpful sometimes. Here are the steps:
First enter debugger mode inside of your anonymous callback,
In your debugger console, look at the right side for "Frames"
Within Frames under , you'll see stack of function execution first top one on the list is the latest:
Click on row(s) below the latest function, until you find an instance of your activity AddInformationActivity. You will see the activity instance on the right side window under Variables. Don't go as far as selecting functions browned out, because those are from internal libraries.
When you see you AddInformationActivity instance, you can expand it and see its variables.
Hope that helps!
It's not a beautiful way, but if you create a method like this:
private fun debug() {
println()
}
and add a breakpoint on the println() it'll capture the activity.
(Don't use TODO as it'll crash the app with a NotImplementedError once called.)
I have this method now in my code all the time to call it whenever I need it.
I know, that question is old, but I just stumbled over it and needed a way.
I'm using Espresso in my Instrumented Tests and Firebase to run them, and it is working just fine. But i think Firebase is screenshoting to early. With Spoon, this exactly behavior also happens.
ScreenShotter.takeScreenshot("main_screen_1", activityRule.activity)
isTextEqualsTo(R.id.toolbarTitle, R.string.add_book)
typeTextOnAEmptyEditText(R.id.titleInputText, title)
typeTextOnAEmptyEditText(R.id.descriptionInputText, description)
ScreenShotter.takeScreenshot("main_screen_2", activityRule.activity)
For above sample, i'm getting this as result:
Looking carefully, you can check that description label is going up, during material ui animation, meaning that Espresso has started clicking/typing.
I simply don't know what is going on here.
EDIT: I think it is a bug. It is impossible do capture screen before and after text typing, and only in text typing (ViewActions.typeText). I don't know yet if it is a bug in TextInputLayout (Material UI) or in the screen capture function.
Ok, just found the reason.
It is a bug in InputTextLayout/TextInputEditText, don't know why or how. Just added a new simple EditText and then worked.
Issue oponed.
Lesson learned: If you want to audit a app flow during a ui test, don't use nothing from Material UI.
I'm taking over care and feeding of an existing React-native app. There's a part of the app that takes a picture, which results in the message "Transform with key of "perspective" cannot be zero: {"perspective":0}". (This happens in the Android emulator.)
In the existing code, there's no place that designates a perspective. I'm curious what might be implicitly expecting this.
I figured out what was happening. The code was rendering a FlipCard (#see react-native-flip-card) FlipCard takes an attribute "perspective," whose default is zero. Setting it to something other than zero saved the day: ...<FlipCard perspective={0.5}...>
Hope this helps someone.
I'm currently trying to get Espresso to match a UIElement by it's class and its text since it currently does not have a resource ID (I know, I know...). I'm not sure what the proper syntax for this is since the Espresso documentation is fuzzy (I'm VERY new to this and programming in general so I'm sure I'm missing something). Here's what I have so far:
onView(allOf(instanceOf(android.widget.CheckBox)), withText("S"))).
perform(scrollTo()).
check(matches(isChecked()));
I've tried typing just "Textbox" but in both cases I get an "Expression Expected" error. As of now this is the only way to identify this element so any pointers will help. Thanks!
Here' s my example:
onView(allOf(instanceOf(Toolbar.class), withChild(withText(R.string.action_settings))))
.check(matches(isDisplayed()));
so I guess that in your test would be
onView(allOf(instanceOf(android.widget.CheckBox.class)), withText("S"))).
perform(scrollTo()).
check(matches(isChecked()));
Hope it will help
I have a viewpager and I want to check for an imageview in it. I have used following code but its not working.
onView(allOf(withId(R.id.img_flag), hasSibling(withText("some
text"))));
this one always returns true
onView(withId(R.id.img_flag)).check(doesNotExist());
this one throws AmbiguousViewMatcherException
I don't know what you're going to check, but to resume:
The first one is always true, because img_flag would be certainly always (I mean: until you put it in another ViewGroup) a sibling to a TextView with some text. It's like mathematical 2+2=4.
So this test only checked if img_flag has sibling with "some text".
AmbiguousViewMatcherException means only that there are more than one view with img_flag id. Espresso don't know which of them shoul not exist so it informs about it.
If you wanna fix the second one please read about onData() Espresso matcher.
Visit also these sites:
https://guides.codepath.com/android/UI-Testing-with-Espresso
https://google.github.io/android-testing-support-library/docs/espresso/index.html
On the second one you would find Espresso Cheat Sheet, where struct of onData() matcher is enough explained
If you have more quesrtions, please feel free to ask.