Permalink
Browse files

feat(protractor): You can `Select` a value and check the `SelectedValue`

  • Loading branch information...
jan-molak committed Sep 18, 2016
1 parent d325d0f commit 274cabca75db66398da0e77452114f53b7a47249
@@ -0,0 +1,38 @@
import { protractor } from 'protractor/globals';
import {
BrowseTheWeb,
Click,
DoubleClick,
Open,
Text,
} from '../../../src/serenity-protractor/screenplay';
import { Actor } from '../../../src/serenity/screenplay';
import test = require('selenium-webdriver/testing');
import expect = require('../../expect');
import { DemoApp } from './ui/demo_app';
test.describe ('Interactions', () => {
let james = Actor.named('James').whoCan(BrowseTheWeb.using(protractor.browser));
test.beforeEach(() => james.attemptsTo(
Open.browserOn('resources/index.html')
));
test.it ('should allow to click elements of the UI', () =>
james.attemptsTo(
Click.on(DemoApp.Event_Trigger.of('click'))
).then(() =>
expect(james.toSee(Text.of(DemoApp.Event_Trigger.of('click'))))
.eventually.equal('click works!')));
test.it ('should allow to double-click elements of the UI', () =>
james.attemptsTo(
DoubleClick.on(DemoApp.Event_Trigger.of('dblclick'))
).then(() =>
expect(james.toSee(Text.of(DemoApp.Event_Trigger.of('dblclick'))))
.eventually.equal('dblclick works!')));
});
@@ -1,12 +1,10 @@
import { by, protractor } from 'protractor/globals';
import { protractor } from 'protractor/globals';
import {
BrowseTheWeb,
Click,
DoubleClick,
Enter,
Open,
Target,
Text,
Value,
Website,
@@ -16,16 +14,9 @@ import { Actor } from '../../../src/serenity/screenplay';
import test = require('selenium-webdriver/testing');
import expect = require('../../expect');
import { Attribute } from '../../../src/serenity-protractor/screenplay/questions/attribute';
class DemoApp {
static Header = Target.the('header').located(by.css('header>h1'));
static Item_Field = Target.the('name field').located(by.model('item'));
static Items = Target.the('list of items').located(by.repeater('item in items'));
static Submit_Button = Target.the('submit button').located(by.css('input[type="submit"]'));
static Event_Trigger = Target.the('event-triggering button').located(by.id('event-tester-{0}'));
}
import { Attribute } from '../../../src/serenity-protractor/screenplay/questions/attribute';
import { DemoApp } from './ui/demo_app';
test.describe ('Interactions', () => {
@@ -56,18 +47,4 @@ test.describe ('Interactions', () => {
test.it ('should allow to read the value of an arbitrary attribute', () =>
expect(james.toSee(Attribute.of(DemoApp.Item_Field).called('id'))).eventually.equal('item') );
test.it ('should allow to click elements of the UI', () =>
james.attemptsTo(
Click.on(DemoApp.Event_Trigger.of('click'))
).then(() =>
expect(james.toSee(Text.of(DemoApp.Event_Trigger.of('click'))))
.eventually.equal('click works!')));
test.it ('should allow to double-click elements of the UI', () =>
james.attemptsTo(
DoubleClick.on(DemoApp.Event_Trigger.of('dblclick'))
).then(() =>
expect(james.toSee(Text.of(DemoApp.Event_Trigger.of('dblclick'))))
.eventually.equal('dblclick works!')));
});
@@ -0,0 +1,28 @@
import {
BrowseTheWeb,
Open,
Select,
SelectedValue,
} from '../../../src/serenity-protractor/screenplay';
import { Actor } from '../../../src/serenity/screenplay';
import { DemoApp } from './ui/demo_app';
import test = require('selenium-webdriver/testing');
import { protractor } from 'protractor/globals';
import expect = require('../../expect');
test.describe ('Interactions', () => {
let james = Actor.named('James').whoCan(BrowseTheWeb.using(protractor.browser));
test.it ('should allow to select an option', () =>
james.attemptsTo(
Open.browserOn('resources/index.html'),
Select.theValue('London').from(DemoApp.Destinations)
).then(() =>
expect(james.toSee(SelectedValue.of(DemoApp.Destinations)))
.eventually.equal('London')));
});
@@ -0,0 +1,14 @@
import { Target } from '../../../../src/serenity-protractor/screenplay';
import { by } from 'protractor/globals';
export class DemoApp {
static Header = Target.the('header').located(by.css('header>h1'));
static Item_Field = Target.the('name field').located(by.model('item'));
static Items = Target.the('list of items').located(by.repeater('item in items'));
static Submit_Button = Target.the('submit button').located(by.css('input[type="submit"]'));
static Event_Trigger = Target.the('event-triggering button').located(by.id('event-tester-{0}'));
static Destinations = Target.the('destination selector').located(by.name('select'));
}
@@ -9,23 +9,13 @@ exports.config = {
seleniumServerJar: path.resolve(node_modules, 'protractor/node_modules/webdriver-manager/selenium/selenium-server-standalone-2.53.1.jar'),
framework: 'mocha',
specs: [ 'integration/**/*.js' ],
specs: [ 'interactions/**/*.js' ],
capabilities: {
'browserName': 'phantomjs',
'phantomjs.binary.path': path.resolve(node_modules, 'phantomjs-prebuilt/lib/phantom/bin/phantomjs'),
},
// capabilities: {
// browserName: 'chrome',
// chromeOptions: {
// args: [
// 'incognito'
// // 'show-fps-counter=true'
// ]
// }
// },
baseUrl: 'file://' + __dirname + '/',
onPrepare: function () {
@@ -28,6 +28,14 @@ <h1>{{ title }}</h1>
<event-tester event-name="dblclick"></event-tester>
</section>
<section id="selecting-an-option">
<select name="select">
<option value="london">London</option>
<option value="warsaw" selected>Warsaw</option>
<option value="barcelona">Barcelona</option>
</select>
</section>
<script>
angular.module('demo', []).
controller('main', ['$scope', function ($scope) {
View
@@ -1,4 +1,5 @@
--require ts-node/register
--require ./spec/fake_protractor.ts
--reporter dot
--watch-extensions ts
spec/**/*.spec.ts
View
@@ -0,0 +1,14 @@
// so that `import { by } from 'protractor/globals'`
// can be used in the Interaction classes
// without having to use the protractor itself
global[ 'protractor' ] = { // tslint:disable-line:no-string-literal
browser: null,
$: null,
$$: null,
element: null,
By: null,
by: null,
wrapDriver: null,
ExpectedConditions: null,
};
@@ -1,5 +1,7 @@
export * from './click';
export * from './double_click';
export * from './enter';
export * from './hit';
export * from './open';
export * from './resize_browser_window';
export * from './select';
@@ -0,0 +1,27 @@
import { Interaction, PerformsTasks, UsesAbilities } from '../../../serenity/screenplay';
import { BrowseTheWeb } from '../abilities/browse_the_web';
import { Target } from '../ui/target';
import { by } from 'protractor/globals';
export class Select {
static theValue(value: string) {
return new Select(value);
}
from(target: Target): Interaction {
return new SelectOption(this.value, target);
}
constructor(private value: string) {
}
}
class SelectOption implements Interaction {
performAs(actor: PerformsTasks & UsesAbilities): PromiseLike<void> {
return BrowseTheWeb.as(actor).locate(this.target).element(by.cssContainingText('option', this.value)).click();
}
constructor(private value: string, private target: Target) {
}
}
@@ -1,4 +1,5 @@
export * from './attribute';
export * from './selected_value';
export * from './text';
export * from './value';
export * from './website';
@@ -0,0 +1,16 @@
import { Question, UsesAbilities } from '../../../serenity/screenplay';
import { BrowseTheWeb } from '../abilities/browse_the_web';
import { Target } from '../ui/target';
export class SelectedValue implements Question<string> {
static of(target: Target) {
return new SelectedValue(target);
}
answeredBy(actor: UsesAbilities): PromiseLike<string> {
return BrowseTheWeb.as(actor).locate(this.target).$('option:checked').getText();
}
constructor(private target: Target) {
}
}

0 comments on commit 274cabc

Please sign in to comment.