-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathplaywright-global-setup.ts
48 lines (40 loc) · 1.32 KB
/
playwright-global-setup.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
import { Browser, chromium, expect } from '@playwright/test'
import { readFixture } from './app/utils/fixtures'
async function loginAs(browser: Browser, user: string) {
const page = await browser.newPage()
await page.goto('http://localhost:3000/')
await page.click('text=Masuk')
await page.fill(
'input[name="email"]',
JSON.parse(await readFixture(`../../e2e/fixtures/users/${user}.local.json`))
?.email
)
await Promise.all([
page.waitForNavigation(/*{ url: 'http://localhost:3000/login' }*/),
page.click('text=Kirim link ke alamat email'),
])
await expect(
page.locator('text=Link telah dikirim ke alamat email Anda').first()
).toBeVisible()
await page.goto(
JSON.parse(await readFixture(`../../e2e/fixtures/magic.local.json`))
?.magicLink
)
await expect(page).toHaveURL('http://localhost:3000/dashboard')
await page
.context()
.storageState({ path: `e2e/fixtures/auth/${user}.local.json` })
}
async function globalSetup() {
const browser = await chromium.launch()
// stable member
await loginAs(browser, 'member')
// member without transaction
await loginAs(browser, 'member-no-transaction')
// editable member
await loginAs(browser, 'member-edit')
// course author
await loginAs(browser, 'author')
await browser.close()
}
export default globalSetup