量角器在生成服务器上失败-ElementNotVisibleError [英] Protractor Fails on Build Server - ElementNotVisibleError
问题描述
我使用量角器和黄瓜进行的所有角度e2e测试在我的机器上运行顺利且良好.但是,一旦我在构建服务器上运行测试,就会收到错误消息
All my angular e2e tests using protractor with cucumber are running smooth and fine on my machine. But as soon as I run the tests on the build server, I get an error
ElementNotVisibleError:元素不可见
会话信息:chrome = 51.0.2704.84
Session info: chrome=51.0.2704.84
驱动程序信息:chromedriver = 2.21.371459
Driver info: chromedriver=2.21.371459
platform = Windows NT 6.1 SP1 x86_64
platform=Windows NT 6.1 SP1 x86_64
在一开始,我认为这与计时有关,正在发生一些异步的事情,但是经过数小时的调试,我终于可以在本地计算机上重现该错误.
In the beginning, I thought this has something to do with timing, some asynchronous stuff that is happening but after hours of debugging I can finally reproduce the bug even on my local machine.
最小化窗口是不够的,但是如果我快速拖动鼠标以使窗口尽可能小,则会出现此错误.因此,这仅仅是窗口大小"的问题.
Minimizing the window is not enough but if I quickly drag the mouse to make the window as small as possible, I get this error. So it is just a matter of "window size".
因此错误消息还可以,但是量角器的含义 在构建服务器上运行?
为什么有些测试通过了?量角器似乎在构建服务器上看到"了东西,因此
And why are some tests passing? Protractor seems to "see" something on the build server, thus
我尝试了
browser.driver.manage().window().maximize();
我尝试了
browser.manage().window().setSize(1920, 1200);
,并且我尝试根据建议的此处更改代码,并且我尝试了更多(绝望)的事情.什么都没用.
and I tried to change my code as suggested here and I tried a lot of more (hopeless) things. Nothing worked.
我现在的大问题:当我想在某个页面上单击最右边的按钮时,如何在构建服务器(以TFS为例)上以稳定的方式进行量角器测试?
My big question now: How can I run a protractor test in a stable fashion on a build server (in my case TFS) when there is a rightmost button I want to click on some page?
短代码示例:
browser.get(browser.baseUrl + '#/somePage').then...
element(by.id(buttonId)).click();
谢谢!
更新:
我遇到问题的主要原因是,在构建服务器上运行测试时,屏幕分辨率的宽度为1024,因此setSize(1920,1200)失败.因此,我现在在onPrepare函数中添加了当前分辨率的输出,以便将来获得提示:
The main reason for my problems was the fact that the screen resolution while running the test on the build server had a width of 1024 and thus setSize(1920, 1200) failed. For that reason I now added an output of the current resoltuion in the onPrepare function, so that I will get a hint in the future:
onPrepare: function () {
browser.executeScript('return { height: screen.availHeight, width: screen.availWidth, top: screen.availTop, left: screen.availLeft};').then(function (result) {
console.log("Screen resolution: ");
console.log(result);
});
browser.manage().window().setSize(1920, 1200);
当然可以扩展一点以抛出异常或类似的东西.
Of course this could be extended a little bit to throw an exception or something like this.
推荐答案
有时,我们需要将所需元素带入视图,以避免出现元素不可见"错误.我们可以通过两种通用方法来做到这一点:
Sometimes, we need to bring the desired element into view in order to avoid "Element not visible" error. We can do that in two general ways:
-
使用浏览器操作" :
var elm = element(by.id("buttonid"));
browser.actions().mouseMove(elm).click().perform()
var elm = element(by.id("buttonid"));
browser.executeScript("arguments[0].scrollIntoView();", elm.getWebElement());
还链接此答案,其中包含很多可以尝试解决问题的内容.
Also linking this answer that has a nice set of things you can try to tackle the problem.
这篇关于量角器在生成服务器上失败-ElementNotVisibleError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!