pages.test.js 16.0 KB
Newer Older
1 2 3 4 5
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isAndroid = platformInfo.startsWith('android')
const isIos = platformInfo.startsWith('ios')
const isApp = isAndroid || isIos
const isWeb = platformInfo.startsWith('web')
6
const isMP = platformInfo.startsWith('mp')
7 8
const isAppWebview = !!process.env.UNI_AUTOMATOR_APP_WEBVIEW

DCloud-WZF's avatar
DCloud-WZF 已提交
9 10
let pageIndex = 0
const pages = [
11 12 13 14 15 16
  // tabBar  //改动频繁,不再测试
  // '/pages/tabBar/component',
  // '/pages/tabBar/API',
  // '/pages/tabBar/CSS',
  // '/pages/tabBar/template',

DCloud-WZF's avatar
DCloud-WZF 已提交
17
  // component
18 19 20 21 22 23 24
  '/pages/component/view/view',
  // 单独测试例截图
  // 'pages/component/scroll-view/scroll-view',
  // 单独测试例截图
  // '/pages/component/scroll-view/scroll-view-refresher',
  // 单独测试例截图
  // '/pages/component/scroll-view/scroll-view-props',
25
  '/pages/component/scroll-view/scroll-view-refresher-props',
26 27
  '/pages/component/scroll-view/scroll-view-custom-refresher-props',
  '/pages/component/swiper/swiper',
28
  // '/pages/component/list-view/list-view',
29 30 31 32
  // 单独测试例截图
  // '/pages/component/list-view/list-view-refresh',
  // 单独测试例截图
  // '/pages/component/list-view/list-view-multiplex',
33 34 35
  // '/pages/component/list-view/list-view-multiplex-input',
  // '/pages/component/list-view/list-view-multiplex-video',
  // '/pages/component/list-view/list-view-children-in-slot',
36 37 38 39 40 41 42 43 44 45
  // 单独测试例截图
  // '/pages/component/sticky-section/sticky-section',
  // 单独测试例截图
  // '/pages/component/sticky-header/sticky-header',
  '/pages/component/text/text',
  // 单独测试例截图
  // '/pages/component/text/text-props',
  '/pages/component/rich-text/rich-text',
  '/pages/component/rich-text/rich-text-tags',
  '/pages/component/rich-text/rich-text-complex',
DCloud-WZF's avatar
DCloud-WZF 已提交
46
  '/pages/component/progress/progress',
47 48 49
  '/pages/component/form/form',
  '/pages/component/button/button',
  '/pages/component/button/buttonstatus',
DCloud-WZF's avatar
DCloud-WZF 已提交
50
  '/pages/component/radio/radio',
51 52 53 54
  '/pages/component/checkbox/checkbox',
  // 自动获取焦点,单独测试例截图
  // '/pages/component/input/input',
  '/pages/component/textarea/textarea',
DCloud-WZF's avatar
DCloud-WZF 已提交
55
  '/pages/component/slider/slider',
56 57 58
  '/pages/component/slider/slider-in-swiper',
  //动态内容
  // '/pages/component/picker-view/picker-view',
DCloud-WZF's avatar
DCloud-WZF 已提交
59
  '/pages/component/switch/switch',
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
  '/pages/component/image/image',
  '/pages/component/image/image-format',
  // 判断CPU类型,单独测试例截图
  // '/pages/component/image/image-mode',
  // 网络资源加载,单独测试例截图
  // '/pages/component/image/image-path',
  // 截图过大
  // '/pages/component/image/image-large',
  '/pages/component/video/video',
  '/pages/component/video/video-format',
  '/pages/component/navigator/navigator',
  '/pages/component/navigator/navigate',
  '/pages/component/navigator/redirect',
  // 动态内容
  // '/pages/component/web-view/web-view',
  // 依赖加载完成回调,单独测试例截图
76
  // '/pages/component/web-view/web-view/web-view-local',
77
  // 动态内容
78
  // '/pages/component/unicloud-db/unicloud-db',
79
  '/pages/component/unicloud-db/unicloud-db/contacts/add',
80
  // 动态内容
81
  // '/pages/component/unicloud-db/unicloud-db/contacts/edit',
82
  // 动态内容
83
  // '/pages/component/unicloud-db/unicloud-db/contacts/detail',
84 85
  // 动态内容
  // '/pages/component/unicloud-db/unicloud-db/mixin-datacom/mixin-datacom',
86
  // 单独测试例截图
87 88 89 90
  // '/pages/component/global-properties/global-properties',
  '/pages/component/global-events/global-events',
  '/pages/component/global-events/transition-events',
  '/pages/component/global-events/touch-events',
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
  // 单独测试例截图
  // '/pages/component/nested-scroll-header/nested-scroll-header',
  // 单独测试例截图
  // '/pages/component/nested-scroll-body/nested-scroll-body',
  // 单独测试例截图
  // '/pages/component/swiper/swiper-list-view',
  // 单独测试例截图
  // '/pages/component/list-view/issue-2199',

  // API
  '/pages/API/get-app/get-app',
  // 单独测试例截图
  // '/pages/API/get-current-pages/get-current-pages',
  // 单独测试例截图
  // '/pages/API/get-current-pages/set-page-style-disable-pull-down-refresh',
  '/pages/API/get-launch-options-sync/get-launch-options-sync',
  '/pages/API/navigator/navigator',
  // 单独测试例截图
  // '/pages/API/set-navigation-bar-color/set-navigation-bar-color',
  // 单独测试例截图
  // '/pages/API/set-navigation-bar-title/set-navigation-bar-title',
  // 单独测试例截图
  // '/pages/API/set-page-backgroundColorContent/set-page-backgroundColorContent',
  // 单独测试例截图
  // '/pages/API/navigator/new-page/new-page-1',
  '/pages/API/navigator/new-page/new-page-3',
117
  '/pages/API/navigator/new-page/onLoad',
118 119 120 121 122 123
  // 下拉刷新,不进行截图
  '/pages/API/pull-down-refresh/pull-down-refresh',
  // 单独测试例截图
  // '/pages/API/get-element-by-id/get-element-by-id',
  // 单独测试例截图
  // '/pages/API/get-element-by-id/get-element-by-id-multiple-root-node',
DCloud-WZF's avatar
DCloud-WZF 已提交
124
  '/pages/API/create-selector-query/create-selector-query',
125 126
  '/pages/API/storage/storage',
  // 单独测试例截图
127
  // '/pages/API/show-action-sheet/show-action-sheet',
128
  // 单独测试例截图
129 130
  // '/pages/API/show-modal/show-modal',
  '/pages/API/show-loading/show-loading',
131
  // 单独测试例截图
132
  // '/pages/API/show-toast/show-toast',
133 134 135 136 137 138 139 140 141 142 143
  // 单独测试例截图
  // '/pages/API/load-font-face/load-font-face',
  // 单独测试例截图
  // '/pages/API/load-font-face/load-font-face-child',
  '/pages/API/get-location/get-location',
  '/pages/API/interceptor/interceptor',
  '/pages/API/interceptor/page1',
  '/pages/API/interceptor/page2',
  '/pages/API/request/request',
  '/pages/API/upload-file/upload-file',
  '/pages/API/download-file/download-file',
144
  '/pages/API/websocket/socketTask',
145
  // 页面销毁时会关闭socket连接,所以规避
146
  // '/pages/API/websocket/websocket',
147 148 149 150
  '/pages/API/unicloud/unicloud/cloud-function',
  '/pages/API/unicloud/unicloud/cloud-object',
  '/pages/API/unicloud/unicloud/database',
  '/pages/API/unicloud/unicloud/cloud-storage',
151 152 153 154 155 156 157 158 159
  '/pages/API/get-system-info/get-system-info',
  '/pages/API/get-device-info/get-device-info',
  '/pages/API/get-app-base-info/get-app-base-info',
  '/pages/API/preview-image/preview-image',
  '/pages/API/choose-image/choose-image',
  '/pages/API/choose-video/choose-video',
  '/pages/API/get-network-type/get-network-type',
  '/pages/API/page-scroll-to/page-scroll-to',
  '/pages/API/event-bus/event-bus',
160
  // '/pages/API/get-battery-info/get-battery-info',
161 162
  '/pages/API/get-window-info/get-window-info',
  '/pages/API/rpx2px/rpx2px',
163 164
  '/pages/API/request-payment/request-payment/request-payment-uni-pay',
  '/pages/API/request-payment/request-payment/order-detail',
165 166 167 168
  // 单独测试例截图
  // '/pages/API/resize-observer/resize-observer',
  // 单独测试例截图
  // '/pages/API/map/map',
DCloud-WZF's avatar
DCloud-WZF 已提交
169 170 171

  // CSS
  '/pages/CSS/background/background-color',
172 173
  // 单独测试例中截图
  // '/pages/CSS/background/background-image',
174
  // '/pages/CSS/border/border',
DCloud-WZF's avatar
DCloud-WZF 已提交
175
  '/pages/CSS/border/border-color',
176 177
  '/pages/CSS/border/border-top',
  '/pages/CSS/border/border-bottom',
DCloud-WZF's avatar
DCloud-WZF 已提交
178 179
  '/pages/CSS/border/border-left',
  '/pages/CSS/border/border-right',
180
  '/pages/CSS/border/border-radius',
DCloud-WZF's avatar
DCloud-WZF 已提交
181 182
  '/pages/CSS/border/border-style',
  '/pages/CSS/border/border-width',
183 184 185 186
  '/pages/CSS/border/complex-border/complex-border',
  // 单独测试例中截图
  // '/pages/CSS/border/dynamic-border',
  '/pages/CSS/box-shadow/box-shadow',
DCloud-WZF's avatar
DCloud-WZF 已提交
187 188
  '/pages/CSS/display/flex',
  '/pages/CSS/display/none',
189
  '/pages/CSS/flex/flex',
DCloud-WZF's avatar
DCloud-WZF 已提交
190 191 192 193 194 195 196 197 198 199
  '/pages/CSS/flex/align-content',
  '/pages/CSS/flex/align-items',
  '/pages/CSS/flex/flex-basis',
  '/pages/CSS/flex/flex-direction',
  '/pages/CSS/flex/flex-flow',
  '/pages/CSS/flex/flex-grow',
  '/pages/CSS/flex/flex-shrink',
  '/pages/CSS/flex/justify-content',
  '/pages/CSS/layout/height',
  '/pages/CSS/layout/min-height',
200
  '/pages/CSS/layout/max-height',
DCloud-WZF's avatar
DCloud-WZF 已提交
201
  '/pages/CSS/layout/min-width',
202
  '/pages/CSS/layout/max-width',
DCloud-WZF's avatar
DCloud-WZF 已提交
203 204 205
  '/pages/CSS/layout/position',
  '/pages/CSS/layout/width',
  '/pages/CSS/layout/z-index',
206 207 208
  '/pages/CSS/layout/visibility',
  '/pages/CSS/margin/margin',
  '/pages/CSS/margin/margin-top',
DCloud-WZF's avatar
DCloud-WZF 已提交
209 210 211
  '/pages/CSS/margin/margin-bottom',
  '/pages/CSS/margin/margin-left',
  '/pages/CSS/margin/margin-right',
212 213
  '/pages/CSS/padding/padding',
  '/pages/CSS/padding/padding-top',
DCloud-WZF's avatar
DCloud-WZF 已提交
214 215 216
  '/pages/CSS/padding/padding-bottom',
  '/pages/CSS/padding/padding-left',
  '/pages/CSS/padding/padding-right',
217 218
  // 单独测试例中截图
  // '/pages/CSS/overflow/overflow',
DCloud-WZF's avatar
DCloud-WZF 已提交
219
  '/pages/CSS/text/color',
220 221 222 223
  // 网络资源加载,单独测试例截图
  // '/pages/CSS/text/font-family',
  // 单独测试例截图
  // '/pages/CSS/text/font-size',
DCloud-WZF's avatar
DCloud-WZF 已提交
224 225 226 227 228 229
  '/pages/CSS/text/font-style',
  '/pages/CSS/text/font-weight',
  '/pages/CSS/text/letter-spacing',
  '/pages/CSS/text/line-height',
  '/pages/CSS/text/text-align',
  '/pages/CSS/text/text-overflow',
DCloud-WZF's avatar
DCloud-WZF 已提交
230
  '/pages/CSS/text/text-decoration-line',
231 232
  // 单独测试例截图
  // '/pages/CSS/transition/transition',
233
  '/pages/CSS/pointer-events/pointer-events',
234 235 236 237 238 239 240 241 242
  // 单独测试例截图
  // '/pages/CSS/transform/translate',
  // 单独测试例截图
  // '/pages/CSS/transform/scale',
  // 单独测试例截图
  // '/pages/CSS/transform/rotate',
  // 单独测试例截图
  // '/pages/CSS/variable/variable',
  '/pages/CSS/overflow/overflow-visible-event',
DCloud-WZF's avatar
DCloud-WZF 已提交
243 244

  // template
245
  // 网络资源加载,单独测试例截图
246
  // '/pages/template/list-news/list-news',
247 248 249 250 251 252 253
  // 依赖网络资源加载
  // '/pages/template/list-news/detail/detail',
  '/pages/template/drop-card/drop-card',
  '/pages/template/swiper-list/swiper-list',
  '/pages/template/swiper-list2/swiper-list2',
  '/pages/template/swiper-vertical-video/swiper-vertical-video',
  '/pages/template/scroll-fold-nav/scroll-fold-nav',
254 255
  '/pages/template/custom-refresher/custom-refresher',
  '/pages/template/half-screen/half-screen',
256 257
  // 动态内容
  // '/pages/template/long-list/long-list',
258 259
  // 动态内容
  // '/pages/template/long-list2/long-list2',
260
  '/pages/template/long-list-nested/long-list-nested',
261
  '/pages/template/pull-zoom-image/pull-zoom-image',
262 263 264 265
  '/pages/template/navbar-lite/navbar-lite',
  '/pages/template/custom-tab-bar/custom-tab-bar',
  // 动态内容
  // '/pages/template/calendar/calendar',
266 267
  // '/pages/template/schema/schema',
  // '/uni_modules/uni-pay-x/pages/success/success',
268 269
  // 依赖 onload 参数获取 web-view src
  // '/uni_modules/uni-pay-x/pages/ad-interactive-webview/ad-interactive-webview',
270
  // '/uni_modules/uni-pay-x/pages/pay-desk/pay-desk',
271 272
  '/pages/template/custom-long-list/custom-long-list',
  '/pages/template/test-background-color-content/test-background-color-content',
DCloud-WZF's avatar
DCloud-WZF 已提交
273
  '/pages/template/slider-100/slider-100',
274 275 276 277 278 279
]

if (isAndroid && isWeb) {
  pages.push(
    '/pages/API/get-battery-info/get-battery-info',
  )
280 281 282 283 284 285 286 287 288 289 290 291
}

if(!isMP) {
  pages.push(
    '/pages/component/list-view/list-view',
    '/pages/component/list-view/list-view-multiplex-input',
    '/pages/component/list-view/list-view-multiplex-video',
    '/pages/component/list-view/list-view-children-in-slot',
    '/pages/template/schema/schema',
    '/uni_modules/uni-pay-x/pages/success/success',
    '/uni_modules/uni-pay-x/pages/pay-desk/pay-desk'
  )
292
}
293 294

if (isApp && !isAppWebview) {
DCloud-WZF's avatar
DCloud-WZF 已提交
295 296
  pages.push(
    '/pages/API/element-draw/element-draw',
297 298 299 300 301 302 303
    '/pages/API/get-file-system-manager/get-file-system-manager',
    '/pages/API/env/env',
    '/pages/API/get-system-setting/get-system-setting',
    '/pages/API/element-takesnapshot/element-takesnapshot',
    '/pages/API/get-app-authorize-setting/get-app-authorize-setting',
    '/pages/API/save-image-to-photos-album/save-image-to-photos-album',
    '/pages/API/save-video-to-photos-album/save-video-to-photos-album',
DCloud-WZF's avatar
DCloud-WZF 已提交
304
    '/pages/API/facial-recognition-meta-info/facial-recognition-meta-info',
305 306
    // 进入页面崩溃,暂时规避
    // '/pages/API/get-univerify-manager/get-univerify-manager',
307 308
    '/pages/API/request-payment/request-payment',
    '/pages/API/theme-change/theme-change',
309
    '/pages/API/share-with-system/share-with-system',
310
    '/pages/template/scroll-sticky/scroll-sticky'
DCloud-WZF's avatar
DCloud-WZF 已提交
311
  )
312 313
}

314 315 316 317 318 319
if (isAndroid && !isAppWebview) {
  pages.push(
    '/pages/API/exit/exit',
    '/pages/API/install-apk/install-apk',
    '/pages/API/get-image-info/get-image-info',
    '/pages/API/get-video-info/get-video-info',
DCloud-WZF's avatar
DCloud-WZF 已提交
320
    '/pages/API/create-rewarded-video-ad/create-rewarded-video-ad',
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
    '/pages/API/create-request-permission-listener/create-request-permission-listener',
    '/pages/API/compress-image/compress-image',
    '/pages/API/compress-video/compress-video',
  )
}


if (isWeb) {
  pages.push(
    '/pages/component/movable-view/movable-view',
    '/pages/component/label/label',
    '/pages/component/picker/picker',
    '/pages/API/get-image-info/get-image-info',
    '/pages/API/get-video-info/get-video-info',
    '/pages/API/make-phone-call/make-phone-call',
DCloud-WZF's avatar
DCloud-WZF 已提交
336 337 338
    '/pages/API/create-inner-audio-context/create-inner-audio-context',
    '/pages/API/create-inner-audio-context/inner-audio-format',
    '/pages/API/create-inner-audio-context/inner-audio-path',
339
    '/pages/API/clipboard/clipboard',
DCloud-WZF's avatar
DCloud-WZF 已提交
340
    '/pages/API/compass/compass',
341
    '/pages/component/canvas/canvas',
DCloud-WZF's avatar
DCloud-WZF 已提交
342
    '/pages/component/canvas/canvas/ball',
343
    '/pages/template/browser-element/browser-element',
344 345 346
  )
}

DCloud-WZF's avatar
DCloud-WZF 已提交
347
let page;
348 349 350 351 352 353 354 355
let windowInfo

async function getWindowInfo() {
  const windowInfoPage = await program.reLaunch('/pages/API/get-window-info/get-window-info')
  await windowInfoPage.waitFor(600);
  return await windowInfoPage.callMethod('jest_getWindowInfo')
}

356 357 358 359 360 361 362 363
function getWaitForTagName(pagePath) {
  if (pagePath === '/pages/component/list-view/list-view-multiplex-input') {
    return 'input'
  }
  if (pagePath === '/pages/component/list-view/list-view-multiplex-video') {
    return 'video'
  }
  if (
364
    pagePath === '/pages/component/global-events/transition-events' ||
365 366 367 368 369
    pagePath === '/pages/API/env/env'
  ) {
    return 'text'
  }
  if (
370 371
    pagePath === '/pages/component/unicloud-db/unicloud-db/contacts/edit' ||
    pagePath === '/pages/component/unicloud-db/unicloud-db/contacts/detail'
372 373 374 375 376 377 378 379 380
  ) {
    return 'scroll-view'
  }
  if (pagePath === '/pages/API/get-file-system-manager/get-file-system-manager') {
    return 'button'
  }
  return 'view'
}

DCloud-WZF's avatar
DCloud-WZF 已提交
381
describe("page screenshot test", () => {
DCloud-WZF's avatar
DCloud-WZF 已提交
382 383 384 385 386 387 388
  if (platformInfo.indexOf('safari') !== -1) {
    it('暂时规避 safari 截图测试', () => {
      expect(1).toBe(1)
    })
    return
  }

DCloud-WZF's avatar
DCloud-WZF 已提交
389 390 391 392
  beforeAll(async () => {
    console.log("page screenshot test start");
  });
  beforeEach(async () => {
393 394 395
    const currentPagePath = pages[pageIndex]
    page = await program.reLaunch(currentPagePath);
    await page.waitFor(getWaitForTagName(currentPagePath));
DCloud-WZF's avatar
DCloud-WZF 已提交
396 397 398 399 400 401 402 403
  });
  afterEach(() => {
    pageIndex++;
  });
  afterAll(() => {
    console.log("page screenshot test finish");
  });
  test.each(pages)("%s", async () => {
404 405
    const currentPagePath = pages[pageIndex]
    console.log("Taking screenshot: ", pageIndex, currentPagePath);
406
    let fullPage = true;
407 408 409 410

    const screenshotParams = {
      fullPage
    }
411
    if (!fullPage && !isAppWebview) {
412 413
      if (!windowInfo) {
        windowInfo = await getWindowInfo()
414 415
        page = await program.reLaunch(currentPagePath);
        await page.waitFor(getWaitForTagName(currentPagePath));
416
      }
417
      let offsetY = '0'
418
      if (isAndroid) {
419
        offsetY = `${windowInfo.statusBarHeight + 44}`
420
      }
421
      if (isIos) {
422 423 424 425 426 427
        offsetY = `${windowInfo.safeAreaInsets.top + 44}`
      }
      screenshotParams.offsetY = offsetY
    }

    const image = await program.screenshot(screenshotParams);
428 429
    expect(image).toSaveImageSnapshot({
      customSnapshotIdentifier() {
430
        return `__pages_test__/${currentPagePath.replace(/\//g, "-").substring(1)}`
431
      }
DCloud-WZF's avatar
DCloud-WZF 已提交
432
    })
433
    await page.waitFor(800);
DCloud-WZF's avatar
DCloud-WZF 已提交
434
  });
435
});