import {Select} from '@serenity-js/protractor/lib/screenplay/interactions'
public class | source

Select

Instructs the Actor to select an option from a HTML <select> element, either by its display name, or by value.

Tests:

See also:

Static Method Summary

Static Public Methods
public static

option(value: string | Answerable<string>): SelectBuilder

Instantiates this Interaction with a single option for the Actor to select.

public static

options(values: Array<Answerable<string[]|string>>): SelectBuilder

Instantiates this Interaction with options for the Actor to select.

public static

value(value: string | Answerable<string>): SelectBuilder

Instantiates this Interaction with a value of a single <option> for the Actor to select.

public static

values(values: Array<Answerable<string[]|string>>): SelectBuilder

Instantiates this Interaction with values of multiple <option> elements for the Actor to select.

Static Public Methods

public static option(value: string | Answerable<string>): SelectBuilder source

Instantiates this Interaction with a single option for the Actor to select.

Params:

NameTypeAttributeDescription
value string | Answerable<string>

Text of the option element for the Actor to select

Returns:

SelectBuilder

Examples:

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 { Target } from '@serenity-js/protractor';
 import { browser, by } from 'protractor';

 class Countries {
     static dropdown = Target.the('countries dropdown')
         .located(by.css('[data-test="countries"]'));
 }
Retrieving the selected value
 import { actorCalled } from '@serenity-js/core';
 import { BrowseTheWeb, Select, Selected } from '@serenity-js/protractor';
 import { Ensure, equals } from '@serenity-js/assertions';
 import { protractor } from 'protractor';

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

public static options(values: Array<Answerable<string[]|string>>): SelectBuilder source

Instantiates this Interaction with options for the Actor to select.

Params:

NameTypeAttributeDescription
values Array<Answerable<string[]|string>>

Text of the option elements for the Actor to select

Returns:

SelectBuilder

Examples:

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 { Target } from '@serenity-js/protractor';
 import { browser, by } from 'protractor';

 class Countries {
     static dropdown = Target.the('countries dropdown')
         .located(by.css('[data-test="countries"]'));
 }
Retrieving the selected value
 import { actorCalled } from '@serenity-js/core';
 import { BrowseTheWeb, Select, Selected } from '@serenity-js/protractor';
 import { Ensure, equals } from '@serenity-js/assertions';
 import { protractor } from 'protractor';

 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' ])
         ),
     );

public static value(value: string | Answerable<string>): SelectBuilder source

Instantiates this Interaction with a value of a single <option> for the Actor to select.

Params:

NameTypeAttributeDescription
value string | Answerable<string>

A value of the option element for the Actor to select

Returns:

SelectBuilder

Examples:

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 { Target } from '@serenity-js/protractor';
 import { browser, by } from 'protractor';

 class Countries {
     static dropdown = Target.the('countries dropdown')
         .located(by.css('[data-test="countries"]'));
 }
Retrieving the selected value
 import { actorCalled } from '@serenity-js/core';
 import { BrowseTheWeb, Select, Selected } from '@serenity-js/protractor';
 import { Ensure, equals } from '@serenity-js/assertions';
 import { protractor } from 'protractor';

 actorCalled('Nick')
     .whoCan(BrowseTheWeb.using(protractor.browser))
     .attemptsTo(
         Select.value('UK').from(Countries.dropdown),
         Ensure.that(Selected.valueOf(Countries.dropdown), equals('UK')),
     );

public static values(values: Array<Answerable<string[]|string>>): SelectBuilder source

Instantiates this Interaction with values of multiple <option> elements for the Actor to select.

Params:

NameTypeAttributeDescription
values Array<Answerable<string[]|string>>

Values of the option elements for the Actor to select

Returns:

SelectBuilder

Examples:

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 { Target } from '@serenity-js/protractor';
 import { browser, by } from 'protractor';

 class Countries {
     static dropdown = Target.the('countries dropdown')
         .located(by.css('[data-test="countries"]'));
 }
Retrieving the selected value
 import { actorCalled } from '@serenity-js/core';
 import { BrowseTheWeb, Select, Selected } from '@serenity-js/protractor';
 import { Ensure, equals } from '@serenity-js/assertions';
 import { protractor } from 'protractor';

 actorCalled('Nick')
     .whoCan(BrowseTheWeb.using(protractor.browser))
     .attemptsTo(
         Select.values('UK').from(Countries.dropdown),
         Ensure.that(Selected.valuesOf(Countries.dropdown), equals([ 'UK' ])),
     );