web-view.test.js 5.0 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
    let page;
6
    let start = 0;
DCloud-WZF's avatar
DCloud-WZF 已提交
7 8 9 10 11 12 13 14
    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)
    });
15

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
    it('test attr webview-styles', async () => {
      await page.setData({
        webview_styles: {
          progress: {
            color: '#FF0'
          }
        }
      });
      await page.waitFor(100);
      await page.callMethod('reload');
      await page.waitFor(100);
      await page.setData({
        webview_styles: {
          progress: {
            color: 'yellow'
          }
        }
      });
      await page.waitFor(100);
      await page.callMethod('reload');
36 37 38 39 40 41 42 43 44
    });

    it('test touch event', async () => {
      await page.setData({
        autoTest: true
      });
      const info = await page.callMethod('getWindowInfo');
      await program.tap({
        x: 1,
45
        y: info.statusBarHeight + 44 + 1
46
      });
47
      await page.waitFor(500);
48
      if(process.env.uniTestPlatformInfo.toLowerCase().startsWith('ios') == false) {
49
         expect(await page.data('isTouchEnable')).toBe(true);
50 51
      }

52
      await page.setData({
53 54
        pointerEvents: 'none',
        isTouchEnable: false
55 56 57 58
      });
      await page.waitFor(100);
      await program.tap({
        x: 10,
59
        y: info.statusBarHeight + 44 + 10
60
      });
61
      await page.waitFor(500);
62
      if(process.env.uniTestPlatformInfo.toLowerCase().startsWith('ios') == false) {
63
        expect(await page.data('isTouchEnable')).toBe(false);
64
      }
65 66 67
      await page.setData({
        pointerEvents: 'auto'
      });
68 69
    });

70
    it('test event loading load', async () => {
71 72 73 74 75
      await page.callMethod('reload');
      start = Date.now();
      await page.waitFor(async () => {
        return (await page.data('eventLoading')) || (Date.now() - start > 500);
      });
lizhongyi_'s avatar
lizhongyi_ 已提交
76
      if(process.env.uniTestPlatformInfo.toLowerCase().startsWith('ios')) {
77 78 79 80 81 82 83
        const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
        if(
          platformInfo.indexOf('14.5') != -1 ||
          platformInfo.indexOf('13.7') != -1 ||
          platformInfo.indexOf('12.4') != -1
          ){
            expect(1).toBe(1)
lizhongyi_'s avatar
lizhongyi_ 已提交
84
            return
85
        }
lizhongyi_'s avatar
lizhongyi_ 已提交
86
        expect(await page.data('eventLoading')).toEqual({
lizhongyi_'s avatar
lizhongyi_ 已提交
87
          "tagName": "WEB-VIEW",
lizhongyi_'s avatar
lizhongyi_ 已提交
88 89 90 91 92
          type: 'loading',
          src: 'https://www.dcloud.io/'
        });
      }else {
        expect(await page.data('eventLoading')).toEqual({
lizhongyi_'s avatar
lizhongyi_ 已提交
93
          tagName: 'WEB-VIEW',
lizhongyi_'s avatar
lizhongyi_ 已提交
94 95 96
          type: 'loading',
          src: 'https://www.dcloud.io/'
        });
97 98 99 100 101
      }
      start = Date.now();
      await page.waitFor(async () => {
        return (await page.data('eventLoad')) || (Date.now() - start > 5000);
      });
lizhongyi_'s avatar
lizhongyi_ 已提交
102 103
      if(process.env.uniTestPlatformInfo.toLowerCase().startsWith('ios')) {
         expect(await page.data('eventLoad')).toEqual({
lizhongyi_'s avatar
lizhongyi_ 已提交
104
           tagName: "WEB-VIEW",
lizhongyi_'s avatar
lizhongyi_ 已提交
105 106 107 108 109
           type: 'load',
           src: 'https://www.dcloud.io/'
         });
      }else {
        expect(await page.data('eventLoad')).toEqual({
lizhongyi_'s avatar
lizhongyi_ 已提交
110
          tagName: 'WEB-VIEW',
lizhongyi_'s avatar
lizhongyi_ 已提交
111 112 113 114
          type: 'load',
          src: 'https://www.dcloud.io/'
        });
      }
115 116 117
    });

    it('test event error', async () => {
118 119 120 121 122
      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'
123 124 125
        });
        start = Date.now();
        await page.waitFor(async () => {
126
          return (await page.data('eventError')) || (Date.now() - start > 5000);
127
        });
lizhongyi_'s avatar
lizhongyi_ 已提交
128 129
        expect(await page.data('eventError')).toEqual({
          tagName: 'WEB-VIEW',
130 131 132 133 134 135 136 137
          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'
        });
      }
138 139 140
      await page.setData({
        autoTest: false
      });
141 142
    });

shutao-dc's avatar
shutao-dc 已提交
143
    it('checkNativeWebView', async () => {
144 145 146 147 148 149 150
      const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
      if(
        platformInfo.indexOf('14.5') != -1 ||
        platformInfo.indexOf('13.7') != -1 ||
        platformInfo.indexOf('12.4') != -1
        ){
          expect(1).toBe(1)
lizhongyi_'s avatar
lizhongyi_ 已提交
151
          return
152
      }
153
      await page.waitFor(300);
154
      const has = await page.callMethod('checkNativeWebView')
155 156
      expect(has).toBe(true)
    })
DCloud-WZF's avatar
DCloud-WZF 已提交
157 158 159 160 161 162
  } else {
    // TODO: web 端暂不支持
    it('web', async () => {
      expect(1).toBe(1)
    })
  }
lizhongyi_'s avatar
lizhongyi_ 已提交
163
});