appium-flutter-driver icon indicating copy to clipboard operation
appium-flutter-driver copied to clipboard

Appium hangs when finder is not working.

Open hex0cter opened this issue 4 years ago • 1 comments

During the tests I have found the Appium request stalls when a command is not working. For instance, I would like to add the following code in https://github.com/truongsinh/appium-flutter-driver/blob/master/example/python/example.py.

counter_finder = FlutterFinder().by_semantics_label("counter_semantic")
counter_element = FlutterElement(driver, counter_finder)
print(counter_element.text)

However the code stops at the last line. Here is the log of Appium:

2021-03-20 13:56:43:570 - [HTTP]
2021-03-20 13:56:43:571 - [HTTP] --> GET /wd/hub/session/971ef296-5825-44d1-a6d7-97e9f1c397f2/element/eyJmaW5kZXJUeXBlIjogIkJ5U2VtYW50aWNzTGFiZWwiLCAiaXNSZWdFeHAiOiBmYWxzZSwgImxhYmVsIjogImNvdW50ZXJfc2VtYW50aWMifQ==/text
2021-03-20 13:56:43:572 - [HTTP] {}
2021-03-20 13:56:43:572 - [debug] [MJSONWP (971ef296)] Calling AppiumDriver.getText() with args: ["eyJmaW5kZXJUeXBlIjogIkJ5U2VtYW50aWNzTGFiZWwiLCAiaXNSZWdFeHAiOiBmYWxzZSwgImxhYmVsIjogImNvdW50ZXJfc2VtYW50aWMifQ==","971ef296-5825-44d1-a6d7-97e9f1c397f2"]
2021-03-20 13:56:43:572 - [debug] [FlutterDriver] Executing Flutter driver command 'getText'

then nothing happens forever.

So I have two questions here:

  1. Did I do anything wrong with the code. I got the label counter_semantic from https://github.com/truongsinh/appium-flutter-driver/blob/master/example/flutter_app_under_test/lib/main.dart#L43 but let me know if I did something stupid.
  2. Even if something is wrong with the test code, why is the code hanging instead of returning an error?

Any help will be appreciated.

hex0cter avatar Mar 20 '21 13:03 hex0cter

Hi, @hex0cter! Don't know if it's still an issue, but what we did to work around this issue was to call flutter:waitFor and pass in the finder as a parameter, before we initialized the Flutter element itself. Because it raises an exception if the finder is not found in the given time it worked quite well in our case. Not a python user so can't give you the exact example, but in ruby, we did something similar to this: defined a method that checks if a finder exists

  def displayed?(finder, wait)
    @driver.driver.execute_script('flutter:waitFor', finder, wait)
    true
  rescue Selenium::WebDriver::Error::UnknownError
    false
  end

Then created a method that returns the element or raises an exception, similar to this:

  def element(finder, wait)
    raise Selenium::WebDriver::Error::NoSuchElementError, 'Element not found' unless displayed?(finder, wait)

    ::Appium::Flutter::Element.new(@driver.driver, finder: finder)
  end

Although the example is in ruby, I think the general approach can be used in python as well.

karlisV avatar Apr 29 '21 15:04 karlisV