Skip to main content

Select

Instructs an actor who has the ability to BrowseTheWeb to select an option from a HTML <select> element, either by its display name, or by value.

Learn more

Index

Constructors

constructor

Methods

staticvalue

  • value(value: Answerable<string>): { from: (pageElement: Answerable<PageElement<any>>) => Interaction }
  • Instantiates an interaction that instructs the actor to select a single <option> with a given value.,

    Example widget

    <select data-test='countries'>
    <option value='UK'>United Kingdom</option>
    <option value='PL'>Poland</option>
    <option value='US'>United States</option>
    </select>

    Lean Page Object describing the widget

    import { By, PageElement } from '@serenity-js/web'

    class Countries {
    static dropdown = () =>
    PageElement.located(By.css('[data-test="countries"]'))
    .describedAs('countries dropdown')
    }

    Retrieving the selected value

    import { actorCalled } from '@serenity-js/core'
    import { Select, Selected } from '@serenity-js/web';
    import { Ensure, equals } from '@serenity-js/assertions'

    await actorCalled('Nick')
    .attemptsTo(
    Select.value('UK').from(Countries.dropdown()),
    Ensure.that(Selected.valueOf(Countries.dropdown()), equals('UK')),
    )

    Learn more


    Parameters

    Returns { from: (pageElement: Answerable<PageElement<any>>) => Interaction }

    • from: (pageElement: Answerable<PageElement<any>>) => Interaction
        • (pageElement: Answerable<PageElement<any>>): Interaction
        • Parameters

          Returns Interaction

staticvalues

  • values(...values: Answerable<string | string[]>[]): { from: (pageElement: Answerable<PageElement<any>>) => Interaction }
  • Instantiates an interaction that instructs the actor to select multiple <option> elements identified by their values.

    Example widget

    <select multiple data-test='countries'>
    <option value='UK'>United Kingdom</option>
    <option value='PL'>Poland</option>
    <option value='US'>United States</option>
    </select>

    Lean Page Object describing the widget

    import { By, PageElement } from '@serenity-js/web'

    class Countries {
    static dropdown = () =>
    PageElement.located(By.css('[data-test="countries"]'))
    .describedAs('countries dropdown')
    }

    Retrieving the selected value

    import { actorCalled } from '@serenity-js/core'
    import { Select, Selected } from '@serenity-js/web'
    import { Ensure, equals } from '@serenity-js/assertions'

    await actorCalled('Nick')
    .attemptsTo(
    Select.values('UK').from(Countries.dropdown()),
    Ensure.that(Selected.valuesOf(Countries.dropdown()), equals([ 'UK' ])),
    )

    Learn more


    Parameters

    Returns { from: (pageElement: Answerable<PageElement<any>>) => Interaction }

    • from: (pageElement: Answerable<PageElement<any>>) => Interaction
        • (pageElement: Answerable<PageElement<any>>): Interaction
        • Parameters

          Returns Interaction

staticoption

  • option(value: Answerable<string>): { from: (pageElement: Answerable<PageElement<any>>) => Interaction }
  • Instantiates an interaction that instructs the actor to select a single <option> with a given description.

    Example widget

    <select data-test='countries'>
    <option value='UK'>United Kingdom</option>
    <option value='PL'>Poland</option>
    <option value='US'>United States</option>
    </select>

    Lean Page Object describing the widget

    import { By, PageElement } from '@serenity-js/by'

    class Countries {
    static dropdown = () =>
    PageElement.located(By.css('[data-test="countries"]'))
    .describedAs('countries dropdown')
    }

    Retrieving the selected value

    import { actorCalled } from '@serenity-js/core'
    import { Select, Selected } from '@serenity-js/web'
    import { Ensure, equals } from '@serenity-js/assertions'

    await actorCalled('Nick')
    .whoCan(BrowseTheWeb.using(protractor.browser))
    .attemptsTo(
    Select.option('Poland').from(Countries.dropdown()),
    Ensure.that(
    Selected.optionIn(Countries.dropdown()),
    equals('Poland')
    ),
    )

    Learn more


    Parameters

    Returns { from: (pageElement: Answerable<PageElement<any>>) => Interaction }

    • from: (pageElement: Answerable<PageElement<any>>) => Interaction
        • (pageElement: Answerable<PageElement<any>>): Interaction
        • Parameters

          Returns Interaction

staticoptions

  • options(...values: Answerable<string | string[]>[]): { from: (pageElement: Answerable<PageElement<any>>) => Interaction }
  • Instantiates an interaction that instructs the actor to select multiple <option> elements identified by their descriptions.

    Example widget

    <select multiple data-test='countries'>
    <option value='UK'>United Kingdom</option>
    <option value='PL'>Poland</option>
    <option value='US'>United States</option>
    </select>

    Lean Page Object describing the widget

    import { By, PageElement } from '@serenity-js/web'

    class Countries {
    static dropdown = () =>
    PageElement.located(By.css('[data-test="countries"]'))
    .describedAs('countries dropdown')
    }
    Retrieving the selected value
    import { actorCalled } from '@serenity-js/core'
    import { Select, Selected } from '@serenity-js/web'
    import { Ensure, equals } from '@serenity-js/assertions'

    await actorCalled('Nick')
    .whoCan(BrowseTheWeb.using(protractor.browser))
    .attemptsTo(
    Select.options('Poland', 'United States').from(Countries.dropdown()),
    Ensure.that(
    Selected.optionsIn(Countries.dropdown()),
    equals([ 'Poland', 'United States' ])
    ),
    )

    Learn more


    Parameters

    Returns { from: (pageElement: Answerable<PageElement<any>>) => Interaction }

    • from: (pageElement: Answerable<PageElement<any>>) => Interaction
        • (pageElement: Answerable<PageElement<any>>): Interaction
        • Parameters

          Returns Interaction