pages.test.js 15.5 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
  // 单独测试例截图
  // '/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',
116
  '/pages/API/navigator/new-page/onLoad',
117 118 119 120 121 122
  // 下拉刷新,不进行截图
  '/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 已提交
123
  '/pages/API/create-selector-query/create-selector-query',
124 125
  '/pages/API/storage/storage',
  // 单独测试例截图
126
  // '/pages/API/show-action-sheet/show-action-sheet',
127
  // 单独测试例截图
128 129
  // '/pages/API/show-modal/show-modal',
  '/pages/API/show-loading/show-loading',
130
  // 单独测试例截图
131
  // '/pages/API/show-toast/show-toast',
132 133 134 135 136 137 138 139 140 141 142
  // 单独测试例截图
  // '/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',
143
  '/pages/API/websocket/socketTask',
144
  // 页面销毁时会关闭socket连接,所以规避
145
  // '/pages/API/websocket/websocket',
146 147 148 149
  '/pages/API/unicloud/unicloud/cloud-function',
  '/pages/API/unicloud/unicloud/cloud-object',
  '/pages/API/unicloud/unicloud/database',
  '/pages/API/unicloud/unicloud/cloud-storage',
150 151 152 153 154 155 156 157 158
  '/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',
159
  // '/pages/API/get-battery-info/get-battery-info',
160 161
  '/pages/API/get-window-info/get-window-info',
  '/pages/API/rpx2px/rpx2px',
162 163
  '/pages/API/request-payment/request-payment/request-payment-uni-pay',
  '/pages/API/request-payment/request-payment/order-detail',
164 165 166 167
  // 单独测试例截图
  // '/pages/API/resize-observer/resize-observer',
  // 单独测试例截图
  // '/pages/API/map/map',
DCloud-WZF's avatar
DCloud-WZF 已提交
168 169 170

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

  // template
244
  // 网络资源加载,单独测试例截图
245
  // '/pages/template/list-news/list-news',
246 247 248 249 250 251 252
  // 依赖网络资源加载
  // '/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',
253 254
  '/pages/template/custom-refresher/custom-refresher',
  '/pages/template/half-screen/half-screen',
255 256
  // 动态内容
  // '/pages/template/long-list/long-list',
257 258
  // 动态内容
  // '/pages/template/long-list2/long-list2',
259
  '/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',
273 274 275 276 277 278 279
]

if (isAndroid && isWeb) {
  pages.push(
    '/pages/API/get-battery-info/get-battery-info',
  )
}
280 281

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

300 301 302 303 304 305
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 已提交
306
    '/pages/API/create-rewarded-video-ad/create-rewarded-video-ad',
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
    '/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/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 已提交
323 324 325
    '/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',
326
    '/pages/API/clipboard/clipboard',
DCloud-WZF's avatar
DCloud-WZF 已提交
327
    '/pages/API/compass/compass',
328
    '/pages/component/canvas/canvas',
DCloud-WZF's avatar
DCloud-WZF 已提交
329
    '/pages/component/canvas/canvas/ball',
330
    '/pages/template/browser-element/browser-element',
331 332 333
  )
}

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

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

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

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

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