Skip to content

Add -android datamatcher selector strategy#386

Merged
dpgraham merged 20 commits intomasterfrom
dpgraham-hamcrest-matcher
Feb 12, 2019
Merged

Add -android datamatcher selector strategy#386
dpgraham merged 20 commits intomasterfrom
dpgraham-hamcrest-matcher

Conversation

@dpgraham
Copy link
Contributor

@dpgraham dpgraham commented Jan 24, 2019

{
  name: '<name>', args: ['arg1', 'arg2', '...'], class: '<optional class>'
}
  • name: The name of a method to invoke. The method must return a Hamcrest Matcher

  • args: The args provided to the method

  • class: The class name that the method is part of (defaults to org.hamcrest.Matchers). Can be fully qualified, or simple, and simple defaults to androidx.test.espresso.matcher package (e.g.: class=CursorMatchers fully qualified is class=androidx.test.espresso.matcher.CursorMatchers

  • Uses reflection to invoke the above methods

  • Selector is like driver.elements("-android datamatcher", "{...}")

@mykola-mokhnach
Copy link
Contributor

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

@dpgraham
Copy link
Contributor Author

@mykola-mokhnach Yeah, I'm planning on doing a lot of documentation for all the new Espresso features.

@dpgraham
Copy link
Contributor Author

Fixes pushed.

@dpgraham
Copy link
Contributor Author

Just made another push. Can I merge this? (Pending Codacy and TravisCI passing, of course)

return defaultValue
}

fun parsePrimitive(jsonPrimitive: JsonPrimitive): Any = when {
Copy link
Contributor

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 %)

Copy link
Contributor Author

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

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 :)

}

throw AppiumException("Could not invoke method: " +
throw AppiumException("Could not find method that matches " +
Copy link
Contributor

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 " +
Copy link
Contributor

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

Copy link
Contributor Author

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?

Copy link
Contributor

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.*
Copy link
Contributor

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();

Copy link
Contributor

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

Copy link
Contributor

@mykola-mokhnach mykola-mokhnach left a 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

@appium appium deleted a comment Jan 29, 2019
@appium appium deleted a comment Jan 29, 2019
@appium appium deleted a comment Jan 29, 2019
@appium appium deleted a comment Jan 29, 2019
@appium appium deleted a comment Jan 29, 2019
@appium appium deleted a comment from mykola-mokhnach Jan 29, 2019
@appium appium deleted a comment Jan 29, 2019
@appium appium deleted a comment Jan 29, 2019
@appium appium deleted a comment from mykola-mokhnach Jan 29, 2019
@appium appium deleted a comment Jan 29, 2019
@appium appium deleted a comment Jan 29, 2019
Copy link
Member

@KazuCocoa KazuCocoa left a 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;
Copy link
Member

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) {
Copy link
Member

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())
}

Copy link
Contributor Author

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.

@dpgraham dpgraham merged commit 0a4b32d into master Feb 12, 2019
@dpgraham dpgraham deleted the dpgraham-hamcrest-matcher branch February 12, 2019 01:34
@appium appium deleted a comment Feb 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants