Comments (32)
Sure, I'll take a look as soon as I have free time
from kakao.
Hey there! Thanks a lot for your interest in our project.
Regarding your question: it can be done via KView
and KListView
. We have inRoot()
function located at BaseAssertions
.
And we have RootBuilder
class which helps you to perform this kind of checks.
Take a look at the example:
fun test() {
screen { list {
inRoot { isPlatformPopup() }
childAt(0) { hasText("TEST") }
} }
}
fun testToast() {
screen { toast {
inRoot { withMatcher(ToastMatcher()) }
hasText("TOAST")
} }
}
from kakao.
Are you sure we're able to get list in popup?
What kind of matcher should i pass in Screen? (id is not set, withClassName doesnt work, withAnyText matches multiple views)
from kakao.
You can try using isInstanceOf
matcher for your list. And are you sure that list doesn't have an id?
from kakao.
Also you can match the list by matching it's items with use of withDescendant
from kakao.
Well, yes. We're using ListPopupWindow which doesnt have an id on list (contains DropDownListView). So the idea is to find a popup first (the real diff is inAdapterView(matcher)
changed to inRoot(RootMatchers.isPlatformPopup())
).
Toast is similiar story. That's why I've changed view to:
override val view = this.builder.getViewInteraction().inRoot(ToastMatcher())
from kakao.
For toast, as I said previously, you can declare a view with text matcher, for example, and then immediately apply root matcher:
val toast = KView {
withText("TOAST")
} perform {
inRoot { withMatcher(ToastMatcher()) }
}
This will return you the KView with view interaction inside, which already has root matcher.
Regarding ListView situation, I think we should ask someone else. @cdsap @VerachadW what do you guys think on this?
from kakao.
@Chesteer89 You may try to send the matcher for list
with the parent matcher. The popup needs to anchor with the view or the screen window. So, I think we can create a matcher for the parent view and pass it to withParent()
for list
. This is my idea.
from kakao.
Thanks guys! Optional parameter or withParent()
sounds good.
I'll migrate to new version after update :)
Did you think about Snackbar tests? Is it possible right now or should i write my custom view + actions?
from kakao.
No, right now we don't have prebuilt view classes for that, but this is good idea, to make KSnackBar
and KToast
. Is this issue resolved?
from kakao.
I'm currently trying to achieve the same thing here with an AutoCompleteTextView
suggestion matcher (PopupWindow
/DropDownListView
), did you manage to find a resolve using withParent()
?
from kakao.
Hi there!
The thing is, right now this behavior is not achievable due to specifics of these classes. PopupWindow
and Toast
actually create new Window
instance when they show up. And espresso is explicitly bound to your activity's window with ViewRootImpl
inside. It cannot access other windows through instrumentation.
from kakao.
We added KSnackBar
support though.
from kakao.
My understanding is that you could use:
onData(equalTo("ITEM"))
.inRoot(RootMatchers.isPlatformPopup())
.perform(click())
for an autocomplete item?
I'm just not quite sure how to integrate that with a KListView
, or if at all it's possible to do so at the moment.
from kakao.
As I recall, we have root matching.
So you can match your KListView
by any means comfortable to you (by id, by class name, by searching through parent class name, etc.) and then apply root matcher during your actions/assertions:
screen {
list {
inRoot { isPlatformPopup() }
// Do your stuff here
}
}
from kakao.
Yep, but the difficulty is creating list
in our Screen<T>
class, the suggestion was to use withParent
and isRoot
, but I've not had much success, what might be a way of selecting it?
from kakao.
val list = KListView(...) {
isInstanceOf(ListView::class.java)
}
...
screen {
list {
inRoot { isPlatformPopup() }
// Do your stuff here
}
}
from kakao.
That's what I've tried, but I'm getting a NoMatchingViewException
😞
from kakao.
Can you provide the dumps of layouts when you open your popup and the results of adb shell dumpsys window windows
and adb shell dumpsys activity
?
from kakao.
Also, what exact class do you use to spawn your popups?
from kakao.
I'm using a custom view extending from AppCompatAutocompleteTextView
Dumps
https://gist.github.com/ashdavies/4cfca8f5ff8697a8f53f566141480f73
https://gist.github.com/ashdavies/829645d64238115db33272af7c21d23f
from kakao.
I looked through the source code, and your view uses ListPopupWindow
class inside, which uses DropDownListView
class (not appcompat). So I would try to match by exact class name, not by parent class name.
from kakao.
Tried by class name also, the issue seems to be that the view hierarchy dumped with NoMatchingViewException
is that of the activity window, which doesn't display the DropDownListView
or the popup decor view, I've tried tweaking with withParent
, inRoot
to no avail 😞
from kakao.
Can you provide your screen class and test code where you try to access your list?
from kakao.
Sorry for the delay, I didn't see the notification
Screen
val list = KListView(
builder = {
isInstanceOf<ListView>()
withParent {
isRoot()
}
},
itemTypeBuilder = {
itemType(::Item)
}
)
class Item(interaction: DataInteraction) : KAdapterItem<Item>(interaction) {
val text = KTextView(interaction) {
withId(android.R.id.text1)
}
}
Test
screen {
list {
inRoot {
isPlatformPopup()
}
firstChild<FinanceCalculatorScreen.Item> {
perform {
click()
}
}
}
}
from kakao.
Hey there!
Try removing this:
withParent {
isRoot()
}
I'm not sure that your list view is a direct descendant of platform popup view.
from kakao.
Still get a NoMatchingViewException
, would it help if I submitted a PR to the samples with the problem I'm trying to solve?
from kakao.
I just noticed. isInstanceOf<ListView>()
is very weird. Kakao doesn't have that function. Kakao's function signature is isInstanceOf(clazz: Class<*>)
. It's not templated.
from kakao.
@Unlimity yep sorry this was an extension function in our code base, just an inline reified alias to Kakao's method
inline fun <reified T> ViewBuilder.isInstanceOf(): Unit = isInstanceOf(T::class.java)
from kakao.
Hm, I don't actually know how to help you now :(
Could you make a public repo with simple activity and test that reproduces your problem?
from kakao.
I'll create a PR for the samples directory with what I'm trying to achieve
from kakao.
@Unlimity Hey! I've created a sample so you can see what I'm trying to achieve
from kakao.
Related Issues (20)
- NestedScrollView not supported by ScrollTo ViewAction HOT 1
- [Question] how to do action on compound customview child ? HOT 1
- ActionBar - Support homeAsUpIndicator HOT 10
- Add TextInputLayoutAssertions.hasHint(@StringRes resId: Int) HOT 6
- isDescendantOfA{ } and withMatcher(isDescendantOfA( )) not the same? HOT 2
- Misleading readme? HOT 2
- AmbiguousViewMatcherException with recycler views HOT 2
- Lot of UI Test fail after upgrading to 2.3.3 HOT 7
- Issue with hasDrawable when ImageView is using scaleType HOT 5
- RecyclerView inside RecyclerView items, cannot get it to be recognized
- Does hasDrawable method work for AppCompatImageView? HOT 2
- Upgrade Espresso version to 3.3.0 HOT 4
- Optional View Elements HOT 2
- Android Compose support HOT 2
- Migrate away from JCenter HOT 8
- DrawableMatcher fails in 2.3.4 HOT 5
- Scroll to RecyclerView element that part can be off screen HOT 1
- Impossible to check if KAlertDialog isn't on the screen HOT 3
- Checking MenuItems
- DrawableMatcher getDrawable from resource
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kakao.