UiElement.fromJson constructor
UiElement.fromJson(
- Map<String, dynamic> json
)
Implementation
factory UiElement.fromJson(Map<String, dynamic> json) {
final stateRaw = json['state'];
final boundsRaw = json['bounds'];
final childrenRaw = json['children'];
final actionsRaw = json['actions'];
final optionsRaw = json['options'];
final locatorRaw = json['suggestedLocator'];
return UiElement(
// Snapshot identity is issued by the observation registry. A locator
// describes how to find an element and must never populate this field.
elementId: json['elementId']?.toString() ?? '',
testId: json['testId']?.toString() ??
(locatorRaw is Map ? locatorRaw['id']?.toString() : null),
type: json['type']?.toString(),
role: json['role']?.toString(),
label: json['label']?.toString(),
text: json['text']?.toString(),
hint: json['hint']?.toString(),
options: optionsRaw is List
? optionsRaw.map((e) => e.toString()).toList()
: const [],
suggestedLocator: locatorRaw is Map
? ElementLocator.fromJson(Map<String, dynamic>.from(locatorRaw))
: null,
locatorWarning: json['locatorWarning']?.toString(),
state: stateRaw is Map
? UiElementState.fromJson(Map<String, dynamic>.from(stateRaw))
: const UiElementState(),
bounds: boundsRaw is Map
? UiBounds.fromJson(Map<String, dynamic>.from(boundsRaw))
: null,
actions: actionsRaw is List
? actionsRaw
.map((action) => _actionNameFromExample(action))
.whereType<String>()
.toList()
: const [],
children: childrenRaw is List
? childrenRaw
.whereType<Map>()
.map((e) => UiElement.fromJson(Map<String, dynamic>.from(e)))
.toList()
: const [],
metadata: json['metadata'] is Map
? Map<String, Object?>.from(json['metadata'] as Map)
: const {},
);
}