toJson method
Implementation
Map<String, dynamic> toJson() {
final title = observerElementTitleForFields(
type: type,
label: label,
text: text,
testId: testId,
);
final locatorJson = suggestedLocator?.toJson();
final boundsJson = bounds?.toJson();
final actions = observerActionExamples(
actions: this.actions,
title: title,
id: testId,
locator: locatorJson,
bounds: boundsJson,
warning: locatorWarning,
value: text,
checked: state.checked,
options: options,
);
return {
'elementId': elementId,
if (testId != null &&
locatorWarning == null &&
(locatorJson == null || locatorJson['id'] != testId))
'testId': testId,
if (type != null) 'type': type,
if (role != null) 'role': role,
if (label != null) 'label': label,
if (text != null) 'text': text,
if (hint != null) 'hint': hint,
if (options.isNotEmpty) 'options': options,
if (suggestedLocator != null)
'suggestedLocator': suggestedLocator!.toJson(),
if (locatorWarning != null) 'locatorWarning': locatorWarning,
'state': state.toJson(),
if (bounds != null) 'bounds': bounds!.toJson(),
if (actions.isNotEmpty) 'actions': actions,
if (children.isNotEmpty)
'children': children.map((c) => c.toJson()).toList(),
if (metadata.isNotEmpty) 'metadata': metadata,
};
}