pages.test.js 15.3 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 59
  '/pages/component/slider-100/slider-100',
  '/pages/component/switch/switch',
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
  '/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',
  // 依赖加载完成回调,单独测试例截图
  // '/pages/component/web-view-local/web-view-local',
  // 动态内容
  // '/pages/component/unicloud-db-contacts/list',
  '/pages/component/unicloud-db-contacts/add',
80
  // 动态内容
81 82 83 84 85 86 87
  // '/pages/component/unicloud-db-contacts/edit',
  // 动态内容
  // '/pages/component/unicloud-db-contacts/detail',
  '/pages/component/mixin-datacom/mixin-datacom',
  // 单独测试例截图
  // '/pages/component/general-attribute/general-attribute',
  '/pages/component/general-event/general-event',
DCloud-WZF's avatar
DCloud-WZF 已提交
88
  '/pages/component/general-event/transition-event',
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
  '/pages/component/general-event/touch-event',
  // 单独测试例截图
  // '/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 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
  // 下拉刷新,不进行截图
  '/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',
  '/pages/API/nodes-info/nodes-info',
  '/pages/API/storage/storage',
  // 单独测试例截图
  // '/pages/API/action-sheet/action-sheet',
  // 单独测试例截图
  // '/pages/API/modal/modal',
  '/pages/API/loading/loading',
  // 单独测试例截图
  // '/pages/API/toast/toast',
  // 单独测试例截图
  // '/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',
  '/pages/API/websocket-socketTask/websocket-socketTask',
  // 页面销毁时会关闭socket连接,所以规避
  // '/pages/API/websocket-global/websocket-global',
  '/pages/API/unicloud-call-function/unicloud-call-function',
  '/pages/API/unicloud-import-object/unicloud-import-object',
  '/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/unicloud-file-api/unicloud-file-api',
  '/pages/API/unicloud-database/unicloud-database',
  '/pages/API/get-battery-info/get-battery-info',
  '/pages/API/get-window-info/get-window-info',
  '/pages/API/rpx2px/rpx2px',
  '/pages/API/request-payment-uni-pay/request-payment-uni-pay',
  '/pages/API/request-payment-uni-pay/order-detail',
  // 单独测试例截图
  // '/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
]
273 274

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

293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323
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',
    '/pages/API/rewarded-video-ad/rewarded-video-ad',
    '/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',
    '/pages/API/inner-audio/inner-audio',
    '/pages/API/inner-audio/inner-audio-format',
    '/pages/API/inner-audio/inner-audio-path',
    '/pages/API/clipboard/clipboard',
    '/pages/API/on-compass-change/on-compass-change',
324 325
    '/pages/component/canvas/canvas',
    '/pages/component/canvas/ball',
326
    '/pages/template/browser-element/browser-element',
327 328 329
  )
}

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

339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364
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 (
    pagePath === '/pages/component/general-event/transition-event' ||
    pagePath === '/pages/component/list-view/list-view-refresh' ||
    pagePath === '/pages/API/env/env'
  ) {
    return 'text'
  }
  if (
    pagePath === '/pages/component/unicloud-db-contacts/edit' ||
    pagePath === '/pages/component/unicloud-db-contacts/detail'
  ) {
    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 已提交
365 366 367 368 369
describe("page screenshot test", () => {
  beforeAll(async () => {
    console.log("page screenshot test start");
  });
  beforeEach(async () => {
370 371 372
    const currentPagePath = pages[pageIndex]
    page = await program.reLaunch(currentPagePath);
    await page.waitFor(getWaitForTagName(currentPagePath));
DCloud-WZF's avatar
DCloud-WZF 已提交
373 374 375 376 377 378 379 380
  });
  afterEach(() => {
    pageIndex++;
  });
  afterAll(() => {
    console.log("page screenshot test finish");
  });
  test.each(pages)("%s", async () => {
381 382
    const currentPagePath = pages[pageIndex]
    console.log("Taking screenshot: ", pageIndex, currentPagePath);
383
    let fullPage = true;
384 385 386
    const screenshotParams = {
      fullPage
    }
387
    if (!fullPage && !isAppWebview) {
388 389
      if (!windowInfo) {
        windowInfo = await getWindowInfo()
390 391
        page = await program.reLaunch(currentPagePath);
        await page.waitFor(getWaitForTagName(currentPagePath));
392
      }
393
      let offsetY = '0'
394
      if (isAndroid) {
395
        offsetY = `${windowInfo.statusBarHeight + 44}`
396
      }
397
      if (isIos) {
398 399 400 401 402 403
        offsetY = `${windowInfo.safeAreaInsets.top + 44}`
      }
      screenshotParams.offsetY = offsetY
    }

    const image = await program.screenshot(screenshotParams);
404 405
    expect(image).toSaveImageSnapshot({
      customSnapshotIdentifier() {
406
        return `__pages_test__/${currentPagePath.replace(/\//g, "-").substring(1)}`
407
      }
DCloud-WZF's avatar
DCloud-WZF 已提交
408
    })
DCloud-WZF's avatar
DCloud-WZF 已提交
409 410
    await page.waitFor(500);
  });
411
});