angular – 使用量角器测试元素在视口中

前端之家收集整理的这篇文章主要介绍了angular – 使用量角器测试元素在视口中前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想测试我的应用是否滚动到线程页面内的特定帖子.

最初我认为isDisplayed可能有所帮助,并编码如下:

@H_502_13@element(by.id(postId)).isDisplayed().then((isDisplayed) => { expect(isDisplayed).toBe(true); });

仔细阅读documentation之后,isDisplayed不会检查元素是否在视口内.

一个hacky方法是计算各种元素的位置,从可滚动的父级(在我的情况下不是窗口)开始.

检查这个是最好的做法吗?

解决方法

第一个想法(你提到过):

>创建类MyRect扩展DOMRect
>基于getBoundingClientRect创建函数getBoundingClientMyRect
>基于(0,wWidth,wHeight)创建函数getWindowMyRect

让wHeight = window.innerHeight || document.documentElement.clientHeight;
让wWidth = window.innerWidth || document.documentElement.clientWidth;

>在MyRect中创建方法isInsideMyRect – 基于https://gist.github.com/davidtheclark/5515733
>在MyRect中创建方法isPartOfMyRect – 基于https://gist.github.com/davidtheclark/5515733#gistcomment-2113166

el.getWindowMyRect().isInsideMyRect(getWindowMyRect())

方法无法解决页面内部滚动的问题

Secand理念:

> elm.getBoundingClientRect()并记下该值>如果需要,滚动到元素:browser.executeScript(“arguments [0] .scrollIntoViewIfNeeded();”,elm.getWebElement());> elm.getBoundingClientRect() – 如果值已更改,则再次与之前的值进行比较,然后滚动是必要的

猜你在找的Angularjs相关文章