// uni-app自动化测试教程: uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/ describe('component-native-web-view', () => { 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); }); it('check_load_url', async () => { expect(await page.data('loadError')).toBe(false) }); it('screenshot', async () => { await page.waitFor(async () => { return await page.data('loadFinish') === true; }); const image = await program.screenshot({ fullPage: true }); expect(image).toSaveImageSnapshot(); }); 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; } 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 }); }); 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) }) } });