Add -android datamatcher selector strategy#386
Conversation
...so-server/app/src/androidTest/java/io/appium/espressoserver/lib/helpers/GsonParserHelpers.kt
Outdated
Show resolved
Hide resolved
...so-server/app/src/androidTest/java/io/appium/espressoserver/lib/helpers/GsonParserHelpers.kt
Outdated
Show resolved
Hide resolved
...so-server/app/src/androidTest/java/io/appium/espressoserver/lib/helpers/GsonParserHelpers.kt
Outdated
Show resolved
Hide resolved
...so-server/app/src/androidTest/java/io/appium/espressoserver/lib/helpers/GsonParserHelpers.kt
Outdated
Show resolved
Hide resolved
...sso-server/app/src/androidTest/java/io/appium/espressoserver/lib/helpers/KReflectionUtils.kt
Outdated
Show resolved
Hide resolved
espresso-server/app/src/androidTest/java/io/appium/espressoserver/lib/helpers/ViewFinder.java
Outdated
Show resolved
Hide resolved
espresso-server/app/src/androidTest/java/io/appium/espressoserver/lib/helpers/ViewFinder.java
Outdated
Show resolved
Hide resolved
espresso-server/app/src/androidTest/java/io/appium/espressoserver/lib/model/DataMatcherJson.kt
Show resolved
Hide resolved
espresso-server/app/src/androidTest/java/io/appium/espressoserver/lib/model/HamcrestMatcher.kt
Outdated
Show resolved
Hide resolved
espresso-server/app/src/androidTest/java/io/appium/espressoserver/lib/model/HamcrestMatcher.kt
Show resolved
Hide resolved
|
I would be happy to see an official documentation entry for the new type of the locator, so then we could add it into client libs |
|
@mykola-mokhnach Yeah, I'm planning on doing a lot of documentation for all the new Espresso features. |
|
Fixes pushed. |
|
Just made another push. Can I merge this? (Pending Codacy and TravisCI passing, of course) |
| return defaultValue | ||
| } | ||
|
|
||
| fun parsePrimitive(jsonPrimitive: JsonPrimitive): Any = when { |
There was a problem hiding this comment.
this looks so Scal'ish %)
There was a problem hiding this comment.
Yeah that was Kazu's idea. I like it. What do you think?
There was a problem hiding this comment.
There was a problem hiding this comment.
Oh, so Scal'ish? (I haven't worked with Scala x) )
Actually, this is kind of functional style, I think :)
...sso-server/app/src/androidTest/java/io/appium/espressoserver/lib/helpers/KReflectionUtils.kt
Outdated
Show resolved
Hide resolved
| } | ||
|
|
||
| throw AppiumException("Could not invoke method: " + | ||
| throw AppiumException("Could not find method that matches " + |
| try { | ||
| return invokeMethod(instance::class.memberFunctions, methodName, instance, *providedParams) | ||
| } catch (e:AppiumException) { | ||
| throw AppiumException("Cannot execute method for instance of " + |
There was a problem hiding this comment.
You could also use triple quotes
There was a problem hiding this comment.
Do you know how to make it exclude newlines?
There was a problem hiding this comment.
trimMargin + replace, which also seem a bit redundant to me %)
|
|
||
| import androidx.test.espresso.DataInteraction | ||
| import androidx.test.espresso.Espresso.onData | ||
| import com.google.gson.* |
| val matcher = HamcrestMatcher.HamcrestMatcherDeserializer() | ||
| .deserialize(json, null, null) | ||
| .invoke(); | ||
|
|
There was a problem hiding this comment.
no need for the empty line
espresso-server/app/src/androidTest/java/io/appium/espressoserver/lib/model/DataMatcherJson.kt
Outdated
Show resolved
Hide resolved
mykola-mokhnach
left a comment
There was a problem hiding this comment.
some minor comments left
| import io.appium.espressoserver.lib.model.Element; | ||
| import io.appium.espressoserver.lib.model.NavigateToParams; | ||
| import io.appium.espressoserver.lib.model.ScrollToPageParams; | ||
| import io.appium.espressoserver.lib.model.SetTimeParams; |
|
|
||
| val args = arrayListOf<Any?>() | ||
| for (arg in listOfArgs) { | ||
| if (arg.isJsonPrimitive) { |
There was a problem hiding this comment.
[nits]
maybe, here also can write like:
when {
arg.isJsonPrimitive -> args.add(GsonParserHelpers.parsePrimitive(arg.asJsonPrimitive))
arg.isJsonNull -> args.add(null)
arg.isJsonObject -> args.add(HamcrestMatcherDeserializer().deserialize(arg, null, null).invoke())
}There was a problem hiding this comment.
Updated. I like that syntax.
Espresso has an
onDatamatcher (see https://medium.com/androiddevelopers/adapterviews-and-espresso-f4172aa853cf for more reference) that allows you to target adapters instead of ViewsThis is a selector strategy that allows users to pass a selector of the form:
name: The name of a method to invoke. The method must return a HamcrestMatcherargs: The args provided to the methodclass: The class name that the method is part of (defaults toorg.hamcrest.Matchers). Can be fully qualified, or simple, and simple defaults toandroidx.test.espresso.matcherpackage (e.g.:class=CursorMatchersfully qualified isclass=androidx.test.espresso.matcher.CursorMatchersUses reflection to invoke the above methods
Selector is like
driver.elements("-android datamatcher", "{...}")