web-view-local.test.js 3.2 KB
Newer Older
DCloud-WZF's avatar
DCloud-WZF 已提交
1 2 3
// uni-app自动化测试教程: uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/

describe('component-native-web-view', () => {
4 5 6 7 8 9
  if (!process.env.uniTestPlatformInfo.startsWith('web') && !process.env.UNI_AUTOMATOR_APP_WEBVIEW) {
    let page;
    beforeAll(async () => {
      page = await program.reLaunch('/pages/component/web-view-local/web-view-local');
      await page.waitFor(1000);
    });
DCloud-WZF's avatar
DCloud-WZF 已提交
10

11 12 13
    it('check_load_url', async () => {
      expect(await page.data('loadError')).toBe(false)
    });
DCloud-WZF's avatar
DCloud-WZF 已提交
14

15
    it('screenshot', async () => {
DCloud-WZF's avatar
DCloud-WZF 已提交
16 17 18 19 20 21
      await page.waitFor(async () => {
        return await page.data('loadFinish') === true;
      });
      const image = await program.screenshot({
        fullPage: true
      });
22
      expect(image).toSaveImageSnapshot();
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
    });

    it('test event download', async () => {
      await page.setData({
        autoTest: true
      });
      await page.callMethod('testEventDownload');
      await page.waitFor(async () => {
        return await page.data('eventDownload');
      });
      if (process.env.uniTestPlatformInfo.startsWith('ios')) {
        expect(await page.data('eventDownload')).toEqual({
          tagName: 'WEB-VIEW',
          type: 'download',
          url: 'https://web-ext-storage.dcloud.net.cn/uni-app-x/pkg/hello-uniappx.apk',
          userAgent: `uni-app-x/${process.env.HX_Version.split('-')[0].split('.').slice(0, 2).join('.')}`,
          contentDisposition: '',
          mimetype: 'application/vnd.android.package-archive',
          contentLength: 27317517
        });
        return;
      }
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
      const infos = process.env.uniTestPlatformInfo.split(' ');
      const version = parseInt(infos[infos.length - 1]);
      if (version > 8) {
        expect(await page.data('eventDownload')).toEqual({
          tagName: 'WEB-VIEW',
          type: 'download',
          url: 'https://web-ext-storage.dcloud.net.cn/uni-app-x/pkg/hello-uniappx.apk',
          userAgent: `uni-app-x/${process.env.HX_Version.split('-')[0].split('.').slice(0, 2).join('.')}`,
          contentDisposition: `attachment; filename="hello-uniappx.apk"; filename*=utf-8''hello-uniappx.apk`,
          mimetype: 'application/vnd.android.package-archive',
          contentLength: 27317517
        });
      } else { // 低版本webview内核,部分属性无有效值
        expect(await page.data('eventDownload')).toEqual({
          tagName: 'WEB-VIEW',
          type: 'download',
          url: 'https://web-ext-storage.dcloud.net.cn/uni-app-x/pkg/hello-uniappx.apk',
          userAgent: '',
          contentDisposition: '',
          mimetype: '',
          contentLength: -1
        });
      }
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
    });

    it('test event message', async () => {
      await page.callMethod('testEventMessage');
      await page.waitFor(async () => {
        return await page.data('eventMessage');
      });
      expect(await page.data('eventMessage')).toEqual({
        tagName: 'WEB-VIEW',
        type: 'message',
        data: [{
          action: 'message'
        }]
      });
      await page.setData({
        autoTest: false
      });
    });
  } else {
    // TODO: web 端暂不支持
    it('web', async () => {
      expect(1).toBe(1)
    })
  }
DCloud-WZF's avatar
DCloud-WZF 已提交
92
});