How to use OpenLayers DrawFeature with Selenium WebDriver in Java (double click issue)?

a 夏天 提交于 2019-12-11 09:29:46

问题


I am testing a GIS API that is based on OpenLayers. I use Selenium WebDriver to perform the tests. I am now trying to test the OpenLayers.DrawFeature. It works fine when drawing points, which require a single click. But for lines and polygons it doesn't.

Line and polygon drawing requires a double click to finish drawing the shape. But, the "doubleClick()" method from Selenium WebDriver doe not seem to work.

It is a work task, so I can't paste the whole code, but here is what I think is the crucial part:

driver = new ChromeDriver();
Global.initWithCookies(driver);

WebElement el = driver.findElement(By.id(Menu.idOfDrawModesBtn()));
Actions act = new Actions(driver);
act.moveToElement(el).perform();
driver.findElement(By.id(Menu.idOfDrawModePolygonBtn())).click();
el = driver.findElement(By.id(Global.idOfMapDiv()));
act.moveToElement(el).perform();

// First click at the center of the map
act.click().perform();
// Moves to 2nd location
act.moveByOffset(100, 10).perform();
// 2nd click creates the 2nd vertex of the polygon
act.click().perform();
// Moves to 2nd location
act.moveByOffset(200, -200).perform();
/* Double click creates the 3rd vertex of the polygon
    AND should finish the drawing */
act.doubleClick().perform();

driver.close();

As you can see here, the polygon is not drawn yet, because the double click didn't work:

This is what it should look like, if the double click worked:


回答1:


I may have found a solution. It works, but I don't understand why.

Instead of:

act.doubleClick().perform();

I did:

act.click().doubleClick().build().perform();

So, I perform a normal click, THEN a double click, I build the action, and perform.

It is working. I am able to finish the drawing.



来源:https://stackoverflow.com/questions/28682195/how-to-use-openlayers-drawfeature-with-selenium-webdriver-in-java-double-click

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!