pages.test.js 7.1 KB
Newer Older
DCloud-WZF's avatar
DCloud-WZF 已提交
1 2 3 4 5 6 7 8 9
let pageIndex = 0
const pages = [
  // component
  '/pages/component/button/button',
  '/pages/component/checkbox/checkbox',
  '/pages/component/general-attribute/general-attribute',
  '/pages/component/general-event/general-event',
  '/pages/component/image/image-format',
  // '/pages/component/image/image-large', // 截图过大
10
  // '/pages/component/image/image-mode', // 判断CPU类型,单独测试例截图
DCloud-WZF's avatar
DCloud-WZF 已提交
11 12 13
  // '/pages/component/image/image-path', // 网络资源加载,单独测试例截图
  '/pages/component/image/image',
  // '/pages/component/input/input', // 自动获取焦点,单独测试例截图
14 15 16
  '/pages/component/list-view/list-view',
  '/pages/component/scroll-view/scroll-view-custom-refresher-props',
  '/pages/component/scroll-view/scroll-view-refresher-props',
DCloud-WZF's avatar
DCloud-WZF 已提交
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
  '/pages/component/navigator/navigate',
  '/pages/component/navigator/navigator',
  '/pages/component/navigator/redirect',
  // '/pages/component/picker-view/picker-view', //动态内容
  '/pages/component/progress/progress',
  '/pages/component/radio/radio',
  '/pages/component/rich-text/rich-text-complex',
  '/pages/component/rich-text/rich-text-tags',
  '/pages/component/rich-text/rich-text',
  '/pages/component/slider/slider',
  '/pages/component/slider-100/slider-100',
  '/pages/component/swiper/swiper',
  '/pages/component/switch/switch',
  '/pages/component/text/text-props',
  '/pages/component/text/text',
  '/pages/component/textarea/textarea',
  // '/pages/component/video/video',
  '/pages/component/view/view',
  // '/pages/component/web-view/web-view', // 动态内容
  // '/pages/component/web-view-local/web-view-local', // 依赖加载完成回调,单独测试例截图
  '/pages/component/general-event/transition-event',

  // CSS
  '/pages/CSS/background/background-color',
  '/pages/CSS/border/complex-border/complex-border',
  '/pages/CSS/border/border-bottom',
  '/pages/CSS/border/border-color',
  '/pages/CSS/border/border-left',
  '/pages/CSS/border/border-radius',
  '/pages/CSS/border/border-right',
  '/pages/CSS/border/border-style',
  '/pages/CSS/border/border-top',
  '/pages/CSS/border/border-width',
50 51
  '/pages/CSS/border/border',
  '/pages/CSS/border/dynamic-border',
DCloud-WZF's avatar
DCloud-WZF 已提交
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
  // '/pages/CSS/box-shadow/box-shadow',
  '/pages/CSS/display/flex',
  '/pages/CSS/display/none',
  '/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/flex',
  '/pages/CSS/flex/justify-content',
  '/pages/CSS/layout/height',
  '/pages/CSS/layout/max-height',
  '/pages/CSS/layout/max-width',
  '/pages/CSS/layout/min-height',
  '/pages/CSS/layout/min-width',
  '/pages/CSS/layout/position',
  '/pages/CSS/layout/visibility',
  '/pages/CSS/layout/width',
  '/pages/CSS/layout/z-index',
  '/pages/CSS/margin/margin-bottom',
  '/pages/CSS/margin/margin-left',
  '/pages/CSS/margin/margin-right',
  '/pages/CSS/margin/margin-top',
  '/pages/CSS/margin/margin',
  '/pages/CSS/padding/padding-bottom',
  '/pages/CSS/padding/padding-left',
  '/pages/CSS/padding/padding-right',
  '/pages/CSS/padding/padding-top',
  '/pages/CSS/padding/padding',
  '/pages/CSS/text/color',
  // '/pages/CSS/text/font-family', // 网络资源加载,单独测试例截图
  '/pages/CSS/text/font-size',
  '/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-decoration-line',
  '/pages/CSS/text/text-overflow',
  '/pages/CSS/transform/rotate',
  '/pages/CSS/transform/scale',
  '/pages/CSS/transform/translate',
96
  '/pages/CSS/transition/transition',
97
  '/pages/CSS/pointer-events/pointer-events',
DCloud-WZF's avatar
DCloud-WZF 已提交
98 99 100 101 102 103 104 105 106

  // tabBar  //改动频繁,不再测试
  // '/pages/tabBar/API',
  // '/pages/tabBar/component',
  // '/pages/tabBar/CSS',
  // '/pages/tabBar/template',

  // template
  // '/pages/template/calendar/calendar', // 动态内容
107 108
  '/pages/template/custom-refresher/custom-refresher',
  '/pages/template/custom-tab-bar/custom-tab-bar',
DCloud-WZF's avatar
DCloud-WZF 已提交
109
  // '/pages/template/drop-card/drop-card',
110
  '/pages/template/half-screen/half-screen',
DCloud-WZF's avatar
DCloud-WZF 已提交
111 112
  // '/pages/template/list-news/list-news', // 网络资源加载,单独测试例截图
  // '/pages/template/long-list/long-list', // 动态内容
113 114 115
  '/pages/template/navbar-lite/navbar-lite',
  '/pages/template/pull-zoom-image/pull-zoom-image',
  '/pages/template/scroll-fold-nav/scroll-fold-nav',
雪洛's avatar
雪洛 已提交
116
  // '/pages/template/scroll-sticky/scroll-sticky',
117 118
  '/pages/template/swiper-list/swiper-list',
  '/pages/template/swiper-list2/swiper-list2',
DCloud-WZF's avatar
DCloud-WZF 已提交
119 120 121 122 123
  // '/pages/template/swiper-vertical-video/swiper-vertical-video'

  // api
  // '/pages/API/element-draw/element-draw',
]
124 125

const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
126
if ((platformInfo.startsWith('android') || platformInfo.startsWith('ios')) && !process.env.UNI_AUTOMATOR_APP_WEBVIEW) {
DCloud-WZF's avatar
DCloud-WZF 已提交
127 128 129
  // 规避 web 端不支持页面
  pages.push(
    '/pages/API/element-draw/element-draw',
雪洛's avatar
雪洛 已提交
130
    '/pages/template/scroll-sticky/scroll-sticky',
DCloud-WZF's avatar
DCloud-WZF 已提交
131
  )
132 133 134 135 136 137 138 139
}

// 设置position: fixed的页面不能截取完整内容
const notFullPages = [
  '/pages/CSS/layout/position',
  '/pages/CSS/layout/z-index'
]

DCloud-WZF's avatar
DCloud-WZF 已提交
140
let page;
141 142 143 144 145 146 147 148
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')
}

DCloud-WZF's avatar
DCloud-WZF 已提交
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
describe("page screenshot test", () => {
  beforeAll(async () => {
    console.log("page screenshot test start");
  });
  beforeEach(async () => {
    page = await program.reLaunch(pages[pageIndex]);
    await page.waitFor(1000);
  });
  afterEach(() => {
    pageIndex++;
  });
  afterAll(() => {
    console.log("page screenshot test finish");
  });
  test.each(pages)("%s", async () => {
    console.log("Taking screenshot: ", pageIndex, pages[pageIndex]);
165 166 167
    let fullPage = true;
    if (notFullPages.includes(pages[pageIndex])) {
      fullPage = false;
168
    }
169 170 171 172 173

    const screenshotParams = {
      fullPage
    }
    if (!fullPage && !process.env.UNI_AUTOMATOR_APP_WEBVIEW) {
174 175 176 177 178
      if (!windowInfo) {
        windowInfo = await getWindowInfo()
        page = await program.reLaunch(pages[pageIndex]);
        await page.waitFor(1000);
      }
179 180
      let offsetY = '0'
      if (process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('android')) {
181
        offsetY = `${windowInfo.statusBarHeight + 44}`
182 183 184 185 186 187 188 189
      }
      if (process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('ios')) {
        offsetY = `${windowInfo.safeAreaInsets.top + 44}`
      }
      screenshotParams.offsetY = offsetY
    }

    const image = await program.screenshot(screenshotParams);
190 191 192 193
    expect(image).toSaveImageSnapshot({
      customSnapshotIdentifier() {
        return `__pages_test__/${pages[pageIndex].replace(/\//g, "-").substring(1)}`
      }
DCloud-WZF's avatar
DCloud-WZF 已提交
194
    })
DCloud-WZF's avatar
DCloud-WZF 已提交
195 196
    await page.waitFor(500);
  });
197
});