Skip to content

Commit eae1817

Browse files
committed
finder returns FlutterElement
1 parent 6bd3ef2 commit eae1817

File tree

16 files changed

+155
-69
lines changed

16 files changed

+155
-69
lines changed

example/java/pom.xml

+6-1
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,15 @@
4444
<version>2.2.4</version>
4545
</dependency>
4646

47+
<dependency>
48+
<groupId>io.appium</groupId>
49+
<artifactId>java-client</artifactId>
50+
<version>4.1.2</version>
51+
</dependency>
4752
<dependency>
4853
<groupId>pro.truongsinh</groupId>
4954
<artifactId>appium-flutter-finder</artifactId>
50-
<version>0.0.1</version>
55+
<version>0.0.2</version>
5156
</dependency>
5257

5358
</dependencies>

example/java/src/test/java/example/appium/BaseDriver.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
package example.appium;
22

33
import io.appium.java_client.AppiumDriver;
4+
import io.appium.java_client.MobileElement;
45
import io.appium.java_client.ios.IOSDriver;
56
import io.appium.java_client.service.local.AppiumDriverLocalService;
67
import io.appium.java_client.service.local.AppiumServerHasNotBeenStartedLocallyException;
78
import org.junit.After;
89
import org.junit.Before;
9-
import org.openqa.selenium.WebElement;
1010
import org.openqa.selenium.remote.DesiredCapabilities;
11+
import org.openqa.selenium.support.ui.WebDriverWait;
1112

1213
import java.io.File;
1314

1415
public class BaseDriver {
15-
public AppiumDriver<WebElement> driver;
16+
public AppiumDriver<MobileElement> driver;
17+
public WebDriverWait wait;
1618
private static AppiumDriverLocalService service;
1719

1820
@Before
@@ -38,7 +40,8 @@ public void setUp() throws Exception {
3840

3941
capabilities.setCapability("automationName", "Flutter");
4042

41-
driver = new IOSDriver<>(service.getUrl(), capabilities);
43+
driver = new IOSDriver<MobileElement>(service.getUrl(), capabilities);
44+
wait = new WebDriverWait(driver, 10);
4245
}
4346

4447
@After
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
package example.appium;
22

3+
import org.junit.Before;
34
import org.junit.Test;
4-
import pro.truongsinh.appium_flutter.finder.Finder;
5-
import org.openqa.selenium.By;
6-
import org.openqa.selenium.WebElement;
7-
8-
import java.util.List;
5+
import pro.truongsinh.appium_flutter.FlutterFinder;
96

107
import static org.junit.Assert.assertEquals;
118

12-
public class FlutterTest extends BaseDriver{
13-
@Test
14-
public void simpleTest(){
15-
String a = Finder.text("input");
16-
System.out.println(a);
17-
}
9+
import io.appium.java_client.MobileElement;
10+
11+
public class FlutterTest extends BaseDriver {
12+
protected FlutterFinder finder;
13+
@Before
14+
public void setUp() throws Exception {
15+
super.setUp();
16+
finder = new FlutterFinder(driver);
17+
}
18+
@Test
19+
public void basicTest () throws InterruptedException {
20+
MobileElement el1 = finder.byValueKey("increment");
21+
el1.click();
22+
Thread.sleep(1000);
23+
}
1824

1925
}

finder/kotlin/build.gradle.kts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import org.gradle.jvm.tasks.Jar
22

33
group = "pro.truongsinh"
4-
version = "0.0.1"
4+
version = "0.0.2"
55

66
plugins {
77
id("kotlinx-serialization") version "1.3.40"
@@ -18,6 +18,7 @@ repositories {
1818
dependencies {
1919
implementation(kotlin("stdlib"))
2020
implementation ("org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.11.1")
21+
implementation ("io.appium:java-client:2.1.0")
2122
testImplementation("junit:junit:4.12")
2223
}
2324

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package pro.truongsinh.appium_flutter
2+
3+
import io.appium.java_client.MobileElement
4+
import org.openqa.selenium.remote.RemoteWebDriver
5+
import pro.truongsinh.appium_flutter.finder.FlutterElement
6+
import pro.truongsinh.appium_flutter.finder.ancestor as _ancestor
7+
import pro.truongsinh.appium_flutter.finder.bySemanticsLabel as _bySemanticsLabel
8+
import pro.truongsinh.appium_flutter.finder.byTooltip as _byTooltip
9+
import pro.truongsinh.appium_flutter.finder.byType as _byType
10+
import pro.truongsinh.appium_flutter.finder.byValueKey as _byValueKey
11+
import pro.truongsinh.appium_flutter.finder.descendant as _descendant
12+
import pro.truongsinh.appium_flutter.finder.pageback as _pageback
13+
import pro.truongsinh.appium_flutter.finder.text as _text
14+
15+
16+
public class FlutterFinder(driver: RemoteWebDriver) {
17+
private val driver = driver
18+
fun ancestor(of: FlutterElement, matching: FlutterElement, matchRoot: Boolean = false): FlutterElement {
19+
val f = _ancestor(of, matching, matchRoot)
20+
f.setParent(driver)
21+
return f
22+
}
23+
fun bySemanticsLabel(label: String): FlutterElement {
24+
val f = _bySemanticsLabel(label)
25+
f.setParent(driver)
26+
return f
27+
}
28+
fun bySemanticsLabel(label: Regex): FlutterElement {
29+
val f = _bySemanticsLabel(label)
30+
f.setParent(driver)
31+
return f
32+
}
33+
fun byTooltip(input: String): FlutterElement {
34+
val f = _byTooltip(input)
35+
f.setParent(driver)
36+
return f
37+
}
38+
fun byType(input: String): FlutterElement {
39+
val f = _byType(input)
40+
f.setParent(driver)
41+
return f
42+
}
43+
fun byValueKey(input: String): FlutterElement {
44+
val f = _byValueKey(input)
45+
f.setParent(driver)
46+
return f
47+
}
48+
fun byValueKey(input: Int): FlutterElement {
49+
val f = _byValueKey(input)
50+
f.setParent(driver)
51+
return f
52+
}
53+
fun descendant(of: FlutterElement, matching: FlutterElement, matchRoot: Boolean = false): FlutterElement {
54+
val f = _descendant(of, matching, matchRoot)
55+
f.setParent(driver)
56+
return f
57+
}
58+
fun pageback(): FlutterElement {
59+
val f = _pageback()
60+
f.setParent(driver)
61+
return f
62+
}
63+
fun text(input: String): FlutterElement {
64+
val f = _text(input)
65+
f.setParent(driver)
66+
return f
67+
}
68+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package pro.truongsinh.appium_flutter.finder
2+
3+
import io.appium.java_client.MobileElement
4+
5+
public class FlutterElement : MobileElement {
6+
private var _rawMap: Map<String, *>
7+
constructor(m: Map<String, *>) {
8+
_rawMap = m
9+
id = serialize(m)
10+
}
11+
fun getRawMap(): Map<String, *> { return _rawMap }
12+
}
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
@file:JvmName("Finder")
1+
@file:JvmName("_FinderRawMethods")
22
@file:JvmMultifileClass
33
package pro.truongsinh.appium_flutter.finder
44

5-
fun ancestor(of: String, matching: String, matchRoot: Boolean = false): String {
5+
fun ancestor(of: FlutterElement, matching: FlutterElement, matchRoot: Boolean = false): FlutterElement {
66
val m = mutableMapOf(
77
"finderType" to "Ancestor",
88
"matchRoot" to matchRoot
99
)
10-
deserialize(of).forEach {
11-
print(it.value)
10+
of.getRawMap().forEach {
1211
m.put("of_${it.key}", it.value!!)
1312
}
14-
deserialize(matching).forEach {
13+
matching.getRawMap().forEach {
1514
m.put("matching_${it.key}", it.value!!)
1615
}
17-
return serialize(m)
16+
return FlutterElement(m)
1817
}
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
1-
@file:JvmName("Finder")
1+
@file:JvmName("_FinderRawMethods")
22
@file:JvmMultifileClass
33
package pro.truongsinh.appium_flutter.finder
44

5-
fun bySemanticsLabel(label: String): String {
6-
val base64Encoded = serialize(mapOf(
5+
fun bySemanticsLabel(label: String): FlutterElement {
6+
return FlutterElement(mapOf(
77
"finderType" to "BySemanticsLabel",
88
"isRegExp" to false,
99
"label" to label
1010
))
11-
return base64Encoded
1211
}
1312

14-
fun bySemanticsLabel(label: Regex): String {
15-
val base64Encoded = serialize(mapOf(
13+
fun bySemanticsLabel(label: Regex): FlutterElement {
14+
return FlutterElement(mapOf(
1615
"finderType" to "BySemanticsLabel",
1716
"isRegExp" to true,
1817
"label" to label.toString()
1918
))
20-
return base64Encoded
2119
}
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
@file:JvmName("Finder")
1+
@file:JvmName("_FinderRawMethods")
22
@file:JvmMultifileClass
33
package pro.truongsinh.appium_flutter.finder
44

5-
fun byTooltip(input: String): String {
6-
val base64Encoded = serialize(mapOf(
5+
fun byTooltip(input: String): FlutterElement {
6+
return FlutterElement(mapOf(
77
"finderType" to "ByTooltipMessage",
88
"text" to input
99
))
10-
return base64Encoded
1110
}
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
@file:JvmName("Finder")
1+
@file:JvmName("_FinderRawMethods")
22
@file:JvmMultifileClass
33
package pro.truongsinh.appium_flutter.finder
44

5-
fun byType(input: String): String {
6-
val base64Encoded = serialize(mapOf(
5+
fun byType(input: String): FlutterElement {
6+
return FlutterElement(mapOf(
77
"finderType" to "ByType",
88
"type" to input
99
))
10-
return base64Encoded
1110
}
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
1-
@file:JvmName("Finder")
1+
@file:JvmName("_FinderRawMethods")
22
@file:JvmMultifileClass
33
package pro.truongsinh.appium_flutter.finder
44

5-
fun byValueKey(input: String): String {
6-
val base64Encoded = serialize(mapOf(
5+
fun byValueKey(input: String): FlutterElement {
6+
return FlutterElement(mapOf(
77
"finderType" to "ByValueKey",
88
"keyValueType" to "String",
99
"keyValueString" to input
1010
))
11-
return base64Encoded
1211
}
1312

14-
fun byValueKey(input: Int): String {
15-
val base64Encoded = serialize(mapOf(
13+
fun byValueKey(input: Int): FlutterElement {
14+
return FlutterElement(mapOf(
1615
"finderType" to "ByValueKey",
1716
"keyValueType" to "int",
1817
"keyValueString" to input
1918
))
20-
return base64Encoded
2119
}
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
@file:JvmName("Finder")
1+
@file:JvmName("_FinderRawMethods")
22
@file:JvmMultifileClass
33
package pro.truongsinh.appium_flutter.finder
44

5-
fun descendant(of: String, matching: String, matchRoot: Boolean = false): String {
5+
fun descendant(of: FlutterElement, matching: FlutterElement, matchRoot: Boolean = false): FlutterElement {
66
val m = mutableMapOf(
77
"finderType" to "Descendant",
88
"matchRoot" to matchRoot
99
)
10-
deserialize(of).forEach {
11-
print(it.value)
10+
of.getRawMap().forEach {
1211
m.put("of_${it.key}", it.value!!)
1312
}
14-
deserialize(matching).forEach {
13+
matching.getRawMap().forEach {
1514
m.put("matching_${it.key}", it.value!!)
1615
}
17-
return serialize(m)
16+
return FlutterElement(m)
1817
}
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
@file:JvmName("Finder")
1+
@file:JvmName("_FinderRawMethods")
22
@file:JvmMultifileClass
33
package pro.truongsinh.appium_flutter.finder
44

5-
fun pageback(): String {
6-
val base64Encoded = serialize(mapOf("finderType" to "PageBack"))
7-
return base64Encoded
5+
fun pageback(): FlutterElement {
6+
return FlutterElement(mapOf("finderType" to "PageBack"))
87
}

finder/kotlin/src/main/kotlin/pro/truongsinh/appium_flutter/finder/serializer.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
1+
@file:JvmName("_FinderRawMethods")
2+
@file:JvmMultifileClass
23
package pro.truongsinh.appium_flutter.finder
34

45
import java.util.Base64
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
@file:JvmName("Finder")
1+
@file:JvmName("_FinderRawMethods")
22
@file:JvmMultifileClass
33
package pro.truongsinh.appium_flutter.finder
44

5-
fun text(input: String): String {
6-
val base64Encoded = serialize(mapOf(
5+
fun text(input: String): FlutterElement {
6+
return FlutterElement(mapOf(
77
"finderType" to "ByText",
88
"text" to input
99
))
10-
return base64Encoded
1110
}

0 commit comments

Comments
 (0)