web-view.test.js 4.7 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 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
  const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
  const isAndroid = platformInfo.startsWith('android')
  const isIOS = platformInfo.startsWith('ios')
  const isMP = platformInfo.startsWith('mp')
  const isWeb = platformInfo.startsWith('web')
  if (isWeb || process.env.UNI_AUTOMATOR_APP_WEBVIEW) {
    it('web', async () => {
      expect(1).toBe(1)
    })
    return
  }
  let page;
  let start = 0;
  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)
  });

  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'
        }
      }
DCloud-WZF's avatar
DCloud-WZF 已提交
43
    });
44 45 46
    await page.waitFor(100);
    await page.callMethod('reload');
  });
DCloud-WZF's avatar
DCloud-WZF 已提交
47

48 49 50 51 52 53
  if (isMP) {
    return
  }
  it('test touch event', async () => {
    await page.setData({
      autoTest: true
DCloud-WZF's avatar
DCloud-WZF 已提交
54
    });
55 56 57 58 59 60 61 62 63
    const info = await page.callMethod('getWindowInfo');
    await program.tap({
      x: 1,
      y: info.statusBarHeight + 44 + 1
    });
    await page.waitFor(500);
    if (process.env.uniTestPlatformInfo.toLowerCase().startsWith('ios') == false) {
      expect(await page.data('isTouchEnable')).toBe(true);
    }
64

65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
    await page.setData({
      pointerEvents: 'none',
      isTouchEnable: false
    });
    await page.waitFor(100);
    await program.tap({
      x: 10,
      y: info.statusBarHeight + 44 + 10
    });
    await page.waitFor(500);
    if (process.env.uniTestPlatformInfo.toLowerCase().startsWith('ios') == false) {
      expect(await page.data('isTouchEnable')).toBe(false);
    }
    await page.setData({
      pointerEvents: 'auto'
    });
  });

  it('test event loading load', async () => {
    await page.callMethod('reload');
    start = Date.now();
    await page.waitFor(async () => {
      return (await page.data('eventLoading')) || (Date.now() - start > 500);
    });
    if (process.env.uniTestPlatformInfo.toLowerCase().startsWith('ios')) {
      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)
        return
      }
      expect(await page.data('eventLoading')).toEqual({
        "tagName": "WEB-VIEW",
        type: 'loading',
        src: 'https://www.dcloud.io/'
103
      });
104 105 106 107 108
    } else {
      expect(await page.data('eventLoading')).toEqual({
        tagName: 'WEB-VIEW',
        type: 'loading',
        src: 'https://www.dcloud.io/'
109
      });
110 111 112 113
    }
    start = Date.now();
    await page.waitFor(async () => {
      return (await page.data('eventLoad')) || (Date.now() - start > 5000);
114
    });
115 116 117 118 119 120
    expect(await page.data('eventLoad')).toEqual({
      tagName: 'WEB-VIEW',
      type: 'load',
      src: 'https://www.dcloud.io/'
    });
  });
121

122 123 124 125 126 127 128
  it('test event error', async () => {
    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'
      });
129
      start = Date.now();
130 131
      await page.waitFor(async () => {
        return (await page.data('eventError')) || (Date.now() - start > 5000);
132
      });
133 134 135 136 137 138 139 140 141 142 143 144
      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'
      });
    }
    await page.setData({
      autoTest: false
145
    });
146
  });
147

148 149 150 151 152 153 154
  it('checkNativeWebView', async () => {
    const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
    if (
      platformInfo.indexOf('14.5') != -1 ||
      platformInfo.indexOf('13.7') != -1 ||
      platformInfo.indexOf('12.4') != -1
    ) {
DCloud-WZF's avatar
DCloud-WZF 已提交
155
      expect(1).toBe(1)
156 157 158 159 160 161
      return
    }
    await page.waitFor(300);
    const has = await page.callMethod('checkNativeWebView')
    expect(has).toBe(true)
  })
lizhongyi_'s avatar
lizhongyi_ 已提交
162
});