diff --git a/example/java/pom.xml b/example/java/pom.xml index f32d8f40..6611058f 100644 --- a/example/java/pom.xml +++ b/example/java/pom.xml @@ -52,7 +52,7 @@ pro.truongsinh appium-flutter-finder - 0.0.2 + 0.0.3 diff --git a/example/java/src/test/java/example/appium/FlutterTest.java b/example/java/src/test/java/example/appium/FlutterTest.java index 82ae7950..e10bec30 100644 --- a/example/java/src/test/java/example/appium/FlutterTest.java +++ b/example/java/src/test/java/example/appium/FlutterTest.java @@ -7,11 +7,11 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.regex.Pattern; import java.io.File; import org.openqa.selenium.OutputType; import io.appium.java_client.MobileElement; -import kotlin.text.Regex; import pro.truongsinh.appium_flutter.FlutterFinder; public class FlutterTest extends BaseDriver { @@ -71,8 +71,7 @@ public void basicTest () throws InterruptedException { find.byTooltip("Increment").click(); - // @todo param override - assertEquals(find.descendant(find.byTooltip("counter_tooltip"), find.byValueKey("counter"), false).getText(), "3"); + assertEquals(find.descendant(find.byTooltip("counter_tooltip"), find.byValueKey("counter")).getText(), "3"); find.byType("FlatButton").click(); driver.executeScript("flutter:waitForAbsent", buttonFinder); @@ -101,19 +100,15 @@ public void basicTest () throws InterruptedException { driver.executeScript("flutter:enterText", "I can enter text"); // enter text driver.executeScript("flutter:waitFor", find.text("I can enter text")); // verify text appears on UI - // @todo should be `pageBack` - find.pageback().click(); + find.pageBack().click(); driver.executeScript("flutter:waitFor", buttonFinder); find.descendant( find.ancestor( - // @todo should be Java Pattern - find.bySemanticsLabel(new Regex("counter_semantic")), - find.byType("Tooltip"), - false + find.bySemanticsLabel(Pattern.compile("counter_semantic")), + find.byType("Tooltip") ), - find.byType("Text"), - false + find.byType("Text") ) .click() ; diff --git a/finder/kotlin/build.gradle.kts b/finder/kotlin/build.gradle.kts index 176e9bf8..915f9e99 100644 --- a/finder/kotlin/build.gradle.kts +++ b/finder/kotlin/build.gradle.kts @@ -1,7 +1,7 @@ import org.gradle.jvm.tasks.Jar group = "pro.truongsinh" -version = "0.0.2" +version = "0.0.3" plugins { id("kotlinx-serialization") version "1.3.40" 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 231ad9e9..03caf166 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 @@ -1,5 +1,7 @@ package pro.truongsinh.appium_flutter +import java.util.regex.Pattern; + import io.appium.java_client.MobileElement import org.openqa.selenium.remote.RemoteWebDriver import pro.truongsinh.appium_flutter.finder.FlutterElement @@ -9,7 +11,7 @@ import pro.truongsinh.appium_flutter.finder.byTooltip as _byTooltip import pro.truongsinh.appium_flutter.finder.byType as _byType import pro.truongsinh.appium_flutter.finder.byValueKey as _byValueKey import pro.truongsinh.appium_flutter.finder.descendant as _descendant -import pro.truongsinh.appium_flutter.finder.pageback as _pageback +import pro.truongsinh.appium_flutter.finder.pageBack as _pageBack import pro.truongsinh.appium_flutter.finder.text as _text @@ -20,12 +22,17 @@ public class FlutterFinder(driver: RemoteWebDriver) { f.setParent(driver) return f } + fun ancestor(of: FlutterElement, matching: FlutterElement): FlutterElement { + val f = _ancestor(of, matching) + f.setParent(driver) + return f + } fun bySemanticsLabel(label: String): FlutterElement { val f = _bySemanticsLabel(label) f.setParent(driver) return f } - fun bySemanticsLabel(label: Regex): FlutterElement { + fun bySemanticsLabel(label: Pattern): FlutterElement { val f = _bySemanticsLabel(label) f.setParent(driver) return f @@ -55,8 +62,13 @@ public class FlutterFinder(driver: RemoteWebDriver) { f.setParent(driver) return f } - fun pageback(): FlutterElement { - val f = _pageback() + fun descendant(of: FlutterElement, matching: FlutterElement): FlutterElement { + val f = _descendant(of, matching) + f.setParent(driver) + return f + } + fun pageBack(): FlutterElement { + val f = _pageBack() f.setParent(driver) return f } diff --git a/finder/kotlin/src/main/kotlin/pro/truongsinh/appium_flutter/finder/bySemanticsLabel.kt b/finder/kotlin/src/main/kotlin/pro/truongsinh/appium_flutter/finder/bySemanticsLabel.kt index acce28c4..b9cbd3bf 100755 --- a/finder/kotlin/src/main/kotlin/pro/truongsinh/appium_flutter/finder/bySemanticsLabel.kt +++ b/finder/kotlin/src/main/kotlin/pro/truongsinh/appium_flutter/finder/bySemanticsLabel.kt @@ -2,6 +2,8 @@ @file:JvmMultifileClass package pro.truongsinh.appium_flutter.finder +import java.util.regex.Pattern; + fun bySemanticsLabel(label: String): FlutterElement { return FlutterElement(mapOf( "finderType" to "BySemanticsLabel", @@ -10,7 +12,7 @@ fun bySemanticsLabel(label: String): FlutterElement { )) } -fun bySemanticsLabel(label: Regex): FlutterElement { +fun bySemanticsLabel(label: Pattern): FlutterElement { return FlutterElement(mapOf( "finderType" to "BySemanticsLabel", "isRegExp" to true, diff --git a/finder/kotlin/src/main/kotlin/pro/truongsinh/appium_flutter/finder/pageback.kt b/finder/kotlin/src/main/kotlin/pro/truongsinh/appium_flutter/finder/pageback.kt index 29878440..f33ce5ad 100755 --- a/finder/kotlin/src/main/kotlin/pro/truongsinh/appium_flutter/finder/pageback.kt +++ b/finder/kotlin/src/main/kotlin/pro/truongsinh/appium_flutter/finder/pageback.kt @@ -2,6 +2,6 @@ @file:JvmMultifileClass package pro.truongsinh.appium_flutter.finder -fun pageback(): FlutterElement { +fun pageBack(): FlutterElement { return FlutterElement(mapOf("finderType" to "PageBack")) } diff --git a/finder/kotlin/src/test/kotlin/pro/truongsinh/appium_flutter/finder/FinderTest.kt b/finder/kotlin/src/test/kotlin/pro/truongsinh/appium_flutter/finder/FinderTest.kt index f36efe71..c7a78db1 100755 --- a/finder/kotlin/src/test/kotlin/pro/truongsinh/appium_flutter/finder/FinderTest.kt +++ b/finder/kotlin/src/test/kotlin/pro/truongsinh/appium_flutter/finder/FinderTest.kt @@ -1,5 +1,7 @@ package pro.truongsinh.appium_flutter.finder +import java.util.regex.Pattern; + import org.junit.Assert.assertEquals import org.junit.Test @@ -8,12 +10,12 @@ class FinderTest { val expected = "eyJmaW5kZXJUeXBlIjoiQW5jZXN0b3IiLCJtYXRjaFJvb3QiOmZhbHNlLCJvZl9maW5kZXJUeXBlIjoiQW5jZXN0b3IiLCJvZl9tYXRjaFJvb3QiOmZhbHNlLCJvZl9vZl9maW5kZXJUeXBlIjoiUGFnZUJhY2siLCJvZl9tYXRjaGluZ19maW5kZXJUeXBlIjoiUGFnZUJhY2siLCJtYXRjaGluZ19maW5kZXJUeXBlIjoiQW5jZXN0b3IiLCJtYXRjaGluZ19tYXRjaFJvb3QiOmZhbHNlLCJtYXRjaGluZ19vZl9maW5kZXJUeXBlIjoiUGFnZUJhY2siLCJtYXRjaGluZ19tYXRjaGluZ19maW5kZXJUeXBlIjoiUGFnZUJhY2sifQ" val observed = ancestor( of = ancestor( - of = pageback(), - matching = pageback() + of = pageBack(), + matching = pageBack() ), matching = ancestor( - of = pageback(), - matching = pageback() + of = pageBack(), + matching = pageBack() ) ).id assertEquals(expected, observed) @@ -22,7 +24,7 @@ class FinderTest { assertEquals("eyJmaW5kZXJUeXBlIjoiQnlTZW1hbnRpY3NMYWJlbCIsImlzUmVnRXhwIjpmYWxzZSwibGFiZWwiOiJzaW1wbGUifQ", bySemanticsLabel("simple").id) } @Test fun TestBySemanticsLabelRegex() { - assertEquals("eyJmaW5kZXJUeXBlIjoiQnlTZW1hbnRpY3NMYWJlbCIsImlzUmVnRXhwIjp0cnVlLCJsYWJlbCI6ImNvbXBsaWNhdGVkIn0", bySemanticsLabel(Regex("complicated")).id) + assertEquals("eyJmaW5kZXJUeXBlIjoiQnlTZW1hbnRpY3NMYWJlbCIsImlzUmVnRXhwIjp0cnVlLCJsYWJlbCI6ImNvbXBsaWNhdGVkIn0", bySemanticsLabel(Pattern.compile("complicated")).id) } @Test fun TestByTooltip() { assertEquals("eyJmaW5kZXJUeXBlIjoiQnlUb29sdGlwTWVzc2FnZSIsInRleHQiOiJteVRleHQifQ", byTooltip("myText").id) @@ -44,18 +46,18 @@ class FinderTest { val expected = "eyJmaW5kZXJUeXBlIjoiRGVzY2VuZGFudCIsIm1hdGNoUm9vdCI6ZmFsc2UsIm9mX2ZpbmRlclR5cGUiOiJEZXNjZW5kYW50Iiwib2ZfbWF0Y2hSb290IjpmYWxzZSwib2Zfb2ZfZmluZGVyVHlwZSI6IlBhZ2VCYWNrIiwib2ZfbWF0Y2hpbmdfZmluZGVyVHlwZSI6IlBhZ2VCYWNrIiwibWF0Y2hpbmdfZmluZGVyVHlwZSI6IkRlc2NlbmRhbnQiLCJtYXRjaGluZ19tYXRjaFJvb3QiOmZhbHNlLCJtYXRjaGluZ19vZl9maW5kZXJUeXBlIjoiUGFnZUJhY2siLCJtYXRjaGluZ19tYXRjaGluZ19maW5kZXJUeXBlIjoiUGFnZUJhY2sifQ" val observed = descendant( of = descendant( - of = pageback(), - matching = pageback() + of = pageBack(), + matching = pageBack() ), matching = descendant( - of = pageback(), - matching = pageback() + of = pageBack(), + matching = pageBack() ) ).id assertEquals(expected, observed) } @Test fun testPageback() { - assertEquals("eyJmaW5kZXJUeXBlIjoiUGFnZUJhY2sifQ", pageback().id) + assertEquals("eyJmaW5kZXJUeXBlIjoiUGFnZUJhY2sifQ", pageBack().id) } @Test fun testText() { assertEquals("eyJmaW5kZXJUeXBlIjoiQnlUZXh0IiwidGV4dCI6IlRoaXMgaXMgMm5kIHJvdXRlIn0", text("This is 2nd route").id)