-
-
Notifications
You must be signed in to change notification settings - Fork 758
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for FlutterAndroidDriver (#2203)
- Loading branch information
1 parent
bb4ee2d
commit 7f28bfb
Showing
14 changed files
with
544 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
src/e2eFlutterTest/java/io/appium/java_client/android/BaseFlutterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package io.appium.java_client.android; | ||
|
||
import io.appium.java_client.AppiumBy; | ||
import io.appium.java_client.android.options.UiAutomator2Options; | ||
import io.appium.java_client.flutter.android.FlutterAndroidDriver; | ||
import io.appium.java_client.flutter.commands.ScrollParameter; | ||
import io.appium.java_client.remote.AutomationName; | ||
import io.appium.java_client.service.local.AppiumDriverLocalService; | ||
import io.appium.java_client.service.local.AppiumServiceBuilder; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.openqa.selenium.By; | ||
import org.openqa.selenium.InvalidArgumentException; | ||
import org.openqa.selenium.WebElement; | ||
|
||
import java.net.MalformedURLException; | ||
import java.util.Optional; | ||
|
||
class BaseFlutterTest { | ||
|
||
private static final boolean IS_ANDROID = Optional | ||
.ofNullable(System.getProperty("platform")) | ||
.orElse("android") | ||
.equalsIgnoreCase("android"); | ||
private static final String APP_ID = IS_ANDROID | ||
? "com.example.appium_testing_app" : "com.example.appiumTestingApp"; | ||
protected static final int PORT = 4723; | ||
|
||
private static AppiumDriverLocalService service; | ||
protected static FlutterAndroidDriver driver; | ||
protected static final By LOGIN_BUTTON = AppiumBy.flutterText("Login"); | ||
|
||
/** | ||
* initialization. | ||
*/ | ||
@BeforeAll | ||
public static void beforeClass() { | ||
service = new AppiumServiceBuilder() | ||
.withIPAddress("127.0.0.1") | ||
.usingPort(PORT) | ||
.build(); | ||
service.start(); | ||
} | ||
|
||
@BeforeEach | ||
public void startSession() throws MalformedURLException { | ||
if (IS_ANDROID) { | ||
// TODO: update it with FlutterDriverOptions once implemented | ||
UiAutomator2Options options = new UiAutomator2Options() | ||
.setAutomationName(AutomationName.FLUTTER_INTEGRATION) | ||
.setApp(System.getProperty("flutterApp")) | ||
.eventTimings(); | ||
driver = new FlutterAndroidDriver(service.getUrl(), options); | ||
} else { | ||
throw new InvalidArgumentException( | ||
"Currently flutter driver implementation only supports android platform"); | ||
} | ||
} | ||
|
||
@AfterEach | ||
public void stopSession() { | ||
if (driver != null) { | ||
driver.quit(); | ||
} | ||
} | ||
|
||
@AfterAll | ||
public static void afterClass() { | ||
if (service.isRunning()) { | ||
service.stop(); | ||
} | ||
} | ||
|
||
public void openScreen(String screenTitle) { | ||
ScrollParameter scrollOptions = new ScrollParameter( | ||
AppiumBy.flutterText(screenTitle), ScrollParameter.ScrollDirection.DOWN); | ||
WebElement element = driver.scrollTillVisible(scrollOptions); | ||
element.click(); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
src/e2eFlutterTest/java/io/appium/java_client/android/CommandTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package io.appium.java_client.android; | ||
|
||
import io.appium.java_client.AppiumBy; | ||
import io.appium.java_client.flutter.commands.ScrollParameter; | ||
import io.appium.java_client.flutter.commands.WaitParameter; | ||
import org.junit.jupiter.api.Test; | ||
import org.openqa.selenium.WebElement; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
class CommandTest extends BaseFlutterTest { | ||
|
||
private static final AppiumBy.FlutterBy MESSAGE_FIELD = AppiumBy.flutterKey("message_field"); | ||
private static final AppiumBy.FlutterBy TOGGLE_BUTTON = AppiumBy.flutterKey("toggle_button"); | ||
|
||
@Test | ||
public void testWaitCommand() { | ||
WebElement loginButton = driver.findElement(BaseFlutterTest.LOGIN_BUTTON); | ||
loginButton.click(); | ||
openScreen("Lazy Loading"); | ||
|
||
WebElement messageField = driver.findElement(MESSAGE_FIELD); | ||
WebElement toggleButton = driver.findElement(TOGGLE_BUTTON); | ||
|
||
assertEquals(messageField.getText(), "Hello world"); | ||
toggleButton.click(); | ||
assertEquals(messageField.getText(), "Hello world"); | ||
|
||
WaitParameter waitParameter = new WaitParameter().setLocator(MESSAGE_FIELD); | ||
|
||
driver.waitForInVisible(waitParameter); | ||
assertEquals(0, driver.findElements(MESSAGE_FIELD).size()); | ||
toggleButton.click(); | ||
driver.waitForVisible(waitParameter); | ||
assertEquals(1, driver.findElements(MESSAGE_FIELD).size()); | ||
assertEquals(messageField.getText(), "Hello world"); | ||
} | ||
|
||
@Test | ||
public void testScrollTillVisibleCommand() { | ||
WebElement loginButton = driver.findElement(BaseFlutterTest.LOGIN_BUTTON); | ||
loginButton.click(); | ||
openScreen("Vertical Swiping"); | ||
|
||
WebElement firstElement = driver.scrollTillVisible(new ScrollParameter(AppiumBy.flutterText("Java"))); | ||
assertTrue(Boolean.parseBoolean(firstElement.getAttribute("displayed"))); | ||
|
||
WebElement lastElement = driver.scrollTillVisible(new ScrollParameter(AppiumBy.flutterText("Protractor"))); | ||
assertTrue(Boolean.parseBoolean(lastElement.getAttribute("displayed"))); | ||
assertFalse(Boolean.parseBoolean(firstElement.getAttribute("displayed"))); | ||
|
||
firstElement = driver.scrollTillVisible( | ||
new ScrollParameter(AppiumBy.flutterText("Java"), | ||
ScrollParameter.ScrollDirection.UP) | ||
); | ||
assertTrue(Boolean.parseBoolean(firstElement.getAttribute("displayed"))); | ||
assertFalse(Boolean.parseBoolean(lastElement.getAttribute("displayed"))); | ||
} | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
src/e2eFlutterTest/java/io/appium/java_client/android/FinderTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package io.appium.java_client.android; | ||
|
||
import io.appium.java_client.AppiumBy; | ||
import org.junit.jupiter.api.Test; | ||
import org.openqa.selenium.WebElement; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
|
||
class FinderTests extends BaseFlutterTest { | ||
|
||
@Test | ||
public void testFlutterByKey() { | ||
WebElement userNameField = driver.findElement(AppiumBy.flutterKey("username_text_field")); | ||
assertEquals("admin", userNameField.getText()); | ||
userNameField.clear(); | ||
driver.findElement(AppiumBy.flutterKey("username_text_field")).sendKeys("admin123"); | ||
assertEquals("admin123", userNameField.getText()); | ||
} | ||
|
||
@Test | ||
public void testFlutterByType() { | ||
WebElement loginButton = driver.findElement(AppiumBy.flutterType("ElevatedButton")); | ||
assertEquals(loginButton.findElement(AppiumBy.flutterType("Text")).getText(), "Login"); | ||
} | ||
|
||
@Test | ||
public void testFlutterText() { | ||
WebElement loginButton = driver.findElement(AppiumBy.flutterText("Login")); | ||
assertEquals(loginButton.getText(), "Login"); | ||
loginButton.click(); | ||
|
||
assertEquals(1, driver.findElements(AppiumBy.flutterText("Slider")).size()); | ||
} | ||
|
||
@Test | ||
public void testFlutterTextContaining() { | ||
WebElement loginButton = driver.findElement(BaseFlutterTest.LOGIN_BUTTON); | ||
loginButton.click(); | ||
assertEquals(driver.findElement(AppiumBy.flutterTextContaining("Vertical")).getText(), | ||
"Vertical Swiping"); | ||
} | ||
|
||
@Test | ||
public void testFlutterSemanticsLabel() { | ||
WebElement loginButton = driver.findElement(BaseFlutterTest.LOGIN_BUTTON); | ||
loginButton.click(); | ||
openScreen("Lazy Loading"); | ||
|
||
WebElement messageField = driver.findElement(AppiumBy.flutterSemanticsLabel("message_field")); | ||
assertEquals(messageField.getText(), | ||
"Hello world"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.