Skip to content

Commit 64b79b0

Browse files
committed
Updated the example to use more modern syntax
1 parent b8c62d9 commit 64b79b0

19 files changed

+139
-106
lines changed

features/step_definitions/journey_planner.steps.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@ import {
55
ChooseOrigin,
66
ChooseTime,
77
ConfirmSelection,
8+
containTrainsDepartingAt,
89
SpecifyPreferences,
910
} from '../../src/journey_planner';
1011

11-
import { Navigate, PlanAJourney } from '../../src';
12+
import { PlanAJourney } from '../../src';
1213

1314
import { following } from '../../src/text';
1415

15-
import { containTrainsDepartingAt } from '../../src/journey_planner/questions/journeys_found';
16-
1716
export = function journeyPlannerSteps() {
1817

1918
this.Given(/(.*) line trains from (.*) leave (.*) at (.*)$/, function(tubeLine, origin, station, departureTimes) {
@@ -56,7 +55,7 @@ export = function journeyPlannerSteps() {
5655

5756
// Wait.until(JourneyPlanner.Results, Is.visible()),
5857
// Scroll.to(JourneyPlanner.Results),
59-
// See.if(Journeys.found(), containTrainsDepartingAt(following(departureTimes))),
58+
// See.if(JourneysFound(), containTrainsDepartingAt(following(departureTimes))),
6059
);
6160
});
6261
};

package.json

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"pree2e": "npm run lint && npm run webdriver:update -- --standalone --versions.standalone=2.53.1 --versions.chrome=2.29",
1111
"e2e": "protractor ./protractor.conf.js --cucumberOpts.name 'Connie looks for the next train'",
1212
"report": "serenity run",
13-
"test": "failsafe e2e report",
13+
"test": "failsafe clean e2e report",
1414
"webdriver:update": "webdriver-manager update"
1515
},
1616
"repository": {
@@ -21,22 +21,23 @@
2121
"license": "Apache-2.0",
2222
"dependencies": {},
2323
"devDependencies": {
24-
"@types/chai": "3.5.2",
25-
"@types/chai-as-promised": "0.0.30",
26-
"@types/node": "7.0.18",
27-
"chai": "3.5.0",
28-
"chai-as-promised": "6.0.0",
24+
"@types/chai": "4.0.0",
25+
"@types/chai-as-promised": "0.0.31",
26+
"@types/cucumber": "1.3.1",
27+
"@types/node": "7.0.31",
28+
"chai": "4.0.2",
29+
"chai-as-promised": "7.0.0",
2930
"chai-smoothie": "0.x",
3031
"cucumber": "1.3.2",
3132
"npm-failsafe": "0.x",
32-
"protractor": "5.1.1",
33+
"protractor": "5.1.2",
3334
"rimraf": "2.6.1",
34-
"serenity-cli": "^0.1.4",
35-
"serenity-js": "^1.x",
36-
"ts-node": "3.0.2",
37-
"tslint": "5.1.0",
35+
"serenity-cli": ">= 0.4.0",
36+
"serenity-js": ">= 1.7.0",
37+
"ts-node": "3.0.6",
38+
"tslint": "5.4.3",
3839
"tslint-microsoft-contrib": "5.0.0",
39-
"typescript": "2.2.2"
40+
"typescript": "2.4.0"
4041
},
4142
"engines": {
4243
"node": ">= 6.9.x"

protractor.conf.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
1+
const
2+
glob = require('glob'),
3+
protractor = require.resolve('protractor'),
4+
node_modules = protractor.substring(0, protractor.lastIndexOf('node_modules') + 'node_modules'.length),
5+
seleniumJar = glob.sync(`${node_modules}/protractor/**/selenium-server-standalone-*.jar`).pop();
6+
17
exports.config = {
28

39
baseUrl: 'https://tfl.gov.uk',
410

11+
seleniumServerJar: seleniumJar,
12+
513
allScriptsTimeout: 110000,
614

15+
disableChecks: true,
16+
17+
// https://github.com/protractor-cucumber-framework/protractor-cucumber-framework#uncaught-exceptions
18+
ignoreUncaughtExceptions: true,
19+
720
framework: 'custom',
821
frameworkPath: require.resolve('serenity-js'),
922

@@ -18,9 +31,13 @@ exports.config = {
1831
browserName: 'chrome',
1932
chromeOptions: {
2033
args: [
21-
// 'incognito',
22-
// 'disable-extensions',
23-
// 'show-fps-counter=true'
34+
'--disable-infobars',
35+
// "--headless",
36+
// "--disable-gpu",
37+
// "--window-size=1024x768"
38+
// '--incognito',
39+
// '--disable-extensions',
40+
// '--show-fps-counter=true'
2441
]
2542
}
2643
}

src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
export * from './actors';
2-
export * from './navigate';
32
export * from './plan_a_journey';

src/journey_planner/avoid_travelling.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import { Click } from 'serenity-js/lib/serenity-protractor';
2-
import { step } from 'serenity-js/lib/serenity/recording';
3-
import { PerformsTasks, Task } from 'serenity-js/lib/serenity/screenplay';
1+
import { Click, PerformsTasks, step, Task } from 'serenity-js/lib/screenplay-protractor';
42

53
import { JourneyPlannerPreferences } from './ui/journey_planner_preferences';
64

src/journey_planner/check.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1+
import { Assertion } from '@serenity-js/core/lib/screenplay/expectations';
12
import { Is, Scroll, See, Task, Wait } from 'serenity-js/lib/screenplay-protractor';
2-
import { Assertion } from 'serenity-js/lib/serenity/screenplay/expectations';
33

4-
import { Journeys, JourneySummary } from '../../src/journey_planner/questions/journeys_found';
4+
import { JourneysFound, JourneySummary } from '../../src/journey_planner';
55
import { JourneyPlanner } from '../../src/journey_planner/ui';
66

7-
export const Check = { ifJourneysFound: (assertion: Assertion<JourneySummary[]>) => Task.where(`#actor checks the results`,
8-
Wait.until(JourneyPlanner.Results, Is.visible()),
9-
Scroll.to(JourneyPlanner.Results),
10-
See.if(Journeys.found(), assertion),
11-
)};
7+
export const Check = {
8+
ifJourneysFound: (assertion: Assertion<PromiseLike<JourneySummary[]>>) =>
9+
10+
Task.where(`#actor checks the results`,
11+
Wait.until(JourneyPlanner.Results, Is.visible()),
12+
Scroll.to(JourneyPlanner.Results),
13+
See.if(JourneysFound(), assertion),
14+
),
15+
};

src/journey_planner/choose_origin_and_destination.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { protractor } from 'protractor';
2-
import { Enter, Hit, Is, Target, Wait } from 'serenity-js/lib/serenity-protractor';
3-
import { Task } from 'serenity-js/lib/serenity/screenplay';
2+
import { Enter, Hit, Is, Target, Task, Wait } from 'serenity-js/lib/screenplay-protractor';
43

54
import { JourneyPlanner } from './ui';
65

@@ -9,10 +8,12 @@ export const ChooseOrigin = { of: (origin: string) => Task.where(`#actor wants t
98
PickTheFirstSuggestion.of(JourneyPlanner.Origin_Field).from(JourneyPlanner.Origin_Suggestions),
109
)};
1110

12-
export const ChooseDestination = { of: (destination: string) => Task.where(`#actor wants to travel to ${destination}`,
13-
Enter.theValue(destination).into(JourneyPlanner.Destination_Field),
14-
PickTheFirstSuggestion.of(JourneyPlanner.Destination_Field).from(JourneyPlanner.Destination_Suggestions),
15-
)};
11+
export const ChooseDestination = {
12+
of: (destination: string) => Task.where(`#actor wants to travel to ${destination}`,
13+
Enter.theValue(destination).into(JourneyPlanner.Destination_Field),
14+
PickTheFirstSuggestion.of(JourneyPlanner.Destination_Field).from(JourneyPlanner.Destination_Suggestions),
15+
),
16+
};
1617

1718
const PickTheFirstSuggestion = {
1819
of: (field: Target) => ({

src/journey_planner/choose_time.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { Click, Select } from 'serenity-js/lib/serenity-protractor';
2-
import { Task } from 'serenity-js/lib/serenity/screenplay';
1+
import { Click, Select, Task } from 'serenity-js/lib/screenplay-protractor';
32
import { JourneyPlanner } from './ui';
43

54
export const ChooseTime = {

src/journey_planner/confirm_selection.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { Click } from 'serenity-js/lib/serenity-protractor';
2-
import { Task } from 'serenity-js/lib/serenity/screenplay';
1+
import { Click, Task } from 'serenity-js/lib/screenplay-protractor';
32

43
import { JourneyPlanner } from './ui';
54

src/journey_planner/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ export * from './check';
33
export * from './choose_origin_and_destination';
44
export * from './choose_time';
55
export * from './confirm_selection';
6+
export * from './journeys_found';
7+
export * from './open_journey_planner';
68
export * from './specify_preferences';

src/journey_planner/journeys_found.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { BrowseTheWeb, Question, Target, UsesAbilities } from 'serenity-js/lib/screenplay-protractor';
2+
3+
import { by } from 'protractor';
4+
import { expect } from '../expect';
5+
import { JourneyResults } from './ui/journey_results';
6+
7+
export interface JourneySummary {
8+
departureTime: string;
9+
arrivalTime: string;
10+
}
11+
12+
export const JourneysFound = () => Question.where(`#actor checks the results`, actor =>
13+
14+
BrowseTheWeb.as(actor).locateAll(JourneyResults.List).
15+
map(result => result.all(by.css('.time-boxes .time-box .time')).getText().then(times => ({
16+
departureTime: times[0],
17+
arrivalTime: times[1],
18+
}))) as PromiseLike<JourneySummary[]>,
19+
);
20+
21+
export const containTrainsDepartingAt = (expectedDepartureTimes: string[]) => foundJourneys => {
22+
return foundJourneys.then(journeys => {
23+
expect(journeys).to.have.lengthOf(expectedDepartureTimes.length);
24+
25+
journeys.forEach(journey => {
26+
expect(journey.departureTime).to.to.be.oneOf(expectedDepartureTimes);
27+
});
28+
});
29+
};
30+
31+
// class-style implementation:
32+
33+
// export class Journeys implements Question<PromiseLike<JourneySummary[]>> {
34+
//
35+
// static found = () => new Journeys();
36+
//
37+
// answeredBy(actor: UsesAbilities): PromiseLike<JourneySummary[]> {
38+
// return BrowseTheWeb.as(actor).locateAll(
39+
// Target.the('results').located(by.css('.publictransport-box')),
40+
// ).map(result => result.all(by.css('.time-boxes .time-box .time')).getText().then(times => ({
41+
// departureTime: times[0],
42+
// arrivalTime: times[1],
43+
// })));
44+
// }
45+
//
46+
// toString = () => `the results`;
47+
// }
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { Open, ResizeBrowserWindow, Task, UseAngular } from 'serenity-js/lib/screenplay-protractor';
2+
3+
export const OpenJourneyPlanner = () => Task.where(`#actor opens the Journey Planner`,
4+
UseAngular.disableSynchronisation(),
5+
ResizeBrowserWindow.toMaximum(),
6+
Open.browserOn('/'),
7+
);

src/journey_planner/questions/journeys_found.ts

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/journey_planner/specify_preferences.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { Click } from 'serenity-js/lib/serenity-protractor';
2-
import { PerformsTasks, Task } from 'serenity-js/lib/serenity/screenplay';
1+
import { Click, PerformsTasks, Task } from 'serenity-js/lib/screenplay-protractor';
32
import { JourneyPlanner } from './ui';
43

54
export class SpecifyPreferences implements Task {
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import { by } from 'protractor';
22
import { Target } from 'serenity-js/lib/serenity-protractor';
33

4-
export class JourneyPlanner {
5-
static Origin_Field = Target.the('"From" field').located(by.id('InputFrom'));
6-
static Origin_Suggestions = Target.the('"From" suggestions').located(by.xpath('//*[input[@id="InputFrom"]]/*[contains(@class, "tt-dropdown-menu")]'));
4+
export const JourneyPlanner = {
5+
Origin_Field: Target.the('"From" field').located(by.id('InputFrom')),
6+
Origin_Suggestions: Target.the('"From" suggestions').located(by.xpath('//*[input[@id="InputFrom"]]/*[contains(@class, "tt-dropdown-menu")]')),
77

8-
static Destination_Field = Target.the('"To" field').located(by.id('InputTo'));
9-
static Destination_Suggestions = Target.the('"To" suggestions').located(by.xpath('//*[input[@id="InputTo"]]/*[contains(@class, "tt-dropdown-menu")]'));
8+
Destination_Field: Target.the('"To" field').located(by.id('InputTo')),
9+
Destination_Suggestions: Target.the('"To" suggestions').located(by.xpath('//*[input[@id="InputTo"]]/*[contains(@class, "tt-dropdown-menu")]')),
1010

11-
static Change_Time_Link = Target.the('change time link').located(by.linkText('change time'));
12-
static Time_Selector = Target.the('time selector').located(by.id('Time'));
13-
static Leaving_Button = Target.the('"leaving" button').located(by.css('label[for="departing"]'));
14-
static Arriving_Button = Target.the('"arriving" button').located(by.css('label[for="arriving"]'));
11+
Change_Time_Link: Target.the('change time link').located(by.linkText('change time')),
12+
Time_Selector: Target.the('time selector').located(by.id('Time')),
13+
Leaving_Button: Target.the('"leaving" button').located(by.css('label[for="departing"]')),
14+
Arriving_Button: Target.the('"arriving" button').located(by.css('label[for="arriving"]')),
1515

16-
static Edit_Preferences_Link = Target.the('Edit preferences link').located(by.linkText('Edit preferences'));
16+
Edit_Preferences_Link: Target.the('Edit preferences link').located(by.linkText('Edit preferences')),
1717

18-
static Plan_My_Journey = Target.the('"Plan my journey" button').located(by.buttonText('Plan my journey'));
18+
Plan_My_Journey: Target.the('"Plan my journey" button').located(by.buttonText('Plan my journey')),
1919

20-
static Results = Target.the('results').located(by.css('.journey-results'));
21-
}
20+
Results: Target.the('results').located(by.css('.journey-results')),
21+
};
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { by } from 'protractor';
22
import { Target } from 'serenity-js/lib/serenity-protractor';
33

4-
export class JourneyPlannerPreferences {
5-
static Journey_Option = Target.the('journey option').located(by.xpath('//label[text()="{0}"]')).called('Travel by {0}');
6-
}
4+
export const JourneyPlannerPreferences = {
5+
Journey_Option: Target.the('journey option').located(by.xpath('//label[text()="{0}"]')).called('Travel by {0}'),
6+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { by } from 'protractor';
2+
import { Target } from 'serenity-js/lib/screenplay-protractor';
3+
4+
export const JourneyResults = {
5+
List: Target.the('results').located(by.css('.publictransport-box')),
6+
};

src/navigate.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/plan_a_journey.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
import { step } from 'serenity-js/lib/serenity/recording';
2-
import { PerformsTasks, Task } from 'serenity-js/lib/serenity/screenplay';
1+
import { PerformsTasks, step, Task } from 'serenity-js/lib/screenplay-protractor';
32
import {
43
AvoidTravelling,
54
ChooseDestination,
65
ChooseOrigin,
76
ChooseTime,
87
ConfirmSelection,
8+
OpenJourneyPlanner,
99
SpecifyPreferences,
1010
} from './journey_planner';
1111

12-
import { Navigate } from './navigate';
1312
import { following } from './text';
1413

1514
export class PlanAJourney implements Task {
@@ -39,7 +38,7 @@ export class PlanAJourney implements Task {
3938
@step('#actor plans a journey')
4039
performAs(actor: PerformsTasks): PromiseLike<void> {
4140
return actor.attemptsTo(
42-
Navigate.to('https://tfl.gov.uk/'),
41+
OpenJourneyPlanner(),
4342
...this.tasks,
4443
ConfirmSelection(),
4544
);

0 commit comments

Comments
 (0)