miniProgramSmoke.live.test.mjs
3.96 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
import assert from 'node:assert/strict'
import test from 'node:test'
import automator from 'miniprogram-automator'
import {
loadUiSmokeConfig,
requireUiSmokeConfig
} from './uiSmokeConfig.mjs'
import { openMiniProgram, releaseMiniProgram } from './uiLauncher.mjs'
import {
findExactIndex,
waitForListData
} from './uiSmokeHelpers.mjs'
const liveEnabled = loadUiSmokeConfig().enabled
const waitForPage = async (
miniProgram,
predicate,
{ timeoutMs = 30000, intervalMs = 300 } = {}
) => {
const deadline = Date.now() + timeoutMs
let lastPath = ''
while (Date.now() < deadline) {
const page = await miniProgram.currentPage()
lastPath = page?.path ?? ''
if (page && predicate(page)) return page
await new Promise(resolve => setTimeout(resolve, intervalMs))
}
throw new Error(`Timed out waiting for mini program page; last=${lastPath}`)
}
const tapListItem = async (page, selector, index, label) => {
const elements = await page.$$(selector)
const element = elements[index]
if (!element) throw new Error(`${label} UI item index ${index} is missing`)
await element.tap()
}
test(
'IT-OL-UI-LIVE-001: login selects exact park, store, premium scene and opens create order',
{ skip: !liveEnabled, timeout: 120000 },
async () => {
const config = requireUiSmokeConfig()
let miniProgram
try {
miniProgram = await openMiniProgram(automator, config)
const loginPage = await miniProgram.reLaunch('/pages/wxLogin/wxLogin')
assert.equal(loginPage?.path, 'pages/wxLogin/wxLogin')
await loginPage.setData({ loginType: 1 })
await loginPage.waitFor(300)
const authSetting = await loginPage.$('auth-setting')
const authCheckbox = await authSetting?.$('.choose-box')
assert.ok(authCheckbox, 'privacy agreement checkbox should be rendered')
await authCheckbox.tap()
const inputs = await loginPage.$$('input')
assert.equal(inputs.length, 2)
await inputs[0].input(config.mobile)
await inputs[1].input(config.code)
const loginButton = await loginPage.$('.login_btn')
assert.ok(loginButton, 'mobile login button should be rendered')
await loginButton.tap()
const parkPage = await waitForPage(
miniProgram,
page => page.path === 'pages/accountItems/accountItems'
)
const parkItems = await waitForListData(
parkPage,
'loginUserInfoList'
)
const parkIndex = findExactIndex(
parkItems,
'merchantName',
config.parkName,
'park'
)
await tapListItem(parkPage, '.items', parkIndex, 'park')
const storePage = await waitForPage(
miniProgram,
page => page.path === 'pages/merchantList/merchantList'
)
const storeItems = await waitForListData(
storePage,
'loginUserInfoList'
)
const storeIndex = findExactIndex(
storeItems,
'merchantName',
config.storeName,
'store'
)
await tapListItem(storePage, '.items', storeIndex, 'store')
const scenePage = await waitForPage(
miniProgram,
page => page.path === 'pages/sceneIndex/sceneIndex'
)
const scenes = await waitForListData(scenePage, 'sceneList')
const sceneIndex = findExactIndex(
scenes,
'sceneName',
config.sceneName,
'scene'
)
await tapListItem(scenePage, '.scene-item', sceneIndex, 'scene')
await waitForPage(
miniProgram,
page => page.path === 'tabIndex/pages/index/index'
)
const createOrderPage = await miniProgram.navigateTo(
'/tabWorkOrder/pages/createOrder/createOrder'
)
assert.equal(
createOrderPage?.path,
'tabWorkOrder/pages/createOrder/createOrder'
)
await createOrderPage.waitFor(1000)
const pageData = await createOrderPage.data()
assert.equal(Number(pageData.sceneType), 1)
} finally {
if (miniProgram) await releaseMiniProgram(miniProgram, config)
}
}
)