Testing 离子3无限长涡旋模拟e2e测试茉莉花/量角器

Testing 离子3无限长涡旋模拟e2e测试茉莉花/量角器,testing,ionic2,jasmine,protractor,ionic3,Testing,Ionic2,Jasmine,Protractor,Ionic3,如果你去这里: 检查演示并单击列表上的最后一项: 然后在控制台中键入:$0.scrollIntoView() 无限卷轴永远不会被触发 有没有一种方法可以在量角器上下文中以编程方式触发无限滚动?在您的示例中,滚动的实现依赖于滚动的速度/速度,我猜当调用scrollIntoView时,滚动的速度/速度远远低于预期范围 一种解决方法是通过在合理的时间内发出多个滚动事件来模拟平滑滚动。这个想法是尽可能地再现真实用户的行为 一些浏览器已经提供了通过(Chrome 62支持)的选项: 在我的例子中,使用公

如果你去这里:

检查演示并单击列表上的最后一项:

然后在控制台中键入:
$0.scrollIntoView()

无限卷轴永远不会被触发


有没有一种方法可以在量角器上下文中以编程方式触发无限滚动?

在您的示例中,滚动的实现依赖于滚动的速度/速度,我猜当调用
scrollIntoView
时,滚动的速度/速度远远低于预期范围

一种解决方法是通过在合理的时间内发出多个滚动事件来模拟平滑滚动。这个想法是尽可能地再现真实用户的行为

一些浏览器已经提供了通过(Chrome 62支持)的选项:


在我的例子中,使用公认的答案,我使用了
ioninfinitescroll
作为参数

完成测试,以检查是否在Ionic中加载了更多内容:

describe('Scroll', () => {
    it('should load more when reached end', async () => {
        let list = getList();

        let currentCount = await list.count();

        const refresher = element(by.tagName('ion-infinite-scroll')).getWebElement();

        let count = 0;

        while(true){
            browser.executeScript(`arguments[0].scrollIntoView({behavior: "smooth", block: "end"});`, refresher);
            browser.sleep(1000); // wait for data to be loaded from api
            list = getList();
            let newCount = await list.count();
            expect(newCount).toBeGreaterThanOrEqual(currentCount)
            expect(newCount).toBeLessThanOrEqual(currentCount * 2)
            if(newCount === currentCount){
                break;
            }
            currentCount = newCount;
            count++;
        }

        expect(count).toBeGreaterThan(0);
    })
});

function getList() {
    return element(by.className(pageId + ' list')).all(by.tagName('ion-item'));
}
describe('Scroll', () => {
    it('should load more when reached end', async () => {
        let list = getList();

        let currentCount = await list.count();

        const refresher = element(by.tagName('ion-infinite-scroll')).getWebElement();

        let count = 0;

        while(true){
            browser.executeScript(`arguments[0].scrollIntoView({behavior: "smooth", block: "end"});`, refresher);
            browser.sleep(1000); // wait for data to be loaded from api
            list = getList();
            let newCount = await list.count();
            expect(newCount).toBeGreaterThanOrEqual(currentCount)
            expect(newCount).toBeLessThanOrEqual(currentCount * 2)
            if(newCount === currentCount){
                break;
            }
            currentCount = newCount;
            count++;
        }

        expect(count).toBeGreaterThan(0);
    })
});

function getList() {
    return element(by.className(pageId + ' list')).all(by.tagName('ion-item'));
}