web-view-local.test.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
  2. const isWeb = platformInfo.startsWith('web')
  3. const isMP = platformInfo.startsWith('mp')
  4. const isHarmony = platformInfo.startsWith('harmony')
  5. const isIOS = platformInfo.startsWith('ios')
  6. const isAndroid = platformInfo.startsWith('android')
  7. const isAppWebView = process.env.UNI_AUTOMATOR_APP_WEBVIEW == 'true'
  8. describe('component-native-web-view', () => {
  9. if(isWeb || isMP || isAppWebView || isIOS || isHarmony){
  10. it('not support', () => {
  11. expect(1).toBe(1)
  12. })
  13. return
  14. }
  15. let page;
  16. let start = 0;
  17. beforeAll(async () => {
  18. page = await program.reLaunch('/pages/component/web-view/web-view/web-view-local');
  19. await page.waitFor(1000);
  20. });
  21. it('check_load_url', async () => {
  22. expect(await page.data('loadError')).toBe(false)
  23. });
  24. it('screenshot', async () => {
  25. await page.waitFor(async () => {
  26. return await page.data('loadFinish') === true;
  27. });
  28. const image = await program.screenshot({
  29. fullPage: true
  30. });
  31. expect(image).toSaveImageSnapshot();
  32. });
  33. it('test event download', async () => {
  34. await page.setData({
  35. autoTest: true
  36. });
  37. await page.callMethod('testEventDownload');
  38. start = Date.now();
  39. await page.waitFor(async () => {
  40. return (await page.data('eventDownload')) || (Date.now() - start > 1000);
  41. });
  42. if (isHarmony) {
  43. await page.waitFor(1500);
  44. // 关闭弹框
  45. await program.tap({ x: 26, y: 80 })
  46. expect(await page.data('eventDownload')).toEqual({
  47. tagName: 'WEB-VIEW',
  48. type: 'download',
  49. url: 'https://web-ext-storage.dcloud.net.cn/uni-app-x/pkg/hello-uniappx.apk',
  50. userAgent: 'Mobile',
  51. contentDisposition: `attachment; filename="hello-uniappx.apk"; filename*=utf-8''hello-uniappx.apk`,
  52. mimetype: 'application/vnd.android.package-archive',
  53. isContentLengthValid: true
  54. });
  55. return;
  56. }
  57. if (isIOS) {
  58. // expect(await page.data('eventDownload')).toEqual({
  59. // tagName: 'WEB-VIEW',
  60. // type: 'download',
  61. // url: 'https://web-ext-storage.dcloud.net.cn/uni-app-x/pkg/hello-uniappx.apk',
  62. // userAgent: `uni-app-x/${process.env.HX_Version.split('-')[0].split('.').slice(0, 2).join('.')}`,
  63. // contentDisposition: '',
  64. // mimetype: 'application/vnd.android.package-archive',
  65. // isContentLengthValid: true
  66. // });
  67. return;
  68. }
  69. const infos = process.env.uniTestPlatformInfo.split(' ');
  70. const version = parseInt(infos[infos.length - 1]);
  71. if (version == 8) return; // android8测试结果不稳定
  72. if (version >= 9) {
  73. expect(await page.data('eventDownload')).toEqual({
  74. tagName: 'WEB-VIEW',
  75. type: 'download',
  76. url: 'https://web-ext-storage.dcloud.net.cn/uni-app-x/pkg/hello-uniappx.apk',
  77. userAgent: `uni-app-x/${process.env.HX_Version.split('-')[0].split('.').slice(0, 2).join('.')}`,
  78. contentDisposition: `attachment; filename="hello-uniappx.apk"; filename*=utf-8''hello-uniappx.apk`,
  79. mimetype: 'application/vnd.android.package-archive',
  80. isContentLengthValid: true
  81. });
  82. } else if (version >= 7) { // 低版本webview内核,部分属性无有效值
  83. expect(await page.data('eventDownload')).toEqual({
  84. tagName: 'WEB-VIEW',
  85. type: 'download',
  86. url: 'https://web-ext-storage.dcloud.net.cn/uni-app-x/pkg/hello-uniappx.apk',
  87. userAgent: '',
  88. contentDisposition: '',
  89. mimetype: '',
  90. isContentLengthValid: false
  91. });
  92. }
  93. });
  94. it('test event message', async () => {
  95. const infos = process.env.uniTestPlatformInfo.split(' ');
  96. const version = parseInt(infos[infos.length - 1]);
  97. if (isAndroid && version > 6) {
  98. await page.callMethod('testEventMessage');
  99. start = Date.now();
  100. await page.waitFor(async () => {
  101. return (await page.data('eventMessage')) || (Date.now() - start > 500);
  102. });
  103. expect(await page.data('eventMessage')).toEqual({
  104. tagName: 'WEB-VIEW',
  105. type: 'message',
  106. data: [{
  107. action: 'message'
  108. }]
  109. });
  110. }
  111. await page.setData({
  112. autoTest: false
  113. });
  114. });
  115. });