appium / appium-flutter-driver

Appium Flutter Driver is a test automation tool for Flutter apps on multiple platforms/OSes. Appium Flutter Driver is part of the Appium mobile test automation tool maintained by community
MIT License
452 stars 183 forks source link

flutter:scrollIntoView not working #511

Open MiglenaPavlova opened 1 year ago

MiglenaPavlova commented 1 year ago

Hello,

I am trying to scroll on a mobile flutter app, to a specific button, to be able to tap on it.
Using python 3.10, Appium v2.0.0-beta.71, flutter@1.15.0 
I am using the following code, where 'keyValueString' is the key of the button:
 self.driver.execute_script('flutter:scrollIntoView', { 'finderType': 'ByValueKey', 'keyValueString': key, 'alignment': 0.5, })

I receive this error: "error: Cannot read properties of undefined (reading 'alignment')") payload = ('{"value":{"error":"unknown error","message":"An unknown server-side error ' 'occurred while processing the command. Original error: Cannot read ' 'properties of undefined (reading \'alignment\')","stacktrace":"UnknownError: ' 'An unknown server-side error occurred while processing the command. Original ' "error: Cannot read properties of undefined (reading 'alignment')\n at " 'getResponseForW3CError '

and this is the log from Appium: HTTP] --> POST /session/68d2391d-37ab-4dfd-ab15-97d853eeb269/execute/sync [HTTP] {"script":"flutter:scrollIntoView","args":[{"finderType":"ByValueKey","keyValueString":"GuestWifi_settings_button_Copy_Password","alignment":0.5}]} [debug] [FlutterDriver@e821 (68d2391d)] Calling AppiumDriver.execute() with args: ["flutter:scrollIntoView",[{"finderType":"ByValueKey","keyValueString":"GuestWifi_settings_button_Copy_Password","alignment":0.5}],"68d2391d-37ab-4dfd-ab15-97d853eeb269"] [debug] [FlutterDriver] Executing Flutter driver command 'execute' [debug] [FlutterDriver@e821 (68d2391d)] Encountered internal error running command: TypeError: Cannot read properties of undefined (reading 'alignment') [debug] [FlutterDriver@e821 (68d2391d)] at scrollIntoView (/Users/devolo/.appium/node_modules/appium-flutter-driver/lib/commands/execute/scroll.ts:212:11) [debug] [FlutterDriver@e821 (68d2391d)] at FlutterDriver.execute (/Users/devolo/.appium/node_modules/appium-flutter-driver/lib/commands/execute.ts:60:28) [debug] [FlutterDriver@e821 (68d2391d)] at commandExecutor (/Users/devolo/node_modules/@appium/base-driver/lib/basedriver/driver.ts:107:18) [debug] [FlutterDriver@e821 (68d2391d)] at /Users/devolo/node_modules/async-lock/lib/index.js:171:12 [debug] [FlutterDriver@e821 (68d2391d)] at AsyncLock._promiseTry (/Users/devolo/node_modules/async-lock/lib/index.js:304:31) [debug] [FlutterDriver@e821 (68d2391d)] at exec (/Users/devolo/node_modules/async-lock/lib/index.js:170:9) [debug] [FlutterDriver@e821 (68d2391d)] at AsyncLock.acquire (/Users/devolo/node_modules/async-lock/lib/index.js:187:3) [debug] [FlutterDriver@e821 (68d2391d)] at FlutterDriver.executeCommand (/Users/devolo/node_modules/@appium/base-driver/lib/basedriver/driver.ts:123:39) [debug] [FlutterDriver@e821 (68d2391d)] at runMicrotasks () [debug] [FlutterDriver@e821 (68d2391d)] at processTicksAndRejections (node:internal/process/task_queues:96:5) [debug] [FlutterDriver@e821 (68d2391d)] at FlutterDriver.executeCommand (/Users/devolo/.appium/node_modules/appium-flutter-driver/lib/driver.ts:167:16) [debug] [FlutterDriver@e821 (68d2391d)] at defaultBehavior (/usr/local/lib/node_modules/appium/lib/appium.js:684:14) [debug] [FlutterDriver@e821 (68d2391d)] at AppiumDriver.executeWrappedCommand (/usr/local/lib/node_modules/appium/lib/appium.js:774:16) [debug] [FlutterDriver@e821 (68d2391d)] at AppiumDriver.executeCommand (/usr/local/lib/node_modules/appium/lib/appium.js:696:17) [debug] [FlutterDriver@e821 (68d2391d)] at asyncHandler (/usr/local/lib/node_modules/appium/node_modules/@appium/base-driver/lib/protocol/protocol.js:393:19) [HTTP] <-- POST /session/68d2391d-37ab-4dfd-ab15-97d853eeb269/execute/sync 500 3 ms - 614 [HTTP]

thuonglai commented 1 year ago

I don't using python but I think it must {'alignment': 0.5}

MiglenaPavlova commented 1 year ago

Yes, it should be without the comma. But still, the error I receive is the same.

KazuCocoa commented 1 year ago

Could below work?

button_finder = finder.by_value_key("GuestWifi_settings_button_Copy_Password")
self.driver.execute_script('flutter:scrollIntoView',  button_finder, {'alignment': 0.5 })
MustafaAgamy commented 6 months ago

@KazuCocoa I tried the following codes in Java it doesn't seem to work if the element is not in the current view of the screen at all

Code 1

Map<String, Object> params = new HashMap<>(); params.put("alignment", 0.5);

driver.executeScript("flutter:scrollIntoView", this.finder.byValueKey("item_12") , params);

End of Code 1

And this code too

Code 2

driver.executeScript("flutter:scroll", this.finder.byValueKey("item_12"), new HashMap<String, Object>() {{ put("dx", 90); put("dy", -400); put("durationMilliseconds", 300); put("frequency", 30); }});

End of Code 2

balakumaran-deriv commented 5 months ago

In Java, below works for me

WebElement scrollToElement = finder.byText(elementTextValue);

Map<String, Object> scrollParams = new HashMap<>();
scrollParams.put("item", scrollToElement);
scrollParams.put("dxScroll", 0); // Horizontal offset
scrollParams.put("dyScroll", -400); // Vertical offset
scrollParams.put("waitTimeoutMilliseconds", 10000); // Timeout (10 seconds)

driver.executeScript("flutter:scrollUntilVisible", finder.byType("ListView"), scrollParams);