滚动测试 [英] Test for scrolling

查看:18
本文介绍了滚动测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 Angular 应用程序中,我有一个侧面有导航链接的页面,当点击该链接时,页面会向下滚动到匹配的元素.

In my angular application, I have a page that has nav links on the side, that, when clicked, scrolls the page down to a matching element.

如何在量角器中为此编写 e2e 测试?有没有像抓住第一个可见的 h1"之类的东西?

How do I write e2e test for this in protractor? Is there something like "Grab the first visible h1" or something like that?

推荐答案

你可以使用 javascript 的 window.pageYOffset 来解决这个问题.以下是我在自己的一个测试用例中的做法:

You can use javascript's window.pageYOffset for this. Here's how I've done it in one of my own test case:

    browser.driver.sleep(2000);
    browser.executeScript('return window.pageYOffset;').then(function(pos) {
        expect(pos).to.be.at.most(100);
    });

100 是我的预期位置.

Where 100 is my expected position.

注意:我使用的是 mocha 和 chai 而不是 jasmine.因此,只需相应地更改最后一行.此外,我正在等待 2 秒以完成滚动.

Note: I'm using mocha and chai instead of jasmine. So, just change the last line accordingly. Also I'm waiting 2 seconds for my scrolling to complete.

这篇关于滚动测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆