【发布时间】:2014-10-09 05:42:15
【问题描述】:
我正在尝试使用 Protractor/Selenium 自动执行拖放操作,以检查基于图块(传单库)的地图是否正常工作,但我无法自动执行拖放操作(平移地图)。
我已经加载了一个带有地图的页面,如下所示: http://tombatossals.github.io/angular-leaflet-directive/examples/center-example.html
而且这个量角器测试没有平移地图,所选图像上的 dragAndDrop 操作似乎不起作用。
describe('Panning map', function() {
var ptor, driver;
beforeEach(function() {
ptor = protractor.getInstance();
browser.get('center-example.html');
driver = ptor.driver;
}, 30000);
it('should update the center value if the map is dragged', function() {
var el = element(by.xpath('.//img[contains(@class, "leaflet-tile-loaded")][1]'));
browser.actions().dragAndDrop(el.find(), { x: 40, y: 40 }).perform();
ptor.sleep(2000);
expect(element(by.model("london.lat")).getAttribute("value")).toBe('51.505');
expect(element(by.model("london.lng")).getAttribute("value")).toBe('-1.09');
});
});
dragAndDrop 操作不适用于此类示例的原因是什么?
【问题讨论】:
-
有趣。你看过 Leaflet 的event documentation吗?
-
是的。我也在 Leaflet 源代码上查找了拖动元素,确实是 img:github.com/Leaflet/Leaflet/blob/master/src/dom/Draggable.js#L87,但我无法使用量角器自动执行拖动操作。
-
我尝试了您的示例页面,但也失败了。你找到解决办法了吗?
标签: angularjs leaflet protractor