Selenium Web 驱动程序和 OpenLayers 2.x:如何在地图上进行交互式放大?
Selenium Web Driver and OpenLayers 2.x: how to do an interactive zoom in on a map?
我要测试一个使用 OpenLayers 2.x、在 Java 中使用 Selenium WebDriver 并使用 Firefox(我在 Windows 7 上)的网络地图应用程序。
我必须测试地图上的交互式放大功能,所以:
1) 点击SHIFT+鼠标左键
2) 拖动鼠标在地图上画一个方框(我做不到....)
3) 松开鼠标左键:此时地图响应是放大(我做不到....)
我不能告诉我的应用程序 url 它不是 public 但我可以使用这个简单的测试用例
http://dev.openlayers.org/releases/OpenLayers-2.13.1/examples/example.html
这显示了我的用例。
建议?样本?
非常感谢您!
切萨雷
我解决了!
这是有效的代码:您可以执行它!
package myTestProjects;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
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 interactiveZoomInOpenLayerstest_01 {
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 test con DEMO 27 ...");
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("Massimizzo la finestra del browser ...");
Thread.sleep(3000L);
driver.manage().window().maximize();
//Launch the OpenLayers 2.x sample
System.out.println("Mi collego all'esempio di OpenLayers 2.x ...");
Thread.sleep(3000L);
driver.get("http://dev.openlayers.org/releases/OpenLayers-2.13.1/examples/example.html");
// Find the viewport inside in witch there is the map
System.out.println("Individuo il viewport al cui interno c'è la mappa ...");
Thread.sleep(3000L);
WebElement el = driver.findElement(By.id("OpenLayers_Map_2_OpenLayers_ViewPort"));
// Create a new Action instance
System.out.println("Creo un oggetto di tipo \"Action\" ...");
Actions act = new Actions(driver);
// Moves to 2nd location
System.out.println("Moves to 1st location: 200, 150 ...");
Thread.sleep(3000L);
// Draw rectangle and execute zoom in
System.out.println("Moves to 1st location: 200, 150 ...");
act.moveToElement(el,200,50).click().keyDown(Keys.SHIFT).clickAndHold().moveToElement(el, 300, 150).click().release().keyUp(Keys.SHIFT).build().perform();
// Print TEST = OK!!
System.out.println("TEST = OK !!");
//driver.quit();
}
}
我要测试一个使用 OpenLayers 2.x、在 Java 中使用 Selenium WebDriver 并使用 Firefox(我在 Windows 7 上)的网络地图应用程序。
我必须测试地图上的交互式放大功能,所以:
1) 点击SHIFT+鼠标左键
2) 拖动鼠标在地图上画一个方框(我做不到....)
3) 松开鼠标左键:此时地图响应是放大(我做不到....)
我不能告诉我的应用程序 url 它不是 public 但我可以使用这个简单的测试用例
http://dev.openlayers.org/releases/OpenLayers-2.13.1/examples/example.html
这显示了我的用例。
建议?样本?
非常感谢您!
切萨雷
我解决了!
这是有效的代码:您可以执行它!
package myTestProjects;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
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 interactiveZoomInOpenLayerstest_01 {
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 test con DEMO 27 ...");
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("Massimizzo la finestra del browser ...");
Thread.sleep(3000L);
driver.manage().window().maximize();
//Launch the OpenLayers 2.x sample
System.out.println("Mi collego all'esempio di OpenLayers 2.x ...");
Thread.sleep(3000L);
driver.get("http://dev.openlayers.org/releases/OpenLayers-2.13.1/examples/example.html");
// Find the viewport inside in witch there is the map
System.out.println("Individuo il viewport al cui interno c'è la mappa ...");
Thread.sleep(3000L);
WebElement el = driver.findElement(By.id("OpenLayers_Map_2_OpenLayers_ViewPort"));
// Create a new Action instance
System.out.println("Creo un oggetto di tipo \"Action\" ...");
Actions act = new Actions(driver);
// Moves to 2nd location
System.out.println("Moves to 1st location: 200, 150 ...");
Thread.sleep(3000L);
// Draw rectangle and execute zoom in
System.out.println("Moves to 1st location: 200, 150 ...");
act.moveToElement(el,200,50).click().keyDown(Keys.SHIFT).clickAndHold().moveToElement(el, 300, 150).click().release().keyUp(Keys.SHIFT).build().perform();
// Print TEST = OK!!
System.out.println("TEST = OK !!");
//driver.quit();
}
}