create-inner-audio-context.test.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
  2. const isMP = platformInfo.startsWith('mp')
  3. const isIos = platformInfo.startsWith('ios')
  4. const isHarmony = platformInfo.toLocaleLowerCase().startsWith('harmony')
  5. const isSafari = platformInfo.indexOf('safari') > -1
  6. const isAndroid = platformInfo.startsWith('android')
  7. describe('inner-audio', () => {
  8. // safari 浏览器运行正常,playwright 环境下给 Audio 实例 src 属性赋值会崩溃
  9. if (isMP || isIos || isSafari) {
  10. it('not support', () => {
  11. expect(1).toBe(1)
  12. })
  13. return
  14. }
  15. beforeAll(async () => {
  16. page = await program.reLaunch('/pages/API/create-inner-audio-context/create-inner-audio-context')
  17. await page.waitFor('view');
  18. });
  19. it('onCanplay',async()=>{
  20. await page.waitFor(1000)
  21. await page.waitFor(async()=>{
  22. return await page.data('isCanplay')
  23. })
  24. const isCanplay = await page.data('isCanplay')
  25. if (!isHarmony) {
  26. expect(await page.data('buffered')).toBeGreaterThan(0)
  27. } else {
  28. expect(isCanplay).toBe(true)
  29. }
  30. })
  31. it('seek-onSeeking-onSeeked', async () => {
  32. if (process.env.uniTestPlatformInfo.indexOf('android') > -1 ) {
  33. expect(1).toBe(1)
  34. return false
  35. }
  36. await page.callMethod('onchangeValue',20)
  37. const waitTime = process.env.uniTestPlatformInfo.includes('chrome') ? 1500:500
  38. await page.waitFor(waitTime)
  39. console.log("seek-onSeeking-onSeeked:",await page.data())
  40. let isDone = await page.waitFor(async () => {
  41. return await page.data('onSeekingTest')
  42. })
  43. expect(await page.data('onSeekingTest')).toBeTruthy();
  44. expect(await page.data('currentTime')).toBe(20);
  45. // expect(await page.data('onWaitingTest')).toBeTruthy();
  46. // expect(await page.data('onSeekedTest')).toBeTruthy();
  47. const image = await program.screenshot({fullPage: true})
  48. expect(image).toSaveImageSnapshot();
  49. });
  50. it('play-onPlay-onTimeUpdate', async () => {
  51. await page.callMethod('play')
  52. const waitTime = process.env.uniTestPlatformInfo.includes('chrome') ? 5000:3000
  53. await page.waitFor(waitTime)
  54. expect(await page.data('isPlaying')).toBeTruthy()
  55. console.log("duration:",await page.data('duration'),"currentTime:",await page.data('currentTime'))
  56. expect(await page.data('duration')).toBeCloseTo(175.109, 0);
  57. // console.log("isPaused",await page.data('isPaused'))
  58. // expect(await page.data('currentTime')).toBeGreaterThan(0);
  59. // expect(await page.data('isPaused')).toBeFalsy();
  60. });
  61. it('pause-onPause', async () => {
  62. await page.callMethod('pause')
  63. await page.waitFor(500);
  64. expect(await page.data('isPlaying')).toBeFalsy()
  65. // expect(await page.data('isPaused')).toBeTruthy();
  66. });
  67. it('stop-onStop', async () => {
  68. await page.callMethod('play')
  69. await page.waitFor(2000);
  70. // 第一次点停止时,不触发onStop事件
  71. await page.callMethod('stop')
  72. await page.callMethod('stop')
  73. await page.waitFor(1000);
  74. expect(await page.data('isPlaying')).toBeFalsy()
  75. // expect(await page.data('isPaused')).toBeTruthy();
  76. });
  77. it('onEnded', async () => {
  78. await page.callMethod('onchangeValue',173)
  79. await page.waitFor(500);
  80. await page.callMethod('play')
  81. await page.waitFor(3000);
  82. // expect(await page.data('isPlayEnd')).toBeTruthy();
  83. });
  84. it('onEnded-android', async () => {
  85. if (!isAndroid) {
  86. expect(1).toBe(1)
  87. return
  88. }
  89. await page.setData({
  90. isPlayEnd: false
  91. })
  92. await page.callMethod('setSrc','file:///android_asset/uni-autoTest/alert2s.mp3')
  93. await page.callMethod('play')
  94. await page.waitFor(3000);
  95. expect(await page.data('isPlayEnd')).toBeTruthy();
  96. });
  97. });