get-current-pages.test.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. jest.setTimeout(40000)
  2. const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
  3. const isAndroid = platformInfo.startsWith('android')
  4. const isWeb = platformInfo.startsWith('web')
  5. const isMP = platformInfo.startsWith('mp')
  6. const isAppWebView = process.env.UNI_AUTOMATOR_APP_WEBVIEW == 'true'
  7. const HOME_PAGE_PATH = '/pages/tabBar/component'
  8. const PAGE_PATH = '/pages/API/get-current-pages/get-current-pages?test=123'
  9. describe('getCurrentPages', () => {
  10. if (isAppWebView) {
  11. it('not support', () => {
  12. expect(1).toBe(1)
  13. })
  14. return
  15. }
  16. let page
  17. const deviceScreenshotParams = {
  18. deviceShot: true,
  19. area: {
  20. x: 0,
  21. y: 0,
  22. }
  23. }
  24. it('getCurrentPages', async () => {
  25. // web 端等待应用首页加载完成
  26. if (isWeb) {
  27. const waitTime = process.env.uniTestPlatformInfo.includes('safari') ?
  28. 5000 :
  29. 3000
  30. await new Promise((resolve) => {
  31. setTimeout(() => {
  32. resolve()
  33. }, waitTime)
  34. })
  35. }
  36. page = await program.switchTab(HOME_PAGE_PATH)
  37. await page.waitFor(1000)
  38. page = await program.navigateTo(PAGE_PATH)
  39. await page.waitFor(1000)
  40. await page.callMethod('_getCurrentPages')
  41. await page.waitFor(200)
  42. const data = await page.data()
  43. expect(data.checked).toBe(true)
  44. })
  45. if (isMP) {
  46. return
  47. }
  48. it('page-style', async () => {
  49. const windowInfo = await program.callUniMethod('getWindowInfo');
  50. deviceScreenshotParams.area.y = windowInfo.safeAreaInsets.top + 44;
  51. await page.callMethod('getPageStyle')
  52. await page.waitFor(200)
  53. const isEnablePullDownRefresh1 = await page.data('currentPageStyle.enablePullDownRefresh')
  54. expect(isEnablePullDownRefresh1).toBe(true)
  55. // setPageStyle
  56. await page.callMethod('setPageStyle', {
  57. enablePullDownRefresh: false
  58. })
  59. await page.waitFor(200)
  60. await page.callMethod('getPageStyle')
  61. await page.waitFor(200)
  62. const isEnablePullDownRefresh2 = await page.data('currentPageStyle.enablePullDownRefresh')
  63. expect(isEnablePullDownRefresh2).toBe(false)
  64. await page.callMethod('startPullDownRefresh')
  65. await page.waitFor(500)
  66. const image2 = await program.screenshot({fullPage: true});
  67. expect(image2).toSaveImageSnapshot({customSnapshotIdentifier() {
  68. return 'get-current-pages-test-js-get-current-pages-page-style-before-set-page-style'
  69. }});
  70. await page.waitFor(3500)
  71. await page.callMethod('setPageStyle', {
  72. enablePullDownRefresh: true
  73. })
  74. await page.waitFor(200)
  75. await page.callMethod('startPullDownRefresh')
  76. await page.waitFor(500)
  77. const image3 = await program.screenshot({fullPage: true});
  78. expect(image3).toSaveImageSnapshot({customSnapshotIdentifier() {
  79. return 'get-current-pages-test-js-get-current-pages-page-style-after-set-page-style'
  80. }});
  81. // setPageStyle
  82. await page.callMethod('setPageStyle', {
  83. androidThreeButtonNavigationBackgroundColor: 'aqua'
  84. });
  85. await page.waitFor(2000);
  86. const image4 = await program.screenshot(deviceScreenshotParams);
  87. expect(image4).toSaveImageSnapshot({customSnapshotIdentifier() {
  88. return 'get-current-pages-test-androidThreeButtonNavigationBackgroundColor'
  89. }});
  90. await page.callMethod('setPageStyle', {
  91. androidThreeButtonNavigationStyle: 'black'
  92. });
  93. await page.waitFor(2000);
  94. const image5 = await program.screenshot(deviceScreenshotParams);
  95. expect(image5).toSaveImageSnapshot({customSnapshotIdentifier() {
  96. return 'get-current-pages-test-androidThreeButtonNavigationStyle'
  97. }});
  98. await page.callMethod('setPageStyle', {
  99. androidThreeButtonNavigationTranslucent: true
  100. });
  101. await page.waitFor(2000);
  102. const image6 = await program.screenshot(deviceScreenshotParams);
  103. expect(image6).toSaveImageSnapshot({customSnapshotIdentifier() {
  104. return 'get-current-pages-test-androidThreeButtonNavigationTranslucent'
  105. }});
  106. await page.callMethod('setPageStyle', {
  107. hideBottomNavigationIndicator: true,
  108. hideStatusBar: true
  109. })
  110. await page.waitFor(2000);
  111. const image7 = await program.screenshot(deviceScreenshotParams);
  112. expect(image7).toSaveImageSnapshot({customSnapshotIdentifier() {
  113. return 'get-current-pages-test-hideStatusBar-hideBottomNavigationIndicator'
  114. }});
  115. })
  116. it('$page', async () => {
  117. await page.setData({testing: true})
  118. const res = await page.callMethod('check$page')
  119. expect(res).toBe(true)
  120. })
  121. it('getParentPage', async () => {
  122. const res = await page.callMethod('checkGetParentPage')
  123. expect(res).toBe(true)
  124. })
  125. it('getDialogPages', async () => {
  126. const res = await page.callMethod('checkGetDialogPages')
  127. expect(res).toBe(true)
  128. })
  129. it('getElementById', async () => {
  130. const res = await page.callMethod('checkGetElementById')
  131. expect(res).toBe(true)
  132. })
  133. it('getAndroidView', async () => {
  134. const res = await page.callMethod('checkGetAndroidView')
  135. expect(res).toBe(isAndroid)
  136. })
  137. it('getIOSView', async () => {
  138. const res = await page.callMethod('checkGetIOSView')
  139. expect(res).toBe(false)
  140. })
  141. it('getHTMLElement', async () => {
  142. const res = await page.callMethod('checkGetHTMLElement')
  143. expect(res).toBe(isWeb)
  144. })
  145. if(isAndroid) {
  146. it('getAndroidActivity', async () => {
  147. const res = await page.callMethod('checkGetAndroidActivity')
  148. expect(res).toBe(true)
  149. })
  150. }
  151. })