-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserenity-js_website.spec.ts
86 lines (80 loc) · 3.99 KB
/
serenity-js_website.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import { Ensure, equals } from '@serenity-js/assertions'
import { actorCalled } from '@serenity-js/core'
import { By, Navigate, PageElement, Text } from '@serenity-js/web'
import { GitHubStatus } from '../serenity/github-api/GitHubStatus'
import { TodoList } from '../serenity/todo-list-app/TodoList'
/**
* Serenity/JS Screenplay Pattern test scenarios use one or more actors to represent people and external systems
* interacting with the system under test.
*
* To design a test scenario, give each actor a series of tasks and interactions to perform
* and instruct them to answer questions about the state of the system under test
* to ensure that the answers meet the expected results.
*
* This example test file demonstrates several ways of writing test scenarios using the Screenplay Pattern.
*
* Learn more:
* - Serenity/JS Screenplay Pattern - https://serenity-js.org/handbook/design/screenplay-pattern/
* - Web Testing with Serenity/JS - https://serenity-js.org/handbook/web-testing/
* - API Testing with Serenity/JS - https://serenity-js.org/handbook/api-testing/
* - Serenity/JS web module - https://serenity-js.org/api/web/
* - Serenity/JS REST module - https://serenity-js.org/api/rest/
* - Serenity/JS assertions module - https://serenity-js.org/api/assertions/
*/
describe('serenity-js website', () => {
/**
* This is the most basic example of a Serenity/JS Screenplay Pattern test scenario.
*
* This scenario uses a single actor configured to perform a series of web-based interactions,
* and uses only the low-level abstractions provided by the Serenity/JS web module.
*/
it('offers a web testing tutorial', async () => {
await actorCalled('Alice').attemptsTo(
Navigate.to('https://serenity-js.org'),
Ensure.that(
Text.of(PageElement.located(By.id('cta-start-automating'))),
equals('Start automating 🚀')
),
)
})
/**
* This is a more advanced example of a Serenity/JS Screenplay Pattern test scenario.
*
* This scenario uses two actors:
* - Apisitt, responsible for interacting with an API to check if the system is up and running before performing any UI checks
* - Wendy, responsible for interacting with the website to perform the actual acceptance test
*
* In this scenario, rather than list all the interactions in the test itself, we use:
* - API Actions Class Pattern to group tasks concerning interacting with the GitHubStatus API
* - Screenplay Pattern flavour of Page Objects to group tasks and questions concerning interacting with the Serenity/JS Todo List app
*
* Note that apart from strongly encouraging the Screenplay Pattern,
* Serenity/JS doesn't require you to organise your code in any particular way.
* This gives you the freedom to choose patterns and abstractions that work best for you, your team,
* and reflect the domain of your system under test.
*/
it(`offers examples to help you practice test automation`, async () => {
// You can use API interactions to manage test data, or to ensure services are up and running before performing any UI checks.
// Since Serenity/JS demo website is deployed to GitHub Pages,
// before interacting with the website we ensure that GitHub itself is up and running.
await actorCalled('Apisitt').attemptsTo(
GitHubStatus.ensureAllSystemsOperational(),
)
// Once we know the system is up and running, Wendy can proceed with the web-based scenario.
await actorCalled('Wendy').attemptsTo(
TodoList.createListContaining([
`Buy dog food`,
`Feed the dog`,
`Book a vet's appointment`,
]),
TodoList.markAsCompleted([
`Buy dog food`,
`Feed the dog`,
]),
Ensure.that(
TodoList.outstandingItemsCount(),
equals(1)
),
)
})
})