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: