web-view.test.js 2.4 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
  if (!process.env.uniTestPlatformInfo.startsWith('web') && !process.env.UNI_AUTOMATOR_APP_WEBVIEW) {
DCloud-WZF's avatar
DCloud-WZF 已提交
5 6 7 8 9 10 11 12 13
    let page;
    beforeAll(async () => {
      page = await program.reLaunch('/pages/component/web-view/web-view');
      await page.waitFor(3000);
    });

    it('check_load_url', async () => {
      expect(await page.data('loadError')).toBe(false)
    });
14 15 16 17 18 19

    it('test event loading load', async () => {
      await page.setData({
        autoTest: true
      });
      await page.callMethod('reload');
lizhongyi_'s avatar
lizhongyi_ 已提交
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
      await page.waitFor(100);
      if(process.env.uniTestPlatformInfo.toLowerCase().startsWith('ios')) {
        expect(await page.data('eventLoading')).toEqual({
          type: 'loading',
          src: 'https://www.dcloud.io/'
        });
      }else {
        expect(await page.data('eventLoading')).toEqual({
          tagName: 'WEB-VIEW',
          type: 'loading',
          src: 'https://www.dcloud.io/'
        });
      }

      await page.waitFor(1000);
      if(process.env.uniTestPlatformInfo.toLowerCase().startsWith('ios')) {
         expect(await page.data('eventLoad')).toEqual({
           type: 'load',
           src: 'https://www.dcloud.io/'
         });
      }else {
        expect(await page.data('eventLoad')).toEqual({
          tagName: 'WEB-VIEW',
          type: 'load',
          src: 'https://www.dcloud.io/'
        });
      }

48 49 50
    });

    it('test event error', async () => {
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 (process.env.uniTestPlatformInfo.startsWith('android') && version > 5) {
        await page.setData({
          src: 'https://www.dclou.io/uni-app-x'
        });
        await page.waitFor(500);
        expect(await page.data('eventError')).toEqual({
          tagName: 'WEB-VIEW',
          type: 'error',
          errCode: 100002,
          errMsg: 'page error',
          url: 'https://www.dclou.io',
          fullUrl: 'https://www.dclou.io/uni-app-x',
          src: 'https://www.dclou.io/uni-app-x'
        });
      }
68 69 70 71
      await page.setData({
        autoTest: false
      });
    });
DCloud-WZF's avatar
DCloud-WZF 已提交
72 73 74 75 76 77
  } else {
    // TODO: web 端暂不支持
    it('web', async () => {
      expect(1).toBe(1)
    })
  }
lizhongyi_'s avatar
lizhongyi_ 已提交
78
});