Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flutter Finder Doesn't Raise Exception if Element Doesn't Exists #697

Closed
sonumuto opened this issue Jun 6, 2024 · 4 comments
Closed

Flutter Finder Doesn't Raise Exception if Element Doesn't Exists #697

sonumuto opened this issue Jun 6, 2024 · 4 comments

Comments

@sonumuto
Copy link

sonumuto commented Jun 6, 2024

Hi,
We are trying to automate a Flutter/Native Android application using Python. We have noticed that if element does not exist in the current page, it does not raise an exception which differs from the expected behavior of the find element. It seems like application is stuck in find element.


import unittest
import time
from typing import Dict, Any
 
from appium import webdriver
from appium.options.common import AppiumOptions
from appium.webdriver.common.appiumby import AppiumBy
from appium_flutter_finder import FlutterFinder, FlutterElement
 
cap: Dict[str, Any] = {
    'platformName': 'Android',
    'automationName': 'flutter',
    'uuid': '**********',
    'platformVersion': '13',
    'app': '/Users/test/Desktop/app-organization.apk',
}
appium_server_url = 'http://localhost:4723'
 
driver = webdriver.Remote(appium_server_url, options=AppiumOptions().load_capabilities(cap))
 
###############Flutter##################################
#Change the context to FLUTTER
driver.switch_to.context("NATIVE_APP")
driver.switch_to.context("FLUTTER")
#Init Fluttter finder class
finder = FlutterFinder()
 
key_finder = finder.by_text('start')
button_element = FlutterElement(driver, key_finder)
print(button_element.text)
button_element.click()
 
key_finder = finder.by_text("Skip")
goto_next_route_element = FlutterElement(driver, key_finder)
goto_next_route_element.click()
###############Flutter##################################
###############Native##################################
driver.switch_to.context("NATIVE_APP")
#Wait async operation
time.sleep(2)
 
driver.find_element(by=AppiumBy.ID, value="com.organization.app:id/base_button").click()
driver.find_element(by=AppiumBy.ID, value="com.organization.app:id/et").send_keys('zzzzzzzzz')
driver.find_element(by=AppiumBy.ID, value="com.organization.app:id/btn_continue").click()
 
driver.switch_to.context("FLUTTER")
 
textfield_key_finder = finder.by_value_key("xNameTextFieldKey")
textfield_element = FlutterElement(driver, textfield_key_finder)
textfield_element.send_keys("Example Text")
time.sleep(3)
 
driver.implicitly_wait(20)
driver.find_element(by=AppiumBy.ID, value="com.organization.app:id/et_x").send_keys('[email protected]')
driver.find_element(by=AppiumBy.ID, value="com.organization.app:id/et_y").send_keys('53634643')
driver.find_element(by=AppiumBy.ID, value="com.organization.app:id/btn_z").click()
 
driver.find_element(by=AppiumBy.ID, value="com.organization.app:id/btn_a").click()
driver.implicitly_wait(20)
try:
    driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value="Show me").click()
except:
    driver.find_element(by=AppiumBy.ID, value="com.organization.app:id/btn_w").click()
 
try:
    driver.find_element(by=AppiumBy.ID, value="com.organization.app:id/btn_w").click()
except:
    pass
 
driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value="Settings").click()
 
driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value="settingsTextKey").click()
 
###############Native##################################
#Switch the context to FLUTTER
 
###############FLUTTER##################################
driver.switch_to.context("FLUTTER")
 
textfield_key_finder = finder.by_value_key("TextFieldKey")
textfield_element = FlutterElement(driver, textfield_key_finder)
textfield_element.send_keys("Example Text")
time.sleep(3)
 
textfield_element.clear()
 
pw_key_finder = finder.by_value_key("extFieldKey")
pw_element = FlutterElement(driver, pw_key_finder)
pw_element.send_keys("58475684")
 
 
time.sleep(10)
driver.quit()

@sonumuto
Copy link
Author

sonumuto commented Jun 9, 2024

Any ideas on possible root causes? @KazuCocoa

@KazuCocoa
Copy link
Member

I guess it is flutter_driver internal behavior. #693 could be a workaround.

@KazuCocoa
Copy link
Member

https://github.com/appium/appium-flutter-driver?tab=readme-ov-file#troubleshooting added the waitFor method as part of troubleshooting. The docs can be improved later of course.

@sonumuto
Copy link
Author

Thanks Kazu!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants