Skip to content

Commit

Permalink
finder returns FlutterElement
Browse files Browse the repository at this point in the history
  • Loading branch information
truongsinh committed Jul 20, 2019
1 parent 6bd3ef2 commit eae1817
Show file tree
Hide file tree
Showing 16 changed files with 155 additions and 69 deletions.
7 changes: 6 additions & 1 deletion example/java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,15 @@
<version>2.2.4</version>
</dependency>

<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>pro.truongsinh</groupId>
<artifactId>appium-flutter-finder</artifactId>
<version>0.0.1</version>
<version>0.0.2</version>
</dependency>

</dependencies>
Expand Down
9 changes: 6 additions & 3 deletions example/java/src/test/java/example/appium/BaseDriver.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package example.appium;

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.ios.IOSDriver;
import io.appium.java_client.service.local.AppiumDriverLocalService;
import io.appium.java_client.service.local.AppiumServerHasNotBeenStartedLocallyException;
import org.junit.After;
import org.junit.Before;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.io.File;

public class BaseDriver {
public AppiumDriver<WebElement> driver;
public AppiumDriver<MobileElement> driver;
public WebDriverWait wait;
private static AppiumDriverLocalService service;

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

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

driver = new IOSDriver<>(service.getUrl(), capabilities);
driver = new IOSDriver<MobileElement>(service.getUrl(), capabilities);
wait = new WebDriverWait(driver, 10);
}

@After
Expand Down
28 changes: 17 additions & 11 deletions example/java/src/test/java/example/appium/FlutterTest.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
package example.appium;

import org.junit.Before;
import org.junit.Test;
import pro.truongsinh.appium_flutter.finder.Finder;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import java.util.List;
import pro.truongsinh.appium_flutter.FlutterFinder;

import static org.junit.Assert.assertEquals;

public class FlutterTest extends BaseDriver{
@Test
public void simpleTest(){
String a = Finder.text("input");
System.out.println(a);
}
import io.appium.java_client.MobileElement;

public class FlutterTest extends BaseDriver {
protected FlutterFinder finder;
@Before
public void setUp() throws Exception {
super.setUp();
finder = new FlutterFinder(driver);
}
@Test
public void basicTest () throws InterruptedException {
MobileElement el1 = finder.byValueKey("increment");
el1.click();
Thread.sleep(1000);
}

}
3 changes: 2 additions & 1 deletion finder/kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import org.gradle.jvm.tasks.Jar

group = "pro.truongsinh"
version = "0.0.1"
version = "0.0.2"

plugins {
id("kotlinx-serialization") version "1.3.40"
Expand All @@ -18,6 +18,7 @@ repositories {
dependencies {
implementation(kotlin("stdlib"))
implementation ("org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.11.1")
implementation ("io.appium:java-client:2.1.0")
testImplementation("junit:junit:4.12")
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package pro.truongsinh.appium_flutter

import io.appium.java_client.MobileElement
import org.openqa.selenium.remote.RemoteWebDriver
import pro.truongsinh.appium_flutter.finder.FlutterElement
import pro.truongsinh.appium_flutter.finder.ancestor as _ancestor
import pro.truongsinh.appium_flutter.finder.bySemanticsLabel as _bySemanticsLabel
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.text as _text


public class FlutterFinder(driver: RemoteWebDriver) {
private val driver = driver
fun ancestor(of: FlutterElement, matching: FlutterElement, matchRoot: Boolean = false): FlutterElement {
val f = _ancestor(of, matching, matchRoot)
f.setParent(driver)
return f
}
fun bySemanticsLabel(label: String): FlutterElement {
val f = _bySemanticsLabel(label)
f.setParent(driver)
return f
}
fun bySemanticsLabel(label: Regex): FlutterElement {
val f = _bySemanticsLabel(label)
f.setParent(driver)
return f
}
fun byTooltip(input: String): FlutterElement {
val f = _byTooltip(input)
f.setParent(driver)
return f
}
fun byType(input: String): FlutterElement {
val f = _byType(input)
f.setParent(driver)
return f
}
fun byValueKey(input: String): FlutterElement {
val f = _byValueKey(input)
f.setParent(driver)
return f
}
fun byValueKey(input: Int): FlutterElement {
val f = _byValueKey(input)
f.setParent(driver)
return f
}
fun descendant(of: FlutterElement, matching: FlutterElement, matchRoot: Boolean = false): FlutterElement {
val f = _descendant(of, matching, matchRoot)
f.setParent(driver)
return f
}
fun pageback(): FlutterElement {
val f = _pageback()
f.setParent(driver)
return f
}
fun text(input: String): FlutterElement {
val f = _text(input)
f.setParent(driver)
return f
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package pro.truongsinh.appium_flutter.finder

import io.appium.java_client.MobileElement

public class FlutterElement : MobileElement {
private var _rawMap: Map<String, *>
constructor(m: Map<String, *>) {
_rawMap = m
id = serialize(m)
}
fun getRawMap(): Map<String, *> { return _rawMap }
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
@file:JvmName("Finder")
@file:JvmName("_FinderRawMethods")
@file:JvmMultifileClass
package pro.truongsinh.appium_flutter.finder

fun ancestor(of: String, matching: String, matchRoot: Boolean = false): String {
fun ancestor(of: FlutterElement, matching: FlutterElement, matchRoot: Boolean = false): FlutterElement {
val m = mutableMapOf(
"finderType" to "Ancestor",
"matchRoot" to matchRoot
)
deserialize(of).forEach {
print(it.value)
of.getRawMap().forEach {
m.put("of_${it.key}", it.value!!)
}
deserialize(matching).forEach {
matching.getRawMap().forEach {
m.put("matching_${it.key}", it.value!!)
}
return serialize(m)
return FlutterElement(m)
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
@file:JvmName("Finder")
@file:JvmName("_FinderRawMethods")
@file:JvmMultifileClass
package pro.truongsinh.appium_flutter.finder

fun bySemanticsLabel(label: String): String {
val base64Encoded = serialize(mapOf(
fun bySemanticsLabel(label: String): FlutterElement {
return FlutterElement(mapOf(
"finderType" to "BySemanticsLabel",
"isRegExp" to false,
"label" to label
))
return base64Encoded
}

fun bySemanticsLabel(label: Regex): String {
val base64Encoded = serialize(mapOf(
fun bySemanticsLabel(label: Regex): FlutterElement {
return FlutterElement(mapOf(
"finderType" to "BySemanticsLabel",
"isRegExp" to true,
"label" to label.toString()
))
return base64Encoded
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
@file:JvmName("Finder")
@file:JvmName("_FinderRawMethods")
@file:JvmMultifileClass
package pro.truongsinh.appium_flutter.finder

fun byTooltip(input: String): String {
val base64Encoded = serialize(mapOf(
fun byTooltip(input: String): FlutterElement {
return FlutterElement(mapOf(
"finderType" to "ByTooltipMessage",
"text" to input
))
return base64Encoded
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
@file:JvmName("Finder")
@file:JvmName("_FinderRawMethods")
@file:JvmMultifileClass
package pro.truongsinh.appium_flutter.finder

fun byType(input: String): String {
val base64Encoded = serialize(mapOf(
fun byType(input: String): FlutterElement {
return FlutterElement(mapOf(
"finderType" to "ByType",
"type" to input
))
return base64Encoded
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
@file:JvmName("Finder")
@file:JvmName("_FinderRawMethods")
@file:JvmMultifileClass
package pro.truongsinh.appium_flutter.finder

fun byValueKey(input: String): String {
val base64Encoded = serialize(mapOf(
fun byValueKey(input: String): FlutterElement {
return FlutterElement(mapOf(
"finderType" to "ByValueKey",
"keyValueType" to "String",
"keyValueString" to input
))
return base64Encoded
}

fun byValueKey(input: Int): String {
val base64Encoded = serialize(mapOf(
fun byValueKey(input: Int): FlutterElement {
return FlutterElement(mapOf(
"finderType" to "ByValueKey",
"keyValueType" to "int",
"keyValueString" to input
))
return base64Encoded
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
@file:JvmName("Finder")
@file:JvmName("_FinderRawMethods")
@file:JvmMultifileClass
package pro.truongsinh.appium_flutter.finder

fun descendant(of: String, matching: String, matchRoot: Boolean = false): String {
fun descendant(of: FlutterElement, matching: FlutterElement, matchRoot: Boolean = false): FlutterElement {
val m = mutableMapOf(
"finderType" to "Descendant",
"matchRoot" to matchRoot
)
deserialize(of).forEach {
print(it.value)
of.getRawMap().forEach {
m.put("of_${it.key}", it.value!!)
}
deserialize(matching).forEach {
matching.getRawMap().forEach {
m.put("matching_${it.key}", it.value!!)
}
return serialize(m)
return FlutterElement(m)
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
@file:JvmName("Finder")
@file:JvmName("_FinderRawMethods")
@file:JvmMultifileClass
package pro.truongsinh.appium_flutter.finder

fun pageback(): String {
val base64Encoded = serialize(mapOf("finderType" to "PageBack"))
return base64Encoded
fun pageback(): FlutterElement {
return FlutterElement(mapOf("finderType" to "PageBack"))
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

@file:JvmName("_FinderRawMethods")
@file:JvmMultifileClass
package pro.truongsinh.appium_flutter.finder

import java.util.Base64
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
@file:JvmName("Finder")
@file:JvmName("_FinderRawMethods")
@file:JvmMultifileClass
package pro.truongsinh.appium_flutter.finder

fun text(input: String): String {
val base64Encoded = serialize(mapOf(
fun text(input: String): FlutterElement {
return FlutterElement(mapOf(
"finderType" to "ByText",
"text" to input
))
return base64Encoded
}
Loading

0 comments on commit eae1817

Please sign in to comment.