scroll-view-refresher.test.js 2.8 KB
Newer Older
1
// uni-app自动化测试教程: uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/
2 3 4
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isAndroid = platformInfo.startsWith('android')
const isIos = platformInfo.startsWith('ios')
雪洛's avatar
雪洛 已提交
5
describe('component-native-scroll-view-refresher', () => {
6
  if (process.env.UNI_AUTOMATOR_APP_WEBVIEW) {
雪洛's avatar
雪洛 已提交
7 8 9 10 11 12 13 14 15
    it('other platform', () => {
      expect(1).toBe(1)
    })
    return
  }
  let page;
  beforeAll(async () => {
    page = await program.reLaunch('/pages/component/scroll-view/scroll-view-refresher');
    await page.waitFor(300);
16
  });
17

雪洛's avatar
雪洛 已提交
18 19 20 21
  it('scroll-view-refresher-screenshot', async () => {
    //禁止滚动条
    await page.setData({
        showScrollbar: false
22
    })
雪洛's avatar
雪洛 已提交
23 24 25 26
    await page.waitFor(300);
    const image = await program.screenshot({fullPage: true});
    expect(image).toSaveImageSnapshot();
  })
27

28
  it('check_refresher_refresh_event', async () => {
雪洛's avatar
雪洛 已提交
29 30
    await page.setData({
      refresherTriggered: true
31
    })
32
    await page.waitFor(2000);
33 34
    expect(await page.data('refresherrefreshTimes')).toBe(1)
    // 手动设置下拉刷新状态refresher-triggered为true时,在web和iOS不触发@refresherpulling事件
35
    if(isAndroid){
36
      expect(await page.data('onRefresherpullingTest')).toBe('refresherpulling:Success')
37
      expect(await page.data('refresherrefreshTest')).toBe('refresherrefresh:Success')
38 39
    }
    await page.waitFor(1000);
40
    expect(await page.data('onRefresherrestoreTest')).toBe('refresherrestore:Success')
雪洛's avatar
雪洛 已提交
41
  });
42

43 44
  // 仅App端支持手势下拉刷新,在不同设备上位置有差异可能导致不触发中止事件
  // 安卓端仅测'android 11.0.0'、'android 10.0.0_x86_64'、'android 10.0.0_x86'
45
  if(!platformInfo.startsWith('web')){
46
    it('check_refresherabort', async () => {
47 48 49 50 51 52 53
      if(isIos){
        await program.swipe({
          startPoint: {x: 100,y: 500},
          endPoint: {x: 100,y: 630},
          duration: 1000
        })
      }else if(isAndroid){
54 55 56 57 58
        await program.swipe({
          startPoint: {x: 100,y: 400},
          endPoint: {x: 100,y: 500},
          duration: 1000
        })
59
      }
60
      await page.waitFor(1500)
61 62
      console.log('onRefresherpullingTest',await page.data('onRefresherpullingTest'))
      console.log(platformInfo,'onRefresherabortTest',await page.data('onRefresherabortTest'))
63
      if(isIos || platformInfo.startsWith('android 10') || platformInfo.startsWith('android 11')){
64 65
        expect(await page.data('onRefresherabortTest')).toBe('refresherabort:Success')
      }
66 67
    });
  }
雪洛's avatar
雪洛 已提交
68 69 70 71 72 73 74 75 76

  it('check_refresher_snapshot', async () => {
    await page.setData({
      refresherTriggered: true
    })
    await page.waitFor(300);
    const image = await program.screenshot({fullPage: true});
    expect(image).toSaveImageSnapshot();
  });
77
});