-
Notifications
You must be signed in to change notification settings - Fork 4
/
data.spec.ts
77 lines (65 loc) · 2.64 KB
/
data.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
import { test, expect, TestInfo, Page } from '@playwright/test';
import { LoginPage } from '../page/LoginPage';
import { MembersPage } from '../page/MembersPage';
import { Cookie, nameDataScenario } from '../util/util'
import { Scenarios, ScenarioConfig, DataPools, getData } from '../util/dataGenerator';
import { StaffPage } from '../page/StaffPage';
import { TagPage } from '../page/TagPage';
// Run this tests in parallel
test.describe.configure({ mode: 'parallel' })
type ScenarioTestConfig = {
page: Page,
testinfo: TestInfo,
identifier: string,
scenario: ScenarioConfig,
}
let poolcounter = 0;
function oneDataPool() {
poolcounter++;
return DataPools[poolcounter % DataPools.length];
}
async function runScenario(config: ScenarioTestConfig, cookie: Cookie) {
const { page, testinfo, identifier, scenario } = config;
const { oracle } = scenario
// This method generates the member using the provided pool configuration
const data = getData({ identifier: identifier, pool: cookie.pool })
let res: boolean;
// Login
const loginPage = new LoginPage(page, testinfo);
await loginPage.open();
await loginPage.login();
expect(await loginPage.userIsLoggedIn()).toBeTruthy();
if (scenario.model === 'member') {
// Go to members page
const membersPage = new MembersPage(page, testinfo);
// Create member with the given data, returns true if created successfully or false if the creation faileed
res = await membersPage.CreateMember(data);
} else if (scenario.model === 'staff') {
// Go to the staff edit page
const staffPage = new StaffPage(page, testinfo);
await staffPage.open();
// Edit the staff with the given data, returns true if saved successfully or false if the edition failed
res = await staffPage.editStaff(data);
} else if (scenario.model === 'tag') {
const tagPage = new TagPage(page, testinfo);
await tagPage.open();
// Edit the staff with the given data, returns true if saved successfully or false if the edition failed
res = await tagPage.createTag(data);
} else {
throw new Error(`Unknown model: ${scenario.model}`);
}
// The scenarios data comes from the data pool and the oracles is defined with the data
expect(res).toBe(oracle);
}
let scenariosRun: Cookie[] = []
let counter = 1
Object.entries(Scenarios).forEach(([identifier, scenario]) => {
// Run each scenario individually
let pool = oneDataPool();
let cookie: Cookie = { scenarios: [scenario], pool: pool }
test(nameDataScenario(cookie, counter), async ({ page }, testinfo) => {
await runScenario({ page, testinfo, identifier, scenario }, cookie);
scenariosRun.push(cookie);
});
counter++;
})