scroll-view-props.test.js 3.6 KB
Newer Older
shutao-dc's avatar
shutao-dc 已提交
1 2
// uni-app自动化测试教程: uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/

3
describe('component-native-scroll-view-props', () => {
shutao-dc's avatar
shutao-dc 已提交
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26

    let page;
    beforeAll(async () => {
        page = await program.reLaunch('/pages/component/scroll-view/scroll-view-props');
        await page.waitFor(300);
    });

    //检测竖向可滚动区域
    it('check_scroll_height', async () => {
      await page.setData({
          scrollX: false
      })
      await page.waitFor(300);
      const value = await page.callMethod('checkScrollHeight')
      expect(value).toBe(true)
    })

    //检测竖向scrolltop属性赋值
    it('check_scroll_top', async () => {
        await page.setData({
            scrollTop: 600
        })
        await page.waitFor(600)
27 28 29 30
        //检测滚动top 是否触发scroll 事件
        const scrollChangeTop = await page.data('scrollChangeTop')
        console.log("scrollChangeTop="+scrollChangeTop)
        expect(scrollChangeTop-600).toBeGreaterThanOrEqual(0)
shutao-dc's avatar
shutao-dc 已提交
31
        const element = await page.$('#scrollViewY')
32
        const scrollTop = await element.property("scrollTop")
shutao-dc's avatar
shutao-dc 已提交
33 34 35 36 37 38 39 40 41 42 43
        console.log("check_scroll_top---"+scrollTop)
        expect(scrollTop-600).toBeGreaterThanOrEqual(0)
    })

    //检测竖向scroll_into_view属性赋值
    it('check_scroll_into_view_top', async () => {
        await page.setData({
            scrollIntoView: "item3"
        })
        await page.waitFor(600)
        const element = await page.$('#scrollViewY')
44
        const scrollTop = await element.property("scrollTop")
shutao-dc's avatar
shutao-dc 已提交
45 46 47 48
        console.log("check_scroll_into_view_top--"+scrollTop)
        await page.setData({
            scrollIntoView: ""
        })
shutao-dc's avatar
shutao-dc 已提交
49
        expect(scrollTop-570).toBeGreaterThanOrEqual(0)
shutao-dc's avatar
shutao-dc 已提交
50 51 52 53 54 55 56 57 58 59 60
    })

    //检测横向可滚动区域
    it('check_scroll_width', async () => {
      await page.setData({
          scrollX: true
      })
      await page.waitFor(300);
      const value = await page.callMethod('checkScrollWidth')
      expect(value).toBe(true)
    })
61

shutao-dc's avatar
shutao-dc 已提交
62 63 64 65 66 67 68
    //检测横向scrollLeft属性赋值
    it('check_scroll_left', async () => {
      await page.setData({
          scrollLeft: 600
      })
      await page.waitFor(600)
      const element = await page.$('#scrollViewX')
69
      const scrollLeft = await element.property("scrollLeft")
shutao-dc's avatar
shutao-dc 已提交
70 71 72
      console.log("check_scroll_left---"+scrollLeft)
      expect(scrollLeft-600).toBeGreaterThanOrEqual(0)
    })
73

shutao-dc's avatar
shutao-dc 已提交
74 75 76 77 78 79 80
    //检测横向scroll_into_view属性赋值
    it('check_scroll_into_view_left', async () => {
      await page.setData({
          scrollIntoView: "horizontal_item3"
      })
      await page.waitFor(600)
      const element = await page.$('#scrollViewX')
81
      const scrollLeft = await element.property("scrollLeft")
shutao-dc's avatar
shutao-dc 已提交
82 83 84 85
      console.log("check_scroll_into_view_left--"+scrollLeft)
      await page.setData({
          scrollIntoView: ""
      })
shutao-dc's avatar
shutao-dc 已提交
86
      expect(scrollLeft-930).toBeGreaterThanOrEqual(0)
shutao-dc's avatar
shutao-dc 已提交
87 88
    })

89 90 91 92 93 94 95
    //截图对比
    it('scroll-view-props-screenshot', async () => {
      //禁止滚动条
      await page.setData({
          showScrollbar: false
      })
      await page.waitFor(300);
96
      const image = await program.screenshot({fullPage: true});
97
      expect(image).toSaveImageSnapshot();
98
    })
99 100 101 102 103 104 105 106 107 108 109 110


    //截图末尾位置元素
    it('scroll-view-props-last-item-screenshot', async () => {
      //滚动到末尾位置
      await page.setData({
          scrollLeft: 10000
      })
      await page.waitFor(300);
      const image = await program.screenshot({fullPage: true});
      expect(image).toSaveImageSnapshot();
    })
shutao-dc's avatar
shutao-dc 已提交
111
});