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

Selected

Represents options and values selected in a HTML <select> element.

See also:

Static Method Summary

Static Public Methods
public static

optionIn(target: Question<ElementFinder> | ElementFinder): Question<Promise<string>>

Represents a single option selected in a HTML <select> element

public static

optionsIn(target: Question<ElementFinder> | ElementFinder): Question<Promise<string[]>>

Represents options selected in a HTML <select multiple> element

public static

valueOf(target: Question<ElementFinder> | ElementFinder): Question<Promise<string>>

Represents the value of a single option selected in a HTML <select> element.

public static

valuesOf(target: Question<ElementFinder> | ElementFinder): Question<Promise<string[]>>

Represents values of options selected in a HTML <select multiple> element

Static Public Methods

public static optionIn(target: Question<ElementFinder> | ElementFinder): Question<Promise<string>> source

Represents a single option selected in a HTML <select> element

Params:

NameTypeAttributeDescription
target Question<ElementFinder> | ElementFinder

A Target identifying the <select> element of interest

Returns:

Question<Promise<string>>

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
 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 { Accept, 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 optionsIn(target: Question<ElementFinder> | ElementFinder): Question<Promise<string[]>> source

Represents options selected in a HTML <select multiple> element

Params:

NameTypeAttributeDescription
target Question<ElementFinder> | ElementFinder

A Target identifying the <select> element of interest

Returns:

Question<Promise<string[]>>

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
 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 { Accept, 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 valueOf(target: Question<ElementFinder> | ElementFinder): Question<Promise<string>> source

Represents the value of a single option selected in a HTML <select> element.

Params:

NameTypeAttributeDescription
target Question<ElementFinder> | ElementFinder

A Target identifying the <select> element of interest

Returns:

Question<Promise<string>>

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
 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 { Accept, 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 valuesOf(target: Question<ElementFinder> | ElementFinder): Question<Promise<string[]>> source

Represents values of options selected in a HTML <select multiple> element

Params:

NameTypeAttributeDescription
target Question<ElementFinder> | ElementFinder

A Target identifying the <select> element of interest

Returns:

Question<Promise<string[]>>

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