【问题标题】:Selenium Web Driver and OpenLayers 2.x: how to do a identify on a map?Selenium Web Driver 和 OpenLayers 2.x:如何在地图上进行识别?
【发布时间】:2015-09-11 18:16:57
【问题描述】:

我要测试一个使用 OpenLayers 2.x、使用 Java 中的 Selenium Web 驱动程序和 Firefox(我在 Windows 7 上)的网络地图应用程序。

我发现只有这个问题How to use OpenLayers DrawFeature with Selenium WebDriver in Java (double click issue)? 不能解决我的问题。

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

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?

对此有何帮助?

提前非常感谢您!!!

【问题讨论】:

    标签: java selenium selenium-webdriver openlayers


    【解决方案1】:

    我解决了!!

    这是有效的代码!

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

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

    “核心”代码是关于这一行的

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

    注释行是错误的代码行,指的是视口,正确的代码行指的是对象“olAlphaImg”。

    就是这样!

    我希望这对其他人有用!

    切萨雷

    【讨论】:

      猜你喜欢
      • 2021-10-04
      • 2015-09-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-20
      • 1970-01-01
      • 2011-12-22
      相关资源
      最近更新 更多