diff --git a/README.md b/README.md index a9496b0..85760c4 100644 --- a/README.md +++ b/README.md @@ -134,6 +134,29 @@ For more details, refer to the documentation for each driver: | appium:flutterSystemPort | The number of the port on the host machine used for the Flutter server. By default the first free port from 10000..11000 range is selected. It is recommended to set this value if you are running parallel tests on the same machine.| No | +## Element attributes + +The Flutter Integration Driver supports all the attributes that are returned by native flutter components. + +How does the driver fetch the attributes? + +The driver uses the flutter [diagnostic node](https://api.flutter.dev/flutter/foundation/DiagnosticsNode-class.html) to fetch the attributes and also [Semantic data](https://api.flutter.dev/flutter/semantics/SemanticsNode/getSemanticsData.html). We merged all the attributes from both the trees. + +For example: If you want to know all the attributes that are attached to an element from flutter, you can use the below command. + +```javascript + const allProps = await browser.flutterBySemanticsLabel$('switch_button'); + await allProps.getAttribute('all') +``` + +What is the way to check if the button, checkbox, toggle button state? + +```javascript + const prop3 = await browser.flutterByValueKey$('enabled_text_field'); + await prop3.getAttribute('flags'); +``` +Flutter has flags which basically returns the state of the element. https://api.flutter.dev/flutter/dart-ui/SemanticsFlag-class.html + ## Locating Elements You can use the following locators to find elements in your Flutter app. Custom finders are built for WDIO. Refer to the [wdio-flutter-by-service](https://www.npmjs.com/package/wdio-flutter-by-service?activeTab=readme). diff --git a/test/specs/test.e2e.js b/test/specs/test.e2e.js index c47c651..27b0cda 100644 --- a/test/specs/test.e2e.js +++ b/test/specs/test.e2e.js @@ -99,6 +99,67 @@ describe('My Login application', () => { expect(popUpText).toBe(true); }); + it('Properties Test', async () => { + await performLogin(); + await openScreen('UI Elements'); + const prop2 = await browser.flutterBySemanticsLabel$('disabled_text_field'); + const disableTextFieldState = await prop2.getAttribute('flags'); + expect(disableTextFieldState).toEqual('[isTextField, hasEnabledState, isReadOnly]'); + + const prop4 = await browser.flutterBySemanticsLabel$('switch_button'); + await prop4.getAttribute('flags') + expect(await prop4.getAttribute('flags')).toEqual('[hasEnabledState, isEnabled, hasToggledState, isFocusable]'); + await prop4.click(); + await prop4.getAttribute('flags'); + expect(await prop4.getAttribute('flags')).toEqual('[hasEnabledState, isEnabled, hasToggledState, isToggled, isFocusable]'); + const prop5 = await browser.flutterBySemanticsLabel$('switch_button'); + await prop5.getAttribute('all'); // Will return all attributes attached to the element + // { + // owner: 'SemanticsOwner#fd8a3', + // isMergedIntoParent: 'false', + // mergeAllDescendantsIntoThisNode: 'false', + // rect: 'Rect.fromLTRB(0.0, 0.0, 60.0, 48.0)', + // tags: 'null', + // actions: '[tap]', + // customActions: '[]', + // flags: '[hasEnabledState, isEnabled, hasToggledState, isToggled, isFocusable]', + // isInvisible: 'false', + // isHidden: 'false', + // identifier: 'null', + // label: 'switch_button', + // value: 'null', + // increasedValue: 'null', + // decreasedValue: 'null', + // hint: 'null', + // tooltip: 'null', + // textDirection: 'null', + // sortKey: 'null', + // platformViewId: 'null', + // maxValueLength: 'null', + // currentValueLength: 'null', + // scrollChildren: 'null', + // scrollIndex: 'null', + // scrollExtentMin: 'null', + // scrollPosition: 'null', + // scrollExtentMax: 'null', + // indexInParent: 'null', + // elevation: '0.0', + // thickness: '0.0', + // container: 'true', + // properties: 'SemanticsProperties(label: "switch_button")', + // checked: 'null', + // mixed: 'null', + // expanded: 'null', + // selected: 'null', + // attributedLabel: 'null', + // attributedValue: 'null', + // attributedIncreasedValue: 'null', + // attributedDecreasedValue: 'null', + // attributedHint: 'null', + // hintOverrides: 'null' + // } + }); + it.skip('Invalid Driver', async () => { await browser.flutterBySemanticsLabel$('username_text_field').clearValue(); await browser