-
Notifications
You must be signed in to change notification settings - Fork 190
Expand file tree
/
Copy pathsalesforce.scenario.ts
More file actions
139 lines (109 loc) · 5.18 KB
/
Copy pathsalesforce.scenario.ts
File metadata and controls
139 lines (109 loc) · 5.18 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import { expect, test } from '@playwright/test'
import { createTest } from '../lib/framework'
import type { SalesforceApp } from '../lib/framework'
// Skip non chromium browsers because --disable-web-security is chromium-only.
test.skip(() => test.info().project.name !== 'chromium', 'Salesforce app is tested on chromium only')
// Bypass CSP and CORS restrictions in the Salesforce app.
test.use({
bypassCSP: true,
launchOptions: { args: ['--disable-web-security'] },
})
const baseSalesforceRumConfiguration = {
trackLongTasks: true,
trackResources: true,
trackUserInteractions: true,
}
const salesforceApps: SalesforceApp[] = ['lwc', 'experience-cloud', 'experience-cloud-headmarkup']
for (const app of salesforceApps) {
const canCallRumFromComponents = app !== 'experience-cloud-headmarkup'
createTest(`salesforce ${app} views`)
.withRum(baseSalesforceRumConfiguration)
.withSalesforceApp(app)
.run(async ({ page, intakeRegistry, flushEvents }) => {
await expect(page.getByTestId('home-custom-actions')).toBeVisible({ timeout: 30000 })
await page.getByRole('link', { name: 'Product Explorer' }).click()
await expect(page.getByTestId('product-explorer')).toBeVisible()
await flushEvents()
const homeView = intakeRegistry.rumViewEvents.find((e) => e.view.loading_type === 'initial_load')
expect(homeView).toBeDefined()
const productExplorerView = intakeRegistry.rumViewEvents.find((e) => e.view.loading_type === 'route_change')
expect(productExplorerView).toBeDefined()
})
createTest(`salesforce ${app} resources`)
.withRum(baseSalesforceRumConfiguration)
.withSalesforceApp(app)
.run(async ({ page, intakeRegistry, flushEvents }) => {
await expect(page.getByTestId('home-custom-actions')).toBeVisible({ timeout: 30000 })
await page.getByTestId('fetch-resource').click()
await page.getByTestId('xhr-resource').click()
await page.getByTestId('image-resource').click()
await flushEvents()
const resourceTypes = new Set(intakeRegistry.rumResourceEvents.map((e) => e.resource.type))
for (const resourceType of ['document', 'other', 'xhr', 'fetch', 'image'] as const) {
expect(
resourceTypes.has(resourceType),
`missing resource type "${resourceType}", got: [${[...resourceTypes].join(', ')}]`
).toBe(true)
}
})
createTest(`salesforce ${app} long tasks${canCallRumFromComponents ? ' and vitals' : ''}`)
.withRum(baseSalesforceRumConfiguration)
.withSalesforceApp(app)
.run(async ({ page, intakeRegistry, flushEvents }) => {
await expect(page.getByTestId('home-custom-actions')).toBeVisible({ timeout: 30000 })
await page.getByTestId('long-task').click()
if (canCallRumFromComponents) {
await page.getByRole('button', { name: 'Add Duration Vital' }).click()
}
await flushEvents()
expect(intakeRegistry.rumLongTaskEvents.length).toBeGreaterThanOrEqual(1)
if (canCallRumFromComponents) {
expect(intakeRegistry.rumVitalEvents.length).toBeGreaterThanOrEqual(1)
}
})
createTest(`salesforce ${app} actions`)
.withRum(baseSalesforceRumConfiguration)
.withSalesforceApp(app)
.run(async ({ page, intakeRegistry, flushEvents }) => {
await expect(page.getByTestId('home-custom-actions')).toBeVisible({ timeout: 30000 })
await page.getByTestId('custom-action-1').click()
await flushEvents()
const actionTypes = new Set(intakeRegistry.rumActionEvents.map((e) => e.action.type))
expect(actionTypes.has('click')).toBe(true)
if (canCallRumFromComponents) {
const customAction = intakeRegistry.rumActionEvents.find(
(e) => e.action.type === 'custom' && e.action.target?.name?.includes('custom action 1') === true
)
expect(customAction).toBeDefined()
}
})
createTest(`salesforce ${app} errors`)
.withRum(baseSalesforceRumConfiguration)
.withSalesforceApp(app)
.run(async ({ page, intakeRegistry, flushEvents, withBrowserLogs }) => {
await expect(page.getByTestId('home-custom-actions')).toBeVisible({ timeout: 30000 })
if (canCallRumFromComponents) {
await page.getByTestId('custom-error-1').click()
}
await page.getByTestId('runtime-error').click()
await page.evaluate(() => window.console.error('salesforce console error test'))
await flushEvents()
const consoleError = intakeRegistry.rumErrorEvents.find(
(e) => e.error.source === 'console' && e.error.message?.includes('salesforce console error test') === true
)
expect(consoleError).toBeDefined()
withBrowserLogs((logs) => {
expect(logs.filter((log) => log.level === 'error').length).toBeGreaterThanOrEqual(1)
})
const errorEvent = intakeRegistry.rumErrorEvents.find(
(e) => e.error.message?.includes('salesforce direct runtime error test') === true
)
expect(errorEvent).toBeDefined()
if (canCallRumFromComponents) {
const customError = intakeRegistry.rumErrorEvents.find(
(e) => e.error.source === 'custom' && e.error.message?.includes('custom error 1') === true
)
expect(customError).toBeDefined()
}
})
}