show-toast.test.js 2.2 KB
Newer Older
杜庆泉's avatar
杜庆泉 已提交
1 2 3 4
// uni-app自动化测试教程: uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/

describe('API-toast', () => {
  let page;
5
  const isApp = process.env.UNI_OS_NAME === "android" || process.env.UNI_OS_NAME === "ios";
杜庆泉's avatar
杜庆泉 已提交
6
  beforeAll(async () => {
7
    page = await program.reLaunch('/pages/API/show-toast/show-toast')
Anne_LXM's avatar
Anne_LXM 已提交
8
    await page.waitFor("view");
杜庆泉's avatar
杜庆泉 已提交
9 10
  });

Anne_LXM's avatar
Anne_LXM 已提交
11
  async function toScreenshot(imgName) {
12
    if (isApp) {
13
      await page.waitFor(500);
14 15 16
      const res = await page.callMethod('jest_getWindowInfo')
      const windowHeight = res.windowHeight * res.pixelRatio;
      const windowWidth = res.windowWidth * res.pixelRatio;
杜庆泉's avatar
杜庆泉 已提交
17
      const image = await program.screenshot({
18
        deviceShot: true,
杜庆泉's avatar
杜庆泉 已提交
19 20 21
        area: {
          x: 0,
          y: 200,
22 23
          height: windowHeight - 200,
          width:windowWidth
杜庆泉's avatar
杜庆泉 已提交
24 25
        },
      });
Anne_LXM's avatar
Anne_LXM 已提交
26 27 28
      expect(image).toSaveImageSnapshot({customSnapshotIdentifier() {
        return imgName
      }})
杜庆泉's avatar
杜庆泉 已提交
29 30
    }else{
      const image = await program.screenshot({
31
        deviceShot: true,
杜庆泉's avatar
杜庆泉 已提交
32 33
        fullPage: true
      });
Anne_LXM's avatar
Anne_LXM 已提交
34 35 36
      expect(image).toSaveImageSnapshot({customSnapshotIdentifier() {
        return imgName
      }})
杜庆泉's avatar
杜庆泉 已提交
37
    }
Anne_LXM's avatar
Anne_LXM 已提交
38 39
    await page.waitFor(500);
  }
杜庆泉's avatar
杜庆泉 已提交
40

Anne_LXM's avatar
Anne_LXM 已提交
41 42
  it("onload-toast-test", async () => {
    await toScreenshot('toast-onload')
杜庆泉's avatar
杜庆泉 已提交
43 44
  })

Anne_LXM's avatar
Anne_LXM 已提交
45 46 47 48 49 50 51 52
  it("icon-toast-test", async () => {
    const icons = await page.$$('.radio-icon')
    for (let i = 0; i < icons.length; i++) {
      await icons[i].tap()
      const iconText = await icons[i].text()
      await page.callMethod('toast1Tap')
      await page.waitFor(100);
      await toScreenshot(`${iconText}`)
杜庆泉's avatar
杜庆泉 已提交
53 54 55
    }
  })

Anne_LXM's avatar
Anne_LXM 已提交
56 57 58 59 60 61
  it("image-toast-test", async () => {
    await page.setData({imageSelect: true})
    await page.waitFor(300);
    await page.callMethod('toast1Tap')
    await page.waitFor(300);
    await toScreenshot('toast-image')
杜庆泉's avatar
杜庆泉 已提交
62 63
  })

Anne_LXM's avatar
Anne_LXM 已提交
64 65 66 67 68 69 70 71 72
  it("duration-toast-test", async () => {
    await page.setData({intervalSelect: 4000})
    await page.callMethod('toast1Tap')
    await page.waitFor(2000);
    await toScreenshot('toast-duration-2000')
    await page.waitFor(1000);
    await page.callMethod('hideToast')
    await page.waitFor(300);
    await toScreenshot('toast-duration-end')
杜庆泉's avatar
杜庆泉 已提交
73 74 75
  })

});