From c3e3be4986eb199899a37bcbfefa9b4014c4e4b6 Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Sun, 14 Jul 2024 01:45:19 -0700 Subject: [PATCH] fix(kotlin): tweak ancestor/descendant (#717) * fix pom * fix(kotlin): tweak ancestor/descendant --- example/java/pom.xml | 32 ++++++++----------- .../test/java/example/appium/FlutterTest.java | 9 +++--- finder/kotlin/gradle.properties | 1 + .../appium_flutter/FlutterFinder.kt | 9 ++++++ 4 files changed, 29 insertions(+), 22 deletions(-) diff --git a/example/java/pom.xml b/example/java/pom.xml index 5b9a1a7b..778fef23 100644 --- a/example/java/pom.xml +++ b/example/java/pom.xml @@ -45,18 +45,17 @@ - io.appium - java-client - 4.1.2 - - - pro.truongsinh - appium-flutter-finder - 0.0.4 - + io.appium + java-client + 4.1.2 + + + com.github.appium + appium-flutter-driver + main-SNAPSHOT + - @@ -84,12 +83,9 @@ true - - - local-maven-repo - file:///Users/truongsinh/Dev/flutter/appium-flutter-driver/finder/kotlin/build/repository - - - - + + jitpack.io + https://jitpack.io + + diff --git a/example/java/src/test/java/example/appium/FlutterTest.java b/example/java/src/test/java/example/appium/FlutterTest.java index 7aad630a..108e580e 100644 --- a/example/java/src/test/java/example/appium/FlutterTest.java +++ b/example/java/src/test/java/example/appium/FlutterTest.java @@ -13,6 +13,7 @@ import org.openqa.selenium.OutputType; import io.appium.java_client.MobileElement; import pro.truongsinh.appium_flutter.FlutterFinder; +import pro.truongsinh.appium_flutter.finder.FlutterElement; public class FlutterTest extends BaseDriver { protected FlutterFinder find; @@ -25,7 +26,7 @@ public void setUp() throws Exception { @Test public void basicTest () throws InterruptedException { String buttonFinderKey = "increment"; - MobileElement counterTextFinder = find.byValueKey("counter"); + FlutterElement counterTextFinder = find.byValueKey("counter"); MobileElement buttonFinder = waitFor(buttonFinderKey); validateElementPosition(buttonFinder); @@ -73,7 +74,7 @@ public void basicTest () throws InterruptedException { find.byTooltip("Increment").click(); - assertEquals(find.descendant(find.byTooltip("counter_tooltip"), find.byValueKey("counter")).getText(), "3"); + assertEquals(find.descendant(find.byTooltip("counter_tooltip"), find.byValueKey("counter"), false, false).getText(), "3"); find.byType("FlatButton").click(); driver.executeScript("flutter:waitForAbsent", buttonFinder); @@ -107,9 +108,9 @@ public void basicTest () throws InterruptedException { find.descendant( find.ancestor( find.bySemanticsLabel(Pattern.compile("counter_semantic")), - find.byType("Tooltip") + find.byType("Tooltip"), false, false ), - find.byType("Text") + find.byType("Text"), false, false ) .click() ; diff --git a/finder/kotlin/gradle.properties b/finder/kotlin/gradle.properties index 47e1bd7b..301a6ca5 100644 --- a/finder/kotlin/gradle.properties +++ b/finder/kotlin/gradle.properties @@ -24,3 +24,4 @@ org.gradle.vfs.watch=true org.gradle.caching=true # https://youtrack.jetbrains.com/issue/KT-46708 kotlin.stdlib.default.dependency=false +kotlin.experimental=true diff --git a/finder/kotlin/src/main/kotlin/pro/truongsinh/appium_flutter/FlutterFinder.kt b/finder/kotlin/src/main/kotlin/pro/truongsinh/appium_flutter/FlutterFinder.kt index 374f8d2e..cc907dee 100644 --- a/finder/kotlin/src/main/kotlin/pro/truongsinh/appium_flutter/FlutterFinder.kt +++ b/finder/kotlin/src/main/kotlin/pro/truongsinh/appium_flutter/FlutterFinder.kt @@ -17,6 +17,12 @@ import pro.truongsinh.appium_flutter.finder.text as _text public class FlutterFinder(private val driver: RemoteWebDriver) { private val fileDetector = FileDetector { _ -> null } + fun ancestor(of: FlutterElement, matching: FlutterElement): FlutterElement { + val f = _ancestor(of, matching, matchRoot = false, firstMatchOnly = false) + f.setParent(driver) + f.setFileDetector(fileDetector) + return f + } fun ancestor(of: FlutterElement, matching: FlutterElement, matchRoot: Boolean = false, firstMatchOnly: Boolean = false): FlutterElement { val f = _ancestor(of, matching, matchRoot, firstMatchOnly) f.setParent(driver) @@ -59,6 +65,9 @@ public class FlutterFinder(private val driver: RemoteWebDriver) { f.setFileDetector(fileDetector) return f } + fun descendant(of: FlutterElement, matching: FlutterElement): FlutterElement { + return _descendant(of, matching, matchRoot = false, firstMatchOnly = false) + } fun descendant(of: FlutterElement, matching: FlutterElement, matchRoot: Boolean = false, firstMatchOnly: Boolean = false): FlutterElement { val f = _descendant(of, matching, matchRoot, firstMatchOnly) f.setParent(driver)