Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat - add support for SelectedOption, SelectedOptions, SelectedText and SelectedTextItems #373

Merged
merged 1 commit into from
Aug 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 160 additions & 0 deletions packages/protractor/spec/screenplay/questions/SelectedOption.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
import 'mocha';
import { Ensure, equals } from '@serenity-js/assertions';
import { by } from 'protractor';
import { Navigate, Select, SelectedOption, SelectedOptions, Target, Text } from '../../../src';
import { pageFromTemplate } from '../../fixtures';
import { UIActors } from '../../UIActors';
import { actorCalled, engage } from '@serenity-js/core';

describe('SelectedOption', () => {

beforeEach(() => engage(new UIActors()));

class SingleCountry {
static Selector = Target.the('country selector').located(by.id('single-option'));
}

/** @test {SelectedOption} */
const pageWithSingleSelect = `
<html>
<body>
<form>
<fieldset name='options'>
<legend>Working with single option</legend>
<label for='single-option'>
Country
<select id='single-option'>
<option label='United Kingdom' value='GB' selected='selected'>United Kingdom</option>
<option label='Poland' value='PL' selected='selected'>Poland</option>
<option label='Germany' value='DE' selected='selected'>Germany</option>
<option label='France' value='FR'>France</option>
</select>
</label>
</fieldset>
</form>
</body>
</html>`;
/** @test {SelectedOption.of} */
it('should return a single value when a single text argument is passed to Select.option()', () =>
actorCalled('Nick').attemptsTo(
Navigate.to(pageFromTemplate(pageWithSingleSelect)),
Select.option('FR').from(SingleCountry.Selector),
Ensure.that(SelectedOption.of(SingleCountry.Selector), equals('FR'))));
});

describe('SelectedOption', () => {

beforeEach(() => engage(new UIActors()));

class SingleCountry {
static Selector = Target.the('country selector').located(by.id('single-option'));
}

class TextInput {
static Selector = Target.the('country text').located(by.id('country-text'));
}

/** @test {SelectedOption} */
const pageWithSingleSelect = `
<html>
<body>
<input>
<p id='country-text'>PL</p>
<fieldset name='options'>
<legend>Working with single option</legend>
<label for='single-option'>
Country
<select id='single-option'>
<option label='United Kingdom' value='GB' selected='selected'>United Kingdom</option>
<option label='Poland' value='PL' selected='selected'>Poland</option>
<option label='Germany' value='DE' selected='selected'>Germany</option>
<option label='France' value='FR'>France</option>
</select>
</label>
</fieldset>
</form>
</body>
</html>`;
/** @test {SelectedOption.of} */
it('should return a single value when a single answerable argument is passed to Select.option()', () =>
actorCalled('Nick').attemptsTo(
Navigate.to(pageFromTemplate(pageWithSingleSelect)),
Select.option(Text.of(TextInput.Selector)).from(SingleCountry.Selector),
Ensure.that(SelectedOption.of(SingleCountry.Selector), equals('PL'))));
});

describe('SelectedOptions', () => {
class MultiCountry {
static Selector = Target.the('country selector').located(by.id('multiple-options'));
}

/** @test {SelectedOptions} */
const pageWithMultipleSelects = `
<html>
<body>
<form>
<fieldset name='options'>
<legend>Working with options</legend>
<label for='multiple-options'>
Country
<select multiple='' id='multiple-options'>
<option label='United Kingdom' value='GB'>United Kingdom</option>
<option label='Poland' value='PL'>Poland</option>
<option label='Germany' value='DE'>Germany</option>
<option label='France' value='FR'>France</option>
</select>
</label>
</fieldset>
</form>
</body>
</html>`;
/** @test {SelectedOptions.of} */
it('should return a multiple values when multiple text arguments are passed to Select', () =>
actorCalled('Nick').attemptsTo(
Navigate.to(pageFromTemplate(pageWithMultipleSelects)),
Select.options(['PL', 'DE']).from(MultiCountry.Selector),
Ensure.that(SelectedOptions.of(MultiCountry.Selector), equals(['PL', 'DE']))));

});

describe('SelectedOptions', () => {
class MultiCountry {
static Selector = Target.the('country selector').located(by.id('multiple-options'));
}

class ListOfItems {
static Selector = Target.all('country list').located(by.tagName('li'));
}

/** @test {SelectedOptions} */
const pageWithMultipleSelects = `
<html>
<body>
<form>
<ul>
<li>PL</li>
<li>GB</li>
</ul>
<fieldset name='options'>
<legend>Working with options</legend>
<label for='multiple-options'>
Country
<select multiple='' id='multiple-options'>
<option label='United Kingdom' value='GB'>United Kingdom</option>
<option label='Poland' value='PL'>Poland</option>
<option label='Germany' value='DE'>Germany</option>
<option label='France' value='FR'>France</option>
</select>
</label>
</fieldset>
</form>
</body>
</html>`;
/** @test {SelectedOptions.of} */
it('should return a multiple values when multiple text arguments are passed to Select', () =>
actorCalled('Nick').attemptsTo(
Navigate.to(pageFromTemplate(pageWithMultipleSelects)),
Select.options(Text.ofAll(ListOfItems.Selector)).from(MultiCountry.Selector),
Ensure.that(SelectedOptions.of(MultiCountry.Selector), equals(['GB', 'PL']))));

});
126 changes: 126 additions & 0 deletions packages/protractor/spec/screenplay/questions/SelectedText.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import 'mocha';
import { Ensure, equals } from '@serenity-js/assertions';
import { by } from 'protractor';
import { Navigate, Select, SelectedText, SelectedTextItems, Target, Text } from '../../../src';
import { pageFromTemplate } from '../../fixtures';
import { UIActors } from '../../UIActors';
import { actorCalled, engage } from '@serenity-js/core';

describe('SelectedText', () => {

beforeEach(() => engage(new UIActors()));

class SingleCountry {
static Selector = Target.the('country selector').located(by.id('single-option'));
}

/** @test {SelectedText} */
const pageWithSingleSelect = `
<html>
<body>
<form>
<fieldset name="options">
<legend>Working with single option</legend>
<label for="single-option">
Country
<select id="single-option">
<option label="United Kingdom" value="GB" selected="selected">United Kingdom</option>
<option label="Poland" value="PL" selected="selected">Poland</option>
<option label="Germany" value="DE" selected="selected">Germany</option>
<option label="France" value="FR">France</option>
</select>
</label>
</fieldset>
</form>
</body>
</html>`;
/** @test {SelectedText.of} */
it('should return a single value when a single text item is passed to Select.text()', () =>
actorCalled('Nick').attemptsTo(
Navigate.to(pageFromTemplate(pageWithSingleSelect)),
Select.text('France').from(SingleCountry.Selector),
Ensure.that(SelectedText.of(SingleCountry.Selector), equals('France'))));

});

describe('SelectedTextItems', () => {

beforeEach(() => engage(new UIActors()));

class MultiCountry {
static Selector = Target.the('country selector').located(by.id('multiple-options'));
}

/** @test {SelectedText} */
const pageWithMultipleSelects = `
<html>
<body>
<form>
<fieldset name="options">
<legend>Working with options</legend>
<label for="multiple-options">
Country
<select multiple="" id="multiple-options">
<option label="United Kingdom" value="GB">United Kingdom</option>
<option label="Poland" value="PL">Poland</option>
<option label="Germany" value="DE">Germany</option>
<option label="France" value="FR">France</option>
</select>
</label>
</fieldset>
</form>
</body>
</html>`;
/** @test {SelectedText.of} */
it('should return a multiple values when an array of text items is passed to Select.textValues()', () =>
actorCalled('Nick').attemptsTo(
Navigate.to(pageFromTemplate(pageWithMultipleSelects)),
Select.textValues(['Poland', 'France']).from(MultiCountry.Selector),
Ensure.that(SelectedTextItems.of(MultiCountry.Selector), equals(['Poland', 'France']))));

});

describe('SelectedTextItems', () => {

beforeEach(() => engage(new UIActors()));

class MultiCountry {
static Selector = Target.the('country selector').located(by.id('multiple-options'));
}

class ListOfItems {
static Selector = Target.all('country list').located(by.tagName('li'));
}

/** @test {SelectedText} */
const pageWithMultipleSelects = `
<html>
<body>
<form>
<ul>
<li>Poland</li>
<li>Germany</li>
</ul>
<fieldset name="options">
<legend>Working with options</legend>
<label for="multiple-options">
Country
<select multiple="" id="multiple-options">
<option label="United Kingdom" value="GB">United Kingdom</option>
<option label="Poland" value="PL">Poland</option>
<option label="Germany" value="DE">Germany</option>
<option label="France" value="FR">France</option>
</select>
</label>
</fieldset>
</form>
</body>
</html>`;
/** @test {SelectedText.of} */
it('should return a multiple values when an answerable array of text items is passed to Select.textValues()', () =>
actorCalled('Nick').attemptsTo(
Navigate.to(pageFromTemplate(pageWithMultipleSelects)),
Select.textValues(Text.ofAll(ListOfItems.Selector)).from(MultiCountry.Selector),
Ensure.that(SelectedTextItems.of(MultiCountry.Selector), equals(['Poland', 'Germany']))));

});
Loading