I am trying to automate flutter app using java and flutter finder but I am getting unknown locator for each and every flutter element. Here I am attaching java code. Please let me know what is the problem here.
public class FlutterAutomation {
private static AndroidDriver driver;
private static final String appPath = "C:\Users\NMAHESHBABU\flutterlogin-debug.apk";
private final String deviceName = "Pixel 3 API 29";
private final String testName = "Flutter Automation";
@BeforeTest
public void setUp() throws MalformedURLException {
DesiredCapabilities flutterCapabilities = new DesiredCapabilities();
flutterCapabilities.setCapability("deviceName", deviceName);
flutterCapabilities.setCapability("platformName", "Android");
flutterCapabilities.setCapability("automationName", "flutter");
flutterCapabilities.setCapability("app", appPath);
flutterCapabilities.setCapability("noReset", true);
flutterCapabilities.setCapability("testName", testName);
driver = new AndroidDriver(new URL("https://127.0.0.1:4723/wd/hub"), flutterCapabilities);
System.out.println("Created AppiumDriver");
}
@Test
public void checkLoginFunction() throws Exception {
FlutterFinder find = new FlutterFinder(driver);
Thread.sleep(3000);
FlutterElement txt_username = find.byValueKey("txt_username"); // this is valid locator
FlutterElement txt_password = find.byValueKey("txt_pass"); // this is not a valid locator actual locator is txt_password
FlutterElement btn_click = find.byValueKey("button_login");// this is valid locator
System.out.println(txt_username);
System.out.println(txt_password);
txt_username.sendKeys("[email protected]");
txt_password.sendKeys("user123");
btn_click.click();
}
@AfterTest
public void tearDown() {
if (driver != null) {
driver.quit();
}
}
}
Output:
[RemoteTestNG] detected TestNG version 7.4.0
SLF4J: No SLF4J providers were found.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See https://www.slf4j.org/codes.html#noProviders for further details.
Created AppiumDriver
[io.github.ashwith.flutter.FlutterElement@6cfedde -> unknown locator]
[io.github.ashwith.flutter.FlutterElement@8343364 -> unknown locator]
FAILED: checkLoginFunction
org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
Build info: version: ‘4.13.0’, revision: ‘ba948ece5b*’
System info: os.name: ‘Windows 11’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘17.0.2’
Driver info: io.appium.java_client.android.AndroidDriver
Command: [f457e47b-31f2-4c5c-af08-1f94839dbe02, sendKeysToElement [id, value]]
Capabilities {appium:address: 127.0.0.1, appium:allowCors: false, appium:allowInsecure: [], appium:androidCoverage: false, appium:app: C:UsersNMAHESHBABUflutte…, appium:appWaitActivity: false, appium:appWaitPackage: false, appium:automationName: flutter, appium:backendRetries: 3, appium:basePath: /wd/hub, appium:bootstrapPort: 4724, appium:debugLogSpacing: false, appium:defaultCapabilities: {}, appium:defaultCommandTimeout: 60, appium:defaultDevice: false, appium:denyInsecure: [], appium:deviceName: Pixel 3 API 29, appium:deviceReadyTimeout: 5, appium:dontStopAppOnReset: false, appium:enforceStrictCaps: false, appium:fastReset: false, appium:forceIpad: false, appium:forceIphone: false, appium:fullReset: false, appium:intentAction: android.intent.action.MAIN, appium:intentCategory: android.intent.category.LAU…, appium:intentFlags: 0x10200000, appium:isolateSimDevice: false, appium:keepArtifacts: false, appium:keepKeyChains: false, appium:keyAlias: androiddebugkey, appium:keyPassword: android, appium:keystorePassword: android, appium:keystorePath: C:UsersNMAHESHBABU.andro…, appium:launch: false, appium:launchTimeout: 90000, appium:localTimezone: false, appium:localizableStringsDir: en.lproj, appium:logNoColors: false, appium:logTimestamp: false, appium:loglevel: debug, appium:longStacktrace: false, appium:nativeInstrumentsLib: false, appium:noPermsCheck: false, appium:noReset: true, appium:port: 4723, appium:reboot: false, appium:relaxedSecurityEnabled: true, appium:robotAddress: 0.0.0.0, appium:robotPort: -1, appium:safari: false, appium:sessionOverride: false, appium:shell: false, appium:showConfig: false, appium:showIOSLog: false, appium:skipUninstall: true, appium:suppressKillServer: false, appium:testName: Flutter Automation, appium:tmpDir: C:UsersNMAHES~1AppDataL…, appium:useKeystore: false, appium:wdaLocalPort: 8100, appium:webkitDebugProxyPort: 27753, platformName: ANDROID}
Element: [io.github.ashwith.flutter.FlutterElement@8343364 -> unknown locator]
Session ID: f457e47b-31f2-4c5c-af08-1f94839dbe02
txt_username is valid locator but i am getting unknown locator [io.github.ashwith.flutter.FlutterElement@6cfedde -> unknown locator]
for txt_password is not a valid locator but I am getting [io.github.ashwith.flutter.FlutterElement@8343364 -> unknown locator]
Pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.demo.test</groupId>
<artifactId>PracticeTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>PracticeTest</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>8.6.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.12.0</version>
</dependency>
<dependency>
<groupId>io.github.ashwithpoojary98</groupId>
<artifactId>appium_flutterfinder_java</artifactId>
<version>1.0.5</version>
</dependency>
</dependencies>
</project>