Skip to content

Agent DX improvement: Value-bearing locators are write-only — no getValue() anywhere #152

Description

@peholmst

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions