Skip to content

Commit

Permalink
Update readme on usage of attribute (#18)
Browse files Browse the repository at this point in the history
* add attribute

* updated readMe on using element attributes
  • Loading branch information
saikrishna321 authored Jun 26, 2024
1 parent 94c7b19 commit 8ad2d6c
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
61 changes: 61 additions & 0 deletions test/specs/test.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8ad2d6c

Please sign in to comment.