Skip to content

Commit ce1e6f8

Browse files
committed
Updated the tutorial to work with the new version of the TFL website
1 parent 64b79b0 commit ce1e6f8

File tree

6 files changed

+43
-11
lines changed

6 files changed

+43
-11
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ target/
1010
# Build artifacts
1111
.nyc_output
1212
lib
13-
staging
13+
staging

protractor.conf.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const
2+
crew = require('serenity-js/lib/stage_crew');
23
glob = require('glob'),
34
protractor = require.resolve('protractor'),
45
node_modules = protractor.substring(0, protractor.lastIndexOf('node_modules') + 'node_modules'.length),
@@ -20,6 +21,20 @@ exports.config = {
2021
framework: 'custom',
2122
frameworkPath: require.resolve('serenity-js'),
2223

24+
serenity: {
25+
crew: [
26+
crew.serenityBDDReporter(),
27+
28+
// crew.photographer()
29+
30+
crew.Photographer.who(_ => _
31+
.takesPhotosOf(_.Failures)
32+
)
33+
34+
// crew.consoleReporter()
35+
]
36+
},
37+
2338
specs: [ 'features/**/*.feature' ],
2439
cucumberOpts: {
2540
require: [ 'features/**/*.ts' ],
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
import { Click, Task } from 'serenity-js/lib/screenplay-protractor';
1+
import { Click, Hit, Task } from 'serenity-js/lib/screenplay-protractor';
22

3+
import { protractor } from 'protractor';
34
import { JourneyPlanner } from './ui';
45

56
export const ConfirmSelection = () => Task.where(`#actor confirms their selection`,
6-
Click.on(JourneyPlanner.Plan_My_Journey),
7+
Hit.the(protractor.Key.RETURN).into(JourneyPlanner.Plan_My_Journey),
8+
9+
// or:
10+
// Scroll.to(JourneyPlanner.Plan_My_Journey),
11+
// Click.on(JourneyPlanner.Plan_My_Journey),
712
);

src/journey_planner/journeys_found.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { BrowseTheWeb, Question, Target, UsesAbilities } from 'serenity-js/lib/screenplay-protractor';
1+
import { BrowseTheWeb, Question } from 'serenity-js/lib/screenplay-protractor';
22

3-
import { by } from 'protractor';
3+
import { by, ElementFinder } from 'protractor';
44
import { expect } from '../expect';
55
import { JourneyResults } from './ui/journey_results';
66

@@ -12,12 +12,23 @@ export interface JourneySummary {
1212
export const JourneysFound = () => Question.where(`#actor checks the results`, actor =>
1313

1414
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[]>,
15+
map(resultsToJourneySummaries) as PromiseLike<JourneySummary[]>,
1916
);
2017

18+
function resultsToJourneySummaries(result: ElementFinder) {
19+
return result.all(by.css('.time-boxes .time-box .time')).getText().then(individualResultToJourneySummary);
20+
}
21+
22+
function individualResultToJourneySummary(text: string): JourneySummary {
23+
const summaryFormat = /(\d{2}:\d{2})/gi;
24+
const times = text[0].match(summaryFormat);
25+
26+
return ({
27+
departureTime: times[0],
28+
arrivalTime: times[1],
29+
});
30+
}
31+
2132
export const containTrainsDepartingAt = (expectedDepartureTimes: string[]) => foundJourneys => {
2233
return foundJourneys.then(journeys => {
2334
expect(journeys).to.have.lengthOf(expectedDepartureTimes.length);

src/journey_planner/ui/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export * from './journey_planner_form';
1+
export * from './journey_planner';
22
export * from './journey_planner_preferences';

src/journey_planner/ui/journey_planner_form.ts renamed to src/journey_planner/ui/journey_planner.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ export const JourneyPlanner = {
1515

1616
Edit_Preferences_Link: Target.the('Edit preferences link').located(by.linkText('Edit preferences')),
1717

18-
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')),
19+
Plan_My_Journey: Target.the('"Plan my journey" button').located(by.xpath('(//input[@type="submit"][contains(@value, "Plan my journey")])[2]')),
1920

2021
Results: Target.the('results').located(by.css('.journey-results')),
2122
};

0 commit comments

Comments
 (0)