show-toast.test.js 2.9 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
    }
  })

56 57 58 59 60 61 62
  it("icon=none-mask=true-toast-test", async () => {
    await page.setData({maskSelect: true})
    await page.callMethod('toast3Tap')
    await page.waitFor(300);
    await toScreenshot('icon=none-mask=true-toast-image')
  })

Anne_LXM's avatar
Anne_LXM 已提交
63 64 65 66 67 68
  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
杜庆泉 已提交
69 70
  })

Anne_LXM's avatar
Anne_LXM 已提交
71 72 73 74 75 76 77 78 79
  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
杜庆泉 已提交
80 81
  })

Anne_LXM's avatar
Anne_LXM 已提交
82 83 84 85 86 87 88 89 90 91 92
  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);
93
      await toScreenshot(`toast-position-${positionsText}`)
Anne_LXM's avatar
Anne_LXM 已提交
94 95 96
    }
  })

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