image.test.js 2.2 KB
Newer Older
shutao-dc's avatar
shutao-dc 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13
// uni-app自动化测试教程: uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/

describe('component-native-image', () => {

    let page;
    beforeAll(async () => {
        page = await program.reLaunch('/pages/component/image/image');
        await page.waitFor(600);
    });

    it('check_image_load', async () => {
         expect(await page.data('loadError')).toBe(false)
    });
shutao-dc's avatar
shutao-dc 已提交
14 15 16 17 18 19 20 21 22

    it('check_image_load_url', async () => {
      await page.setData({
        loadError: false,
        imageSrc: 'https://request.dcloud.net.cn/api/http/contentType/image/png'
      })
      await page.waitFor(300);
      expect(await page.data('loadError')).toBe(false)
    })
雪洛's avatar
雪洛 已提交
23

shutao-dc's avatar
shutao-dc 已提交
24 25 26 27 28 29 30 31
    it('check_image_load_error', async () => {
      await page.setData({
        loadError: false,
        imageSrc: 'testerror.jpg'
      })
      await page.waitFor(300);
      expect(await page.data('loadError')).toBe(true)
    })
32

33
    if (process.env.uniTestPlatformInfo.startsWith('android') && !process.env.UNI_AUTOMATOR_APP_WEBVIEW) {
雪洛's avatar
雪洛 已提交
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
      it('check-cookie', async () => {
        await page.setData({
          autoTest: true,
          setCookieImage: 'https://cdn.dcloud.net.cn/img/shadow-grey.png'
        });
        await page.waitFor(1000);
        await page.setData({
          loadError: false,
          verifyCookieImage: 'https://request.dcloud.net.cn/img/shadow-grey.png'
        });
        await page.waitFor(1000);
        expect(await page.data('loadError')).toBe(false);
        await page.setData({
          autoTest: false
        });
      })
    }
51

52 53 54 55 56 57 58 59
    it('path-screenshot', async () => {
      const page = await program.navigateTo('/pages/component/image/image-path');
      await page.waitFor(3000);
      const image = await program.screenshot({
        fullPage: true
      })
      expect(image).toMatchImageSnapshot()
    });
60 61 62 63 64 65 66 67 68 69

    it('mode-screenshot', async () => {
      if (process.env.android_cpu_type === 'x86_64') return
      const page = await program.navigateTo('/pages/component/image/image-mode');
      await page.waitFor(1000);
      const image = await program.screenshot({
        fullPage: true
      })
      expect(image).toMatchImageSnapshot()
    });
shutao-dc's avatar
shutao-dc 已提交
70
});