show-toast.test.js 2.6 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
  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);
52
      await toScreenshot(`${iconText}-toast`)
杜庆泉'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
  })

Anne_LXM's avatar
Anne_LXM 已提交
75 76 77 78 79 80 81 82 83 84 85
  if(process.env.uniTestPlatformInfo.startsWith('web')){
    return
  }

  it("position-toast-test", async () => {
    const positions = await page.$$('.radio-position')
    for (let i = 0; i < positions.length; i++) {
      await positions[i].tap()
      const positionsText = await positions[i].attribute('value')
      await page.callMethod('toast2Tap')
      await page.waitFor(100);
86
      await toScreenshot(`toast-position-${positionsText}`)
Anne_LXM's avatar
Anne_LXM 已提交
87 88 89
    }
  })

杜庆泉's avatar
杜庆泉 已提交
90
});