我有一个使用.NET呈现的页面,它包含c# .net代码。我正在使用幻影GhostDriver对protractorjs进行测试。但是,当页面加载时,我似乎遇到了问题。
如果我运行这个测试
it('should redirect to login', function () {
targetUrl = 'http://localhost:52254/';
ptor = protractor.getInstance();
ptor.ignoreSychronization = true;
ptor.get(targetUrl);
ptor.wait(function () {
return ptor.driver.getCurrentUrl().then(function (url) {
return targetUrl = url;
}, 2000, 'It\'s taking to long to load ' + targetUrl + '!');
});
expect(ptor.driver.getCurrentUrl()).toBe('http://localhost:52254/');
}, 5000);一切都很好,我在我所期望的地方。
但是,如果我运行下面的测试(除了与下面的测试相同),我将在页面上搜索一个元素。
it('should redirect to login', function () {
targetUrl = 'http://localhost:52254/';
ptor = protractor.getInstance();
ptor.ignoreSychronization = true;
ptor.get(targetUrl);
ptor.wait(function () {
return ptor.driver.getCurrentUrl().then(function (url) {
return targetUrl = url;
}, 2000, 'It\'s taking to long to load ' + targetUrl + '!');
});
ptor.driver.findElement(by.id('headerLoginBtn')).click().then(function () {
expect(ptor.driver.getCurrentUrl()).toBe('http://localhost:52254/Account/Login');
});
}, 5000);我得到下面显示的异常
UnknownError: Error Message => 'Element is not currently visible and may not be manipulated' 当使用chrome驱动程序运行时,测试运行良好,但是在幻影中它失败了。我是在这里遗漏了什么吗?还是这是对幻影的限制,它不会运行在前端.NET代码上。
发布于 2014-08-05 14:53:00
有时候,幻影中的测试会失败,因为幻影窗口(你看不见)很小,量角器(selenium)只能看到页面上可见的元素(而不必滚动)。因此,当幻影启动一个相对较小的窗口时,某些内容和要使用的元素不适合于可见部分。
在post https://github.com/angular/protractor/issues/585中,描述了设置屏幕分辨率的解决方案。使用它,您可以为量角器启动的浏览器设置一个屏幕分辨率。我注意到幻影通常比firefox和chrome需要更多的空间。
另外,使用量角器-html-屏幕截图-记者,您可以在测试失败的时刻拍摄屏幕截图,这样您就可以查看元素是否可见。这是特别有用的幻影,因为你不能停止除错量角器,看看是什么问题。
发布于 2015-01-13 06:48:30
我同意@Andre Paap。
在python单元测试中,我在幻影中也遇到了同样的问题。
我通过添加以下一行来解决问题。
self.driver.set_window_size(1120, 550)https://stackoverflow.com/questions/21182067
复制相似问题