Problem. Every field locator can write a value but none can read one. The
locators otherwise read as if they proxy the component, so getValue() is the
first thing you reach for, and it doesn't compile.
Surveyed in browserless-test-shared:1.1.1:
| Locator |
setValue |
clear |
value getter |
TextFieldLocator |
✅ |
✅ |
❌ |
TextAreaLocator |
✅ |
❌ |
❌ |
BigDecimalFieldLocator |
✅ |
✅ |
❌ |
NumberFieldLocator |
✅ |
❌ |
❌ |
IntegerFieldLocator |
✅ |
❌ |
❌ |
EmailFieldLocator / PasswordFieldLocator |
✅ |
✅ |
❌ |
DatePickerLocator / DateTimePickerLocator / TimePickerLocator |
✅ |
❌ |
❌ |
ComboBoxLocator / SelectLocator |
❌ (selectItem) |
❌ |
getSelected() |
CheckboxLocator |
❌ (click) |
❌ |
❌ |
So a test that asserts "this field defaults to 1" has to leave the locator API:
// Wanted
assertThat(findBigDecimalField().withLabel("Quantity").getValue())
.isEqualByComparingTo("1");
// Actual
assertThat(findBigDecimalField().withLabel("Quantity").getComponent().getValue())
.isEqualByComparingTo("1");
Why it's cheap to fix. HasValueFilter<C extends Component & HasValue<?, V>, V, SELF>
already binds both the component type and the value type — it exists to power
withValue(V). A default accessor on that interface (or a sibling
HasValueAccess) gives every value locator a typed, correct getter with no
per-locator work:
default V getValue() { return ((Locator<C, SELF>) this).component().getValue(); }
Ask. Add getValue() to the value-bearing locators (ideally as one default
method on the existing filter/accessor interface). Keep getSelected() on
ComboBoxLocator/SelectLocator as an alias if the selection vocabulary is
deliberate, but make getValue() work everywhere setValue/withValue does.
Copied from https://github.com/vaadin/agentic-dx-improvement/issues/107
Problem. Every field locator can write a value but none can read one. The
locators otherwise read as if they proxy the component, so
getValue()is thefirst thing you reach for, and it doesn't compile.
Surveyed in
browserless-test-shared:1.1.1:setValueclearTextFieldLocatorTextAreaLocatorBigDecimalFieldLocatorNumberFieldLocatorIntegerFieldLocatorEmailFieldLocator/PasswordFieldLocatorDatePickerLocator/DateTimePickerLocator/TimePickerLocatorComboBoxLocator/SelectLocatorselectItem)getSelected()CheckboxLocatorclick)So a test that asserts "this field defaults to 1" has to leave the locator API:
Why it's cheap to fix.
HasValueFilter<C extends Component & HasValue<?, V>, V, SELF>already binds both the component type and the value type — it exists to power
withValue(V). A default accessor on that interface (or a siblingHasValueAccess) gives every value locator a typed, correct getter with noper-locator work:
Ask. Add
getValue()to the value-bearing locators (ideally as one defaultmethod on the existing filter/accessor interface). Keep
getSelected()onComboBoxLocator/SelectLocatoras an alias if the selection vocabulary isdeliberate, but make
getValue()work everywheresetValue/withValuedoes.Copied from https://github.com/vaadin/agentic-dx-improvement/issues/107