-
-
Notifications
You must be signed in to change notification settings - Fork 75
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
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) |
@@ -37,4 +38,26 @@ class GsonParserHelpers { | |||
} | |||
return defaultValue | |||
} | |||
|
|||
fun parsePrimitive(jsonPrimitive: JsonPrimitive): Any = when { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks so Scal'ish %)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that was Kazu's idea. I like it. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -53,15 +75,24 @@ object KReflectionUtils { | |||
} | |||
} | |||
|
|||
throw AppiumException("Could not invoke method: " + | |||
throw AppiumException("Could not find method that matches " + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the method
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could also use triple quotes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know how to make it exclude newlines?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
star import?
val matcher = HamcrestMatcher.HamcrestMatcherDeserializer() | ||
.deserialize(json, null, null) | ||
.invoke(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for the empty line
espresso-server/app/src/androidTest/java/io/appium/espressoserver/lib/model/DataMatcherJson.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some minor comments left
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Kotlin :)
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 clean up
|
||
val args = arrayListOf<Any?>() | ||
for (arg in listOfArgs) { | ||
if (arg.isJsonPrimitive) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated. I like that syntax.
Espresso has an
onData
matcher (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 HamcrestMatcher
args
: 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.matcher
package (e.g.:class=CursorMatchers
fully qualified isclass=androidx.test.espresso.matcher.CursorMatchers
Uses reflection to invoke the above methods
Selector is like
driver.elements("-android datamatcher", "{...}")