pages.test.js 15.6 KB
Newer Older
1 2 3 4 5 6 7
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')
const isAppWebview = !!process.env.UNI_AUTOMATOR_APP_WEBVIEW

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

DCloud-WZF's avatar
DCloud-WZF 已提交
16
  // component
17 18 19 20 21 22 23
  '/pages/component/view/view',
  // 单独测试例截图
  // 'pages/component/scroll-view/scroll-view',
  // 单独测试例截图
  // '/pages/component/scroll-view/scroll-view-refresher',
  // 单独测试例截图
  // '/pages/component/scroll-view/scroll-view-props',
24
  '/pages/component/scroll-view/scroll-view-refresher-props',
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
  '/pages/component/scroll-view/scroll-view-custom-refresher-props',
  '/pages/component/swiper/swiper',
  '/pages/component/list-view/list-view',
  // 单独测试例截图
  // '/pages/component/list-view/list-view-refresh',
  // 单独测试例截图
  // '/pages/component/list-view/list-view-multiplex',
  '/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/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 已提交
45
  '/pages/component/progress/progress',
46 47 48
  '/pages/component/form/form',
  '/pages/component/button/button',
  '/pages/component/button/buttonstatus',
DCloud-WZF's avatar
DCloud-WZF 已提交
49
  '/pages/component/radio/radio',
50 51 52 53
  '/pages/component/checkbox/checkbox',
  // 自动获取焦点,单独测试例截图
  // '/pages/component/input/input',
  '/pages/component/textarea/textarea',
DCloud-WZF's avatar
DCloud-WZF 已提交
54
  '/pages/component/slider/slider',
55 56 57
  '/pages/component/slider/slider-in-swiper',
  //动态内容
  // '/pages/component/picker-view/picker-view',
DCloud-WZF's avatar
DCloud-WZF 已提交
58
  '/pages/component/switch/switch',
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
  '/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',
  // 依赖加载完成回调,单独测试例截图
75
  // '/pages/component/web-view/web-view/web-view-local',
76
  // 动态内容
77
  // '/pages/component/unicloud-db/unicloud-db',
78
  '/pages/component/unicloud-db/unicloud-db/contacts/add',
79
  // 动态内容
80
  // '/pages/component/unicloud-db/unicloud-db/contacts/edit',
81
  // 动态内容
82
  // '/pages/component/unicloud-db/unicloud-db/contacts/detail',
83 84
  // 动态内容
  // '/pages/component/unicloud-db/unicloud-db/mixin-datacom/mixin-datacom',
85
  // 单独测试例截图
86 87 88 89
  // '/pages/component/global-properties/global-properties',
  '/pages/component/global-events/global-events',
  '/pages/component/global-events/transition-events',
  '/pages/component/global-events/touch-events',
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
  // 单独测试例截图
  // '/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/list-view-refresh',
  // 单独测试例截图
  // '/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 160 161 162
  '/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',
  '/pages/API/get-battery-info/get-battery-info',
  '/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 174
  // 单独测试例中截图
  // '/pages/CSS/background/background-image',
  '/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',
230 231 232
  '/pages/CSS/text/text-decoration-line',
  // 单独测试例截图
  // '/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 258 259
  // 动态内容
  // '/pages/template/long-list/long-list',
  '/pages/template/long-list2/long-list2',
  '/pages/template/long-list-nested/long-list-nested',
260
  '/pages/template/pull-zoom-image/pull-zoom-image',
261 262 263 264 265 266 267 268 269 270 271
  '/pages/template/navbar-lite/navbar-lite',
  '/pages/template/custom-tab-bar/custom-tab-bar',
  // 动态内容
  // '/pages/template/calendar/calendar',
  '/pages/template/schema/schema',
  '/uni_modules/uni-pay-x/pages/success/success',
  // 依赖 onload 参数获取 web-view src
  // '/uni_modules/uni-pay-x/pages/ad-interactive-webview/ad-interactive-webview',
  '/uni_modules/uni-pay-x/pages/pay-desk/pay-desk',
  '/pages/template/custom-long-list/custom-long-list',
  '/pages/template/test-background-color-content/test-background-color-content',
DCloud-WZF's avatar
DCloud-WZF 已提交
272
  '/pages/template/slider-100/slider-100',
DCloud-WZF's avatar
DCloud-WZF 已提交
273
]
274 275

if (isApp && !isAppWebview) {
DCloud-WZF's avatar
DCloud-WZF 已提交
276 277
  pages.push(
    '/pages/API/element-draw/element-draw',
278 279 280 281 282 283 284
    '/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 已提交
285
    '/pages/API/facial-recognition-meta-info/facial-recognition-meta-info',
286 287
    // 进入页面崩溃,暂时规避
    // '/pages/API/get-univerify-manager/get-univerify-manager',
288 289
    '/pages/API/request-payment/request-payment',
    '/pages/API/theme-change/theme-change',
雪洛's avatar
雪洛 已提交
290
    '/pages/template/scroll-sticky/scroll-sticky',
DCloud-WZF's avatar
DCloud-WZF 已提交
291
  )
292 293
}

294 295 296 297 298 299
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 已提交
300
    '/pages/API/create-rewarded-video-ad/create-rewarded-video-ad',
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319
    '/pages/API/create-request-permission-listener/create-request-permission-listener',
    '/pages/API/compress-image/compress-image',
    '/pages/API/compress-video/compress-video',
    '/pages/template/share/share',
  )
}


if (isWeb) {
  pages.push(
    '/pages/component/movable-view/movable-view',
    '/pages/component/label/label',
    '/pages/component/picker/picker',
    '/pages/component/map/map',
    '/pages/component/cover-view/cover-view',
    '/pages/component/editor/editor',
    '/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 已提交
320 321 322
    '/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',
323
    '/pages/API/clipboard/clipboard',
DCloud-WZF's avatar
DCloud-WZF 已提交
324
    '/pages/API/compass/compass',
325
    '/pages/component/canvas/canvas',
DCloud-WZF's avatar
DCloud-WZF 已提交
326
    '/pages/component/canvas/canvas/ball',
327
    '/pages/template/browser-element/browser-element',
328 329 330
  )
}

DCloud-WZF's avatar
DCloud-WZF 已提交
331
let page;
332 333 334 335 336 337 338 339
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')
}

340 341 342 343 344 345 346 347
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 (
348
    pagePath === '/pages/component/global-events/transition-events' ||
349 350 351 352 353 354
    pagePath === '/pages/component/list-view/list-view-refresh' ||
    pagePath === '/pages/API/env/env'
  ) {
    return 'text'
  }
  if (
355 356
    pagePath === '/pages/component/unicloud-db/unicloud-db/contacts/edit' ||
    pagePath === '/pages/component/unicloud-db/unicloud-db/contacts/detail'
357 358 359 360 361 362 363 364 365
  ) {
    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 已提交
366
describe("page screenshot test", () => {
DCloud-WZF's avatar
DCloud-WZF 已提交
367 368 369 370 371 372 373
  if (platformInfo.indexOf('safari') !== -1) {
    it('暂时规避 safari 截图测试', () => {
      expect(1).toBe(1)
    })
    return
  }

DCloud-WZF's avatar
DCloud-WZF 已提交
374 375 376 377
  beforeAll(async () => {
    console.log("page screenshot test start");
  });
  beforeEach(async () => {
378 379 380
    const currentPagePath = pages[pageIndex]
    page = await program.reLaunch(currentPagePath);
    await page.waitFor(getWaitForTagName(currentPagePath));
DCloud-WZF's avatar
DCloud-WZF 已提交
381 382 383 384 385 386 387 388
  });
  afterEach(() => {
    pageIndex++;
  });
  afterAll(() => {
    console.log("page screenshot test finish");
  });
  test.each(pages)("%s", async () => {
389 390
    const currentPagePath = pages[pageIndex]
    console.log("Taking screenshot: ", pageIndex, currentPagePath);
391
    let fullPage = true;
392 393 394 395

    const screenshotParams = {
      fullPage
    }
396
    if (!fullPage && !isAppWebview) {
397 398
      if (!windowInfo) {
        windowInfo = await getWindowInfo()
399 400
        page = await program.reLaunch(currentPagePath);
        await page.waitFor(getWaitForTagName(currentPagePath));
401
      }
402
      let offsetY = '0'
403
      if (isAndroid) {
404
        offsetY = `${windowInfo.statusBarHeight + 44}`
405
      }
406
      if (isIos) {
407 408 409 410 411 412
        offsetY = `${windowInfo.safeAreaInsets.top + 44}`
      }
      screenshotParams.offsetY = offsetY
    }

    const image = await program.screenshot(screenshotParams);
413 414
    expect(image).toSaveImageSnapshot({
      customSnapshotIdentifier() {
415
        return `__pages_test__/${currentPagePath.replace(/\//g, "-").substring(1)}`
416
      }
DCloud-WZF's avatar
DCloud-WZF 已提交
417
    })
DCloud-WZF's avatar
DCloud-WZF 已提交
418 419
    await page.waitFor(500);
  });
420
});