Selenium Web Driver和OpenLayers 2.x:如何在地图上进行标识? [英] Selenium Web Driver and OpenLayers 2.x: how to do a identify on a map?

查看:85
本文介绍了Selenium Web Driver和OpenLayers 2.x:如何在地图上进行标识?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须测试一个使用OpenLayers 2.x,使用Java中的Selenium Web Driver和使用Firefox(我在Windows 7上)的Web映射应用程序.

I've to test a web mapping application that use OpenLayers 2.x, using Selenium Web Driver in Java and using Firefox (I'm on Windows 7).

我仅发现此问题

I've found only this issue How to use OpenLayers DrawFeature with Selenium WebDriver in Java (double click issue)? that doesn't solve my problem.

我必须在地图上的特征上测试识别功能,所以:

I've have to test the identify function on features on the map, so:

1)选择工具栏上的识别"按钮(我能够执行此操作……所以没问题……)

1) select the identify button on my toolbar (I'm able to do this ... so no problem ...)

2)单击地图上的点要素(我无法执行此操作....)

2) click on a point feature on the map (I'm not able to do this ....)

3)关闭显示功能部件描述数据的对话框(我无法执行此操作....

3) close the dialog that shows the feature descriptive data (I'm not able to do this ....)

我不能给应用程序提供不公开的网址,但是我可以使用这个简单的测试用例

I can't give the url of my application that it's not public but I can use this simple test case

http://dev.openlayers.org/releases /OpenLayers-2.13.1/examples/markers.html

显示了我的用例.

单击地图,您将看到功能详细信息,然后关闭对话框.

Clicking on the map, you'll see the feature details and then close the dialog.

这是我的无效代码

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();

        }
} 

建议?样品?


我有关于这个问题的一些消息(不幸的是,仍然不是解决方案……).


I've some news about this question (not still the solution unfortunately ....).

如果您使用此OpenLayers示例运行我的代码

If you run my code using this OpenLayers sample

http://dev.openlayers.org /releases/OpenLayers-2.13.1/examples/getfeatureinfo-popup.html

您会看到它起作用,因此问题似乎与坐标无关.

you'll see that it works, so the the problem seems NOT to be about coordinates.

我认为问题在于使用此示例

I think that the problem is that using this sample

http://dev.openlayers.org/releases /OpenLayers-2.13.1/examples/markers.html

功能的描述数据被放入DIV中,如您在图片中看到的那样.

the description data of the features is put in a DIV as you can see in the picture ....

点击后如何显示该DIV?

How can I show this DIV after my click?

对此有任何帮助吗?

非常感谢您!

推荐答案

我已经解决了!

这里是有效的代码!

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.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;
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 profile and load my Firefox default profile 
    System.out.println("Creo un nuovo profilo e vi carico il profilo Firefox di default ...");
    Thread.sleep(3000L);
    ProfilesIni profile = new ProfilesIni();        
    FirefoxProfile ffProfile = profile.getProfile("default");

    // Create a new instance of the Firefox driver using my new Firefox profile  
    System.out.println("Creo una nuova sessione del browser Firefox ...");
    Thread.sleep(3000L);
    driver = new FirefoxDriver(ffProfile);

    //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"));
    WebElement el = driver.findElement(By.className("olAlphaImg"));

    // Start the action sequence 
    System.out.println("Start the action sequence  ...");
    Thread.sleep(3000L);
    act.click().perform();        

    // Perform the click operation that opens new window
    // 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();

        }
} 

在这种情况下,解决方案是,您必须考虑标记直接在地图图像上,因此它们是浏览器页面的组成部分,因此您必须引用正确的元素.

In this case the solution is about you've to consider that the markers are directly on the map image, so they are components of the browser page, so you've to refer to the right element.

核心"代码与此行有关

//WebElement el = driver.findElement(By.id("OpenLayers_Map_2_OpenLayers_ViewPort"));
    WebElement el = driver.findElement(By.className("olAlphaImg"));

被注释的行是指向视口的错误代码行,而右边的代码行则指向对象"olAlphaImg".

The commented row is the wrong code row referring to the viewport, the right code row refers to the object "olAlphaImg".

仅此而已!

我希望这对其他人有用!

I hope this could be useful for others!

剖腹产

这篇关于Selenium Web Driver和OpenLayers 2.x:如何在地图上进行标识?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆