java Selenium Web驱动程序和OpenLayers 2。x:如何在地图上进行识别?
我必须测试一个使用OpenLayers 2的web映射应用程序。x、 使用Java中的Selenium Web驱动程序和Firefox(我在Windows 7上)
我发现只有这个问题不能解决我的问题
我必须在地图上的特征上测试识别功能,所以:
1)选择我工具栏上的“识别”按钮(我可以这样做……所以没问题……)
2)点击地图上的一个点要素(我做不到)
3)关闭显示特征描述数据的对话框(我无法执行此操作)
我不能给出我的应用程序的url,它不是公共的,但我可以使用这个简单的测试用例
http://dev.openlayers.org/releases/OpenLayers-2.13.1/examples/markers.html
这显示了我的用例
点击地图,你会看到特征细节,然后关闭对话框
这是我的代码,不起作用
package myTestProjects;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
public class identifyOpenLayersTest_02 {
private static WebDriver driver = null;
public static void main(String[] args) throws InterruptedException {
// Create a new instance of the Firefox driver
System.out.println("Create a new instance of the Firefox driver ...");
driver = new FirefoxDriver();
//Put a Implicit wait, this means that any search for elements on the page could take the time the implicit wait is set for before throwing exception
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
// It is always advisable to Maximize the window before performing DragNDrop action
System.out.println("Maximize the window ...");
driver.manage().window().maximize();
Thread.sleep(3000L);
// Launch the OpenLayers 2.x marker sample
System.out.println("Launch the OpenLayers 2.x marker sample ...");
Thread.sleep(3000L);
driver.get("http://dev.openlayers.org/releases/OpenLayers-2.13.1/examples/markers.html");
// Create a new Action instance
System.out.println("Create a new Action instance ...");
Actions act = new Actions(driver);
// Find the viewport inside in witch there is the map
System.out.println("Find the viewport inside in witch there is the map ...");
Thread.sleep(3000L);
WebElement el = driver.findElement(By.id("OpenLayers_Map_2_OpenLayers_ViewPort"));
// Start the action sequence
System.out.println("Start the action sequence ...");
Thread.sleep(3000L);
act.click().perform();
// Identify marker
System.out.println("Identify marker at 285, 111 ...");
Thread.sleep(3000L);
act.moveToElement(el, 285, 111).click().build().perform();
// Print TEST = OK!!
System.out.println("TEST = OK !!");
//driver.quit();
}
}
建议?样本
编辑:
我有一些关于这个问题的消息(不幸的是,现在还不是解决方案……)
如果您使用这个OpenLayers示例运行我的代码
http://dev.openlayers.org/releases/OpenLayers-2.13.1/examples/getfeatureinfo-popup.html
你会发现它是有效的,所以问题似乎与坐标无关
我认为问题在于使用这个样本
http://dev.openlayers.org/releases/OpenLayers-2.13.1/examples/markers.html
如图所示,特征的描述数据放在一个DIV中
单击后如何显示此DIV
有什么帮助吗
提前非常感谢
# 1 楼答案
我解决了
这就是有效的代码
在这种情况下,解决方案是考虑到标记直接出现在地图图像上,因此它们是浏览器页面的组成部分,因此您必须参考正确的元素。p>
“核心”代码是关于这些行的
注释行是指视口的错误代码行,正确的代码行指对象“olAlphaImg”
就这些
我希望这对其他人有用
塞萨尔