web-view.test.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
  2. const isIOS = platformInfo.startsWith('ios')
  3. const isMP = platformInfo.startsWith('mp')
  4. const isWeb = platformInfo.startsWith('web')
  5. const isHarmony = platformInfo.startsWith('harmony')
  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 || isAppWebView) {
  10. it('web', async () => {
  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');
  19. await page.waitFor(3000);
  20. });
  21. it('check_load_url', async () => {
  22. expect(await page.data('loadError')).toBe(false)
  23. });
  24. it('test attr webview-styles', async () => {
  25. await page.setData({
  26. webview_styles: {
  27. progress: {
  28. color: '#FF0'
  29. }
  30. }
  31. });
  32. await page.waitFor(100);
  33. await page.callMethod('reload');
  34. await page.waitFor(100);
  35. await page.setData({
  36. webview_styles: {
  37. progress: {
  38. color: 'yellow'
  39. }
  40. }
  41. });
  42. await page.waitFor(100);
  43. await page.callMethod('reload');
  44. });
  45. if (isMP) {
  46. return
  47. }
  48. it('set auto test', async () => {
  49. await page.setData({
  50. autoTest: true
  51. });
  52. expect(1).toBe(1)
  53. });
  54. it('test touch event', async () => {
  55. const windowInfo = await program.callUniMethod('getWindowInfo');
  56. await program.tap({
  57. x: 1,
  58. y: windowInfo.safeAreaInsets.top + 44 + 1
  59. });
  60. await page.waitFor(500);
  61. if (!isIOS) {
  62. expect(await page.data('isTouchEnable')).toBe(true);
  63. }
  64. await page.setData({
  65. pointerEvents: 'none',
  66. isTouchEnable: false
  67. });
  68. await page.waitFor(100);
  69. await program.tap({
  70. x: 10,
  71. y: windowInfo.safeAreaInsets.top + 44 + 10
  72. });
  73. await page.waitFor(500);
  74. if (!isIOS && !isHarmony) {
  75. expect(await page.data('isTouchEnable')).toBe(false);
  76. }
  77. await page.setData({
  78. pointerEvents: 'auto'
  79. });
  80. });
  81. it('test event loading load', async () => {
  82. await page.callMethod('reload');
  83. start = Date.now();
  84. await page.waitFor(async () => {
  85. return (await page.data('eventLoading')) || (Date.now() - start > 500);
  86. });
  87. if (isIOS) {
  88. const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
  89. if (
  90. platformInfo.indexOf('14.5') != -1 ||
  91. platformInfo.indexOf('13.7') != -1 ||
  92. platformInfo.indexOf('12.4') != -1
  93. ) {
  94. expect(1).toBe(1)
  95. return
  96. }
  97. expect(await page.data('eventLoading')).toEqual({
  98. "tagName": "WEB-VIEW",
  99. type: 'loading',
  100. src: 'https://www.dcloud.io/'
  101. });
  102. } else {
  103. expect(await page.data('eventLoading')).toEqual({
  104. tagName: 'WEB-VIEW',
  105. type: 'loading',
  106. src: 'https://www.dcloud.io/'
  107. });
  108. }
  109. start = Date.now();
  110. await page.waitFor(async () => {
  111. return (await page.data('eventLoad')) || (Date.now() - start > 5000);
  112. });
  113. expect(await page.data('eventLoad')).toEqual({
  114. tagName: 'WEB-VIEW',
  115. type: 'load',
  116. src: 'https://www.dcloud.io/',
  117. url: 'https://www.dcloud.io/'
  118. });
  119. });
  120. it('test event contentheightchange', async () => {
  121. if (!isAndroid && !isIOS && !isHarmony) {
  122. expect(1).toBe(1);
  123. return;
  124. }
  125. expect(await page.callMethod('getContentHeight')).toBeGreaterThan(0);
  126. start = Date.now();
  127. await page.waitFor(async () => {
  128. return (await page.data('eventContentHeightChange')) || (Date.now() - start > 500);
  129. });
  130. expect(await page.data('eventContentHeightChange')).toEqual({
  131. tagName: 'WEB-VIEW',
  132. type: 'contentheightchange',
  133. isValidHeight: true
  134. });
  135. });
  136. it('test event contentheightchange', async () => {
  137. if (!isAndroid && !isIOS && !isHarmony) {
  138. expect(1).toBe(1);
  139. return;
  140. }
  141. expect(await page.callMethod('getContentHeight')).toBeGreaterThan(0);
  142. start = Date.now();
  143. await page.waitFor(async () => {
  144. return (await page.data('eventContentHeightChange')) || (Date.now() - start > 500);
  145. });
  146. expect(await page.data('eventContentHeightChange')).toEqual({
  147. tagName: 'WEB-VIEW',
  148. type: 'contentheightchange',
  149. isValidHeight: true
  150. });
  151. });
  152. it('test event error', async () => {
  153. const infos = process.env.uniTestPlatformInfo.split(' ');
  154. const version = parseInt(infos[infos.length - 1]);
  155. if (isAndroid && version > 5) {
  156. await page.setData({
  157. src: 'https://www.dclou.io/uni-app-x'
  158. });
  159. start = Date.now();
  160. await page.waitFor(async () => {
  161. return (await page.data('eventError')) || (Date.now() - start > 5000);
  162. });
  163. expect(await page.data('eventError')).toEqual({
  164. tagName: 'WEB-VIEW',
  165. type: 'error',
  166. errCode: 100002,
  167. errMsg: 'page error',
  168. url: 'https://www.dclou.io',
  169. fullUrl: 'https://www.dclou.io/uni-app-x',
  170. src: 'https://www.dclou.io/uni-app-x'
  171. });
  172. }
  173. await page.setData({
  174. autoTest: false
  175. });
  176. });
  177. it('checkNativeWebView', async () => {
  178. const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
  179. if (
  180. platformInfo.indexOf('14.5') != -1 ||
  181. platformInfo.indexOf('13.7') != -1 ||
  182. platformInfo.indexOf('12.4') != -1
  183. ) {
  184. expect(1).toBe(1)
  185. return
  186. }
  187. await page.waitFor(300);
  188. const has = await page.callMethod('checkNativeWebView')
  189. expect(has).toBe(true)
  190. })
  191. it('test lodaData', async () => {
  192. await page.callMethod('loadData');
  193. await page.waitFor(1000);
  194. const image = await program.screenshot({ fullPage: true });
  195. expect(image).toSaveImageSnapshot();
  196. });
  197. });